Brightness Controller with Push Button

Description

In this I am going to make a brightness controller using Arduino, which has two buttons to increase and decrease the brightness of LED. It has simple circuit connection , here you have to add only two push buttons which is connected with Arduino Pins to respective pin to increase and decrease the brightness. So let’s start with first requirement of software and components which you are going to use in this project.

Component & Software

Components

[1] Arduino

[2] Seven-segment LED

[3] Jumper Wires

[4] USB connector

Software

[1] Arduino IDE

Arduino Code & working

Here let’s understand how it is working. To get the variable voltage at the output pin of Arduino we use PWM of Arduino to get the vary voltage between 0-5 volt, so this is the concept I am using here but the difference is here I have added one variable which control the number of steps to increase and decrease the value in between 0-255 , this is the digital value which will give the value in terms of voltage according to that value. Now understand the code how it is working.

Here above is the circuit diagram for this project connect each components as per the circuit diagram then upload that below given code you will get the output as per the given in video.

Code :-

// Electrocircuit Website   📎 www.electrocircuit.net 
// Electrocircuit YouTube   📎 https://m.youtube.com/c/ElectroCircuit
// Electrocircuit Instagram 📎https://instagram.com/electrocircuit_?utm_medium=copy_link

int pinIncrease = 9;       //Button for increase the brightness.
int pinDecrease = 10;      //Button for decrease the brightness.
int pinLED = 3;            // LED pin D3.
int steps = 10;            // Enter number of steps here.
int brightness = 0;
void setup() 
{
  pinMode(pinIncrease, INPUT);
  pinMode(pinDecrease, INPUT);
  pinMode(pinLED, OUTPUT);
  digitalWrite(pinIncrease, HIGH);
  digitalWrite(pinDecrease, HIGH);
}

void loop() {
  brightness = constrain(brightness, 0, 255);
  analogWrite(pinLED, brightness);
  if (digitalRead(pinIncrease) == LOW)
  {
    brightness = brightness + (256/steps);
  } else if (digitalRead(pinDecrease) == LOW)
  {
    brightness = brightness - (256/steps);
  }
  delay(100);
}

As you can see here pinIncrease button is connected with pin D9 of Arduino and pinDecrease is connected with pin D10 of Arduino. And LED is connected with pin D3 of Arduino.

if (digitalRead(pinIncrease) == LOW)
  {
    brightness = brightness + (256/steps);
  } else if (digitalRead(pinDecrease) == LOW)
  {
    brightness = brightness - (256/steps);
  }

Here main thing is that variable steps which is taking the value of steps to be count at the time of Increase or Decrease the brightness, here I have taken as steps 10. Above given condition is to check which button is pressed, if you press Increase button at the time of simulation then it will execute this formula for brightness that is :- brightness = brightness + (256/steps) here in each step when you will press the increase button it will add the (256/steps) value in brightness value so in this way will get the range of 0-255 which directly proportional to 0-5 voltage. Similarly in else if condition if you press Decrease button at the time of simulation then it will execute this formula for brightness that is :- brightness = brightness – (256/steps) it is subtracting this part in each press. So in this way this circuit is working I hope you understood it. If you have any doubt please put that doubt in comment, I will answer that as soon as possible & thankyou for reading 😀.

Output Video
YouTube Video

Thankyou so much to read the article till now there is YouTube video on this project so please go through that video to understand the whole procedure in a better manner there is link for video go and check it out.

One comment

Leave a Reply

Your email address will not be published.