This simple Push Button LED Circuit using Arduino shows how to turn an LED ON and OFF using a push button switch.
When the button is pressed the LED turns ON.
And when released the LED turns OFF.
It helps beginners to learn about digital input and output in Arduino.
Arduino Coding:
int led = 13;
int button = 2;
int buttonstate = 0;
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
buttonstate = digitalRead(button);
if (buttonstate == HIGH) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
}Code Explanation:
- Pinmode sets LED as output and button as input.
- Digitalread reads button state.
- If condition checks if button is pressed (high).
- if pressed LED turns ON using digitalwrite high.
- Else, LED turns OFF using digitalwrite low.
Circuit Working:
Parts List:
| Component Name | Specification | Quantity | 
|---|---|---|
| Resistors | 220Ω 1/4 watt | 1 | 
| 10k 1/4 watt | 1 | |
| Semiconductors | Arduino UNO Board | 1 | 
| LED 5mm any color | 1 | |
| Push Button Switch | 1 | 
When button is not pressed then pin 2 is LOW.
And LED stays OFF.
When button is pressed then pin 2 gets 5V.
Arduino reads HIGH and LED turns ON.
When button released then pin 2 goes LOW again.
And LED turns OFF.
Formula:
Below is the formula for Push Button LED Circuit:
Current through LED = V / R = 5V / 220 ohm = 0.022a = 22ma
LED needs around 20ma, so 220 ohm resistor used here is suitable.
10k resistor is used to keep input low when button not pressed.
How to Build:
To build a Push Button LED Circuit using Arduino follow the below steps for connection:
- Collect all parts same as circuit diagram
- Join LED positive leg (anode) to pin 13 using 220 ohm resistor
- Join LED negative leg (cathode) to ground pin.
- Connect one side of push button to pin 2 of Arduino
- Connect other side of push button to 5V pin
- Put 10k resistor between button pin 2 and ground
Conclusion:
This project if for Push Button LED Circuit using Arduino
It shows how to control an led with a push button using Arduino.
Circuit is simple and helps to learn digital input and output basics easily
