Arduino - Button With LED
by MertArduino in Circuits > Arduino
21366 Views, 63 Favorites, 0 Comments
Arduino - Button With LED
Turns ON and OFF a light LED, when pressing a pushbutton.
Hardware Required
- Arduino Uno
- LED
- Button
- 220 and 10k ohm resistors
- Wires
- Breadboard
LED Connections
- 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
- 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
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
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.