Working with an LED and a Push Button

Working with an LED and a Push Button © GPL3+

This project demonstrates the use of a push button to operate an LED.

  • 103 views
  • 1 comment
  • 2 respects

Components and supplies

Apps and online services

About this project

This project demonstrates the use of a push button to operate a LED.

Objective:

  • To Set LED ON when Button is pressed.
  • To Set LED OFF when Button is pressed (the opposite effect).

Working with a Push Button

Code

LED ON when button is pressedArduino
LED is set to ON when the button is pressed.
const int BUTTON = 2;
const int LED = 3;
int BUTTONstate = 0;

void setup()
{
  pinMode(BUTTON, INPUT);
  pinMode(LED, OUTPUT);
}

void loop()
{
  BUTTONstate = digitalRead(BUTTON);
  if (BUTTONstate == HIGH)
  {
    digitalWrite(LED, HIGH);
  } 
  else{
    digitalWrite(LED, LOW);
  }
}
LED is OFF when button is pressed (Opposite effect)Arduino
LED is OFF when button is pressed (Opposite effect)
const int BUTTON = 2;
const int LED = 3;
int BUTTONstate = 0;

void setup()
{
  pinMode(BUTTON, INPUT);
  pinMode(LED, OUTPUT);
}

void loop()
{
  BUTTONstate = digitalRead(BUTTON);
  if (BUTTONstate == HIGH)
  {
    digitalWrite(LED, LOW);
  } 
  else{
    digitalWrite(LED, HIGH);
  }
}

Schematics

Breadboard Diagram
Make connections as shown in the figure
Breadboard working with a push button cpcexatpa6

Comments

Similar projects you might like

Snap Circuits® - Push Button LED

Project tutorial by Daniel Porrey

  • 2,590 views
  • 0 comments
  • 10 respects

Arduino - Use Reset Button Like a Push Button

by RoHa

  • 1,896 views
  • 0 comments
  • 12 respects

Push Button Combination Lock Using Arduino

Project tutorial by Asim Zulfiqar and High Voltages

  • 3,467 views
  • 8 comments
  • 18 respects

Fade Lights and Push Button

Project tutorial by Phuong Vo

  • 2,631 views
  • 2 comments
  • 9 respects

Bluetooth control led with lcd led status display real time.

Project tutorial by Youssef Sabaa

  • 21,319 views
  • 4 comments
  • 41 respects

Ambient Light Sensor Using Photo Resistor and LED Lights!

Project tutorial by DCamino

  • 4,732 views
  • 4 comments
  • 18 respects
Add projectSign up / Login