Tag Archives | dimmer

Pushbutton Switch Dimmer Control & Alarm

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;

void setup() {
pinMode(buttonPin1,INPUT);
pinMode(buttonPin2,INPUT);
pinMode(LEDPin,OUTPUT);
pinMode(buzzPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
buttonVal1=digitalRead(buttonPin1);
buttonVal2=digitalRead(buttonPin2);
Serial.print(“Button 1 = “);
Serial.print(buttonVal1);
Serial.print(“, “);
Serial.print(“Button 2 = “);
Serial.println(buttonVal2);
delay(dt);

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).