Arduino - Button With LED
by MertArduino in Circuits > Arduino
18953 Views, 63 Favorites, 0 Comments
Arduino - Button With LED
![Arduino Basic Tutorial 06 - Button LED](/proxy/?url=https://content.instructables.com/FW2/IPWP/IVHQJV28/FW2IPWPIVHQJV28.jpg&filename=Arduino Basic Tutorial 06 - Button LED)
![vlcsnap-2016-11-16-03h32m58s784.png](/proxy/?url=https://content.instructables.com/FH0/8K7I/IVHQJUZR/FH08K7IIVHQJUZR.png&filename=vlcsnap-2016-11-16-03h32m58s784.png)
![vlcsnap-2016-11-16-03h33m08s567.png](/proxy/?url=https://content.instructables.com/FY5/PBVK/IVHQJUZU/FY5PBVKIVHQJUZU.png&filename=vlcsnap-2016-11-16-03h33m08s567.png)
Turns ON and OFF a light LED, when pressing a pushbutton.
Hardware Required
![vlcsnap-2016-11-16-03h33m28s063.png](/proxy/?url=https://content.instructables.com/FM1/EUIY/IVHQJUZV/FM1EUIYIVHQJUZV.png&filename=vlcsnap-2016-11-16-03h33m28s063.png)
- Arduino Uno
- LED
- Button
- 220 and 10k ohm resistors
- Wires
- Breadboard
LED Connections
![vlcsnap-2016-11-16-03h33m43s383.png](/proxy/?url=https://content.instructables.com/F78/MTWY/IVHQJUZW/F78MTWYIVHQJUZW.png&filename=vlcsnap-2016-11-16-03h33m43s383.png)
![vlcsnap-2016-11-16-03h33m51s154.png](/proxy/?url=https://content.instructables.com/F5M/9JBC/IVHQJUZX/F5M9JBCIVHQJUZX.png&filename=vlcsnap-2016-11-16-03h33m51s154.png)
![vlcsnap-2016-11-16-03h34m23s172.png](/proxy/?url=https://content.instructables.com/FKH/MZQH/IVHQJV00/FKHMZQHIVHQJV00.png&filename=vlcsnap-2016-11-16-03h34m23s172.png)
![vlcsnap-2016-11-16-03h34m41s968.png](/proxy/?url=https://content.instructables.com/FB3/RW95/IVHQJV03/FB3RW95IVHQJV03.png&filename=vlcsnap-2016-11-16-03h34m41s968.png)
![vlcsnap-2016-11-16-03h35m07s422.png](/proxy/?url=https://content.instructables.com/FKB/T1IS/IVHQJV05/FKBT1ISIVHQJV05.png&filename=vlcsnap-2016-11-16-03h35m07s422.png)
![vlcsnap-2016-11-16-03h35m19s314.png](/proxy/?url=https://content.instructables.com/FFX/NGKX/IVHQJV08/FFXNGKXIVHQJV08.png&filename=vlcsnap-2016-11-16-03h35m19s314.png)
- LED attach to board
- Resistor (220 ohm) connect to LED's long leg (+)
- The wire connect to resistor empty leg
- After that, same wire connect to digital pin from resistor
- The wire connect to LED's short leg (-), after that same wire connect to ground
Pushbutton Connections
![vlcsnap-2016-11-16-03h35m41s468.png](/proxy/?url=https://content.instructables.com/FQK/V3LV/IVHQJV09/FQKV3LVIVHQJV09.png&filename=vlcsnap-2016-11-16-03h35m41s468.png)
![vlcsnap-2016-11-16-03h35m54s999.png](/proxy/?url=https://content.instructables.com/FBM/FFO6/IVHQJV0A/FBMFFO6IVHQJV0A.png&filename=vlcsnap-2016-11-16-03h35m54s999.png)
![vlcsnap-2016-11-16-03h36m05s955.png](/proxy/?url=https://content.instructables.com/FHM/AXQ5/IVHQJV0D/FHMAXQ5IVHQJV0D.png&filename=vlcsnap-2016-11-16-03h36m05s955.png)
![vlcsnap-2016-11-16-03h36m20s200.png](/proxy/?url=https://content.instructables.com/FW5/FTSR/IVHQJV0E/FW5FTSRIVHQJV0E.png&filename=vlcsnap-2016-11-16-03h36m20s200.png)
![vlcsnap-2016-11-16-03h36m33s891.png](/proxy/?url=https://content.instructables.com/F0T/ILVU/IVHQJV0F/F0TILVUIVHQJV0F.png&filename=vlcsnap-2016-11-16-03h36m33s891.png)
![vlcsnap-2016-11-16-03h36m53s297.png](/proxy/?url=https://content.instructables.com/FZL/LBTG/IVHQJV0H/FZLLBTGIVHQJV0H.png&filename=vlcsnap-2016-11-16-03h36m53s297.png)
![vlcsnap-2016-11-16-03h37m09s366.png](/proxy/?url=https://content.instructables.com/FRC/BQFK/IVHQJV18/FRCBQFKIVHQJV18.png&filename=vlcsnap-2016-11-16-03h37m09s366.png)
![vlcsnap-2016-11-16-03h37m29s492.png](/proxy/?url=https://content.instructables.com/FUQ/3UIG/IVHQJV1E/FUQ3UIGIVHQJV1E.png&filename=vlcsnap-2016-11-16-03h37m29s492.png)
- The button attach to board
- 10k resistor connect to button leg
- The wire connect to resistor empty leg, after that same wire connect to ground
- The wire connect to button's other leg, after that same wire connect to +5V
- The yellow wire connect to button's top leg, after that connect to digital pin
Code
![vlcsnap-2016-11-16-03h38m05s383.png](/proxy/?url=https://content.instructables.com/FLR/TF37/IVHQJV1G/FLRTF37IVHQJV1G.png&filename=vlcsnap-2016-11-16-03h38m05s383.png)
const int ledPin = 2;
const int buttonPin = 4;
int buttonState = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("LED ON +++++++");
}
else {
digitalWrite(ledPin, LOW);
Serial.println("LED OFF -------");
}
}
If It Helps, Please Subscribe
![vlcsnap-2016-11-16-03h38m19s481.png](/proxy/?url=https://content.instructables.com/FGM/4D37/IVHQJV1H/FGM4D37IVHQJV1H.png&filename=vlcsnap-2016-11-16-03h38m19s481.png)
First of all, I would like to thank you for reading this guide ! I hope it helps you.
If you want to support me, you can subscribe my channel and watch my videos.