Push Button Controlled LED using Arduino Uno R3 – Tutorial 2

In this tutorial, you will come to learn “How to control an LED using a Push Button .

In this project you will learn basic use of switch. Most of electrical appliances are using switch to turn ON or OFF. In market, many kind of switch. Here, we are using one of them.

To know about basic arduino uno R3 visit out tutorial-1 :- click here

To complete this project, we require following component.

S.noCOMPONENT
1Arduino board
2Breadboard
3Jumper wires
4LED
5Momentary tactile
four-pin pushbutton
610k-ohm resistor
7220-ohm resistor
8POWER SUPPLY

CIRCUIT DIAGRAM :-

How it Works :-

When we press that switch, then it complete circuit, turning on it. If we release that switch then circuit will we incomplete, and circuit will in off state.

This kind of switch we are using in Keyboard, Vehicle.

This kind of switch has four pins, but generally we use only two in circuit.

Project code :-

//www.kits4utech.com////
//welcome to kits4u tech blog//
const int buttonPin = 2; // Pin connected to pushbutton
const int ledPin = 13; // Pin connected to LED
int buttonState = 0; // Give pushbutton a value
void setup() {
 pinMode(ledPin, OUTPUT); // Set LED pin as output
 pinMode(buttonPin, INPUT); // Set pushbutton pin as input
}
void loop() {
 buttonState = digitalRead(buttonPin); // Read input from pin 2
 if (buttonState == HIGH) { // If pushbutton is pressed, set as HIGH
 digitalWrite(ledPin, HIGH); // Turn on LED
 }
 else {
 digitalWrite(ledPin, LOW); // Otherwise, turn off LED
 }
}
Author: kits4ublog

Leave a Reply

Your email address will not be published.