This project controls an increasing and decreasing voltage level in increments to represent a dimmer present at an LED. An in-circuit buzzer serves as an alarm to indicate either a maximum or minimum level is attained. Two separate pushbutton switches are up / down controls at programmable increments.
Both switches are set up in a common physical configuration only attached to separate GPIO ports. The difference between their operation rests within the code. Brightness increments are defined within the code as is the decrements. Each increment and decrement interval is code-defined as both switches are attached as inputs to separate GPIO ports. The LED is simply an indicator of a GPIO output to show what the increments and decrements are doing (increasing and decreasing voltage levels). The buzzer that operates as an alarm triggers when the pushbutton switch is pressed too much or too long. As increments increase to a cap (255) or decrease to a floor (0), the alarm will sound to indicate there is no further increase or decrease available. The dimming or brightness levels off and goes no further.
One pull up resistor for each pushbutton switch is necessary to correctly assert each GPIO input to control circuit and code activity. Four total GPIO pins used, each one for its dedicated function. There is no attempt to make dual use of a GPIO port.
Project schematic to illustrate connections and devices interfaced to the Arduino SBC.
Program & Functional Operation:
Code Setup:
int buttonPin1=12; int buttonPin2=11; int buzzPin=2; int LEDPin=3; int buttonVal1; int buttonVal2; int LEDbright=0; int dt=500;
if (buttonVal1==0){ LEDbright=LEDbright+25; } if (buttonVal2==0){ LEDbright=LEDbright-25; } Serial.println(LEDbright); if (LEDbright>255){ LEDbright=255; digitalWrite(buzzPin,HIGH); delay(dt); digitalWrite(buzzPin,LOW); Serial.println(“Buzz High”); } if (LEDbright<0){ LEDbright=0; digitalWrite(buzzPin,HIGH); delay(dt); digitalWrite(buzzPin,LOW); Serial.println(“Buzz Low”); }
analogWrite(LEDPin, LEDbright);
}
Arduino Set Up:
Partial view of the code to operate the project. The full code is in the text field above. Serial display of printed values to indicate states of switch buttons and increment or decrement values of 25. The smaller the increment or decrement, the more pushbutton switch presses are needed to reach either upper or lower limit. Increment and decrement was set arbitrarily in the code to initialize a reasonable value of 25 to reduce the time and clicks it takes to get to the maximum and minimum (0 – 255).
☩ U.S. military veteran and electrical engineer with an MBA from Pepperdine University and an M.A. in Theological Studies. My background includes wilderness exploration with over 140 mountain ascents and travel throughout Europe and the Americas. My life is in Christ, under the authority of Holy Scripture, with ongoing interests in theology, literature, engineering, and the sciences.
Once initial hardware is in place, it is necessary to gather the libraries to run the software and get connectivity and begin gathering the Arduino unit and the BNO055 IMU…
“I only went out for a walk and finally concluded to stay out till sundown, for going out, I found, was really going in.”― John Muir, John of the Mountains.The…
To get a closer look at the analogWrite command supported by the Arduino platform, its internal pulse width modulation (PWM) function controls the duty cycle of an output voltage to…
Comments are closed.