Minuka Thesath Yapa
Published

Arduino Button with LED

Turns on and off a LED when pressing a pushbutton

BeginnerProtip3,434
Arduino Button with LED

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×4
Arduino UNO
Arduino UNO
×1
Through Hole Resistor, 680 ohm
Through Hole Resistor, 680 ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
LED (generic)
LED (generic)
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

ARDUINO PUSHBUTTON with LED

The circuit diagram

Code

ARDUINO BUTTON.ino

Arduino
const int buttonPin = 2;
const int ledPin =  13;

int buttonState = 0;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop()
{
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH)
  {
    digitalWrite(ledPin, HIGH);
  } 
  else
  {
    digitalWrite(ledPin, LOW);
  }
}

Credits

Minuka Thesath Yapa

Minuka Thesath Yapa

12 projects • 9 followers

Comments

Add projectSign up / Login