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
vlcsnap-2016-11-16-03h32m58s784.png
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

  • Arduino Uno
  • LED
  • Button
  • 220 and 10k ohm resistors
  • Wires
  • Breadboard

LED Connections

vlcsnap-2016-11-16-03h33m43s383.png
vlcsnap-2016-11-16-03h33m51s154.png
vlcsnap-2016-11-16-03h34m23s172.png
vlcsnap-2016-11-16-03h34m41s968.png
vlcsnap-2016-11-16-03h35m07s422.png
vlcsnap-2016-11-16-03h35m19s314.png

  1. LED attach to board
  2. Resistor (220 ohm) connect to LED's long leg (+)
  3. The wire connect to resistor empty leg
  4. After that, same wire connect to digital pin from resistor
  5. The wire connect to LED's short leg (-), after that same wire connect to ground

Pushbutton Connections

vlcsnap-2016-11-16-03h35m41s468.png
vlcsnap-2016-11-16-03h35m54s999.png
vlcsnap-2016-11-16-03h36m05s955.png
vlcsnap-2016-11-16-03h36m20s200.png
vlcsnap-2016-11-16-03h36m33s891.png
vlcsnap-2016-11-16-03h36m53s297.png
vlcsnap-2016-11-16-03h37m09s366.png
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

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

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.

Mert Arduino Tutorial & Projects