Interfacing Button and LED – LED blinking when button is pressed
Principle
- 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).
Code:
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);
}
}
How it work:
- Pushing a button completes a circuit and turns it on. The connection will pull back as soon as the button is removed, breaking the circuit and shutting off the device.
- The push-button switch, which is used in, for instance, computer keyboards, is also known as a momentary or typically open switch. This is in contrast to a toggle switch, which, like a light switch, remains in either the on or off state until you toggle it to the other position.
- There are four pins on this type of pushbutton, but you often only connect with two of them at once. Although the two unused pins at the bottom could also be used, you will use the top connections for this project.
Breadboard Diagram:-
For Videos Join Our Youtube Channel: Join Now
Tags:
b2acypher
Interfacing Button and LED – LED blinking when button is pressed
Interfacing Button and LED blinking using button
IOT by mskuthar
mskuthar