How to interface push button to Arduino UNO

shape
shape
shape
shape
shape
shape
shape
shape
blog-details
June, 2021

Introduction

In this tutorial, you are going to learn how to Control led using Arduino UNO and push button. Whenever we press the switch the led will turn on and turn off while releasing the push button.

Parts Required

Parts Quantity Link
Arduino UNO 1
https://amzn.to/2TvSOxY
A-B cable 1  
LED 1
https://amzn.to/2HDWLxI
Push-button 1
https://amzn.to/2Jba75f
Bread Board 1 https://amzn.to/3mxYVON
Connecting wire As Per Required
https://amzn.to/2TtqeNx
220 ohm 1  
10 Kohm 1  

Circuit Diagram

Program

For programming this concept we need to understand some basic syntax of Arduino IDE. The first thing is we need to install Arduino. After that, we need to know how to interface led to Arduino.

For controlled, we need to declare led as output

pinMode(PIN Number, Device TYPE);

 

PIN Number– The pin, to which we have connected the device. In this case, I have attached Led to 7 no pin of Arduino UNO.

Device Type– What is the device type. For output devices, we need to declare the type as OUTPUT and for input devices, we need to declare it as INPUT. In this case, we have connected Led. As we know, led is an output device. so we have to program.

pinMode(7, OUTPUT);

 

For taking signals from the push button we need to declare the Push button as an input device

pinMode(PIN Number, Device TYPE);

 

PIN Number– The pin, to which we have connected the device. In this case, I have attached the switch to 10 no pin of Arduino UNO.

Device Type– In this case we have connected switch. As we know, the switch is an INPUT device. so we have to write Device type as INPUT.

pinMode(10, INPUT);

After declare we need to turn on/ off led. so, to do that we need to understand about digitalWrite()

digitalWrite(PIN Number, Status);

PIN Number– in which pin we have connected the device. In this case, I have attached to 7 no pin of Arduino UNO

Status–  status means we need to turn the led on/off. For turning led on we can write HIGH or 1 and for turning off led we can write LOW or 0.

 

Final Code

/*
 Tested by robogenesis. in
 This program controlled by a push-button that is connected to Arduino
*/
void setup(){
 pinMode(7, OUTPUT);        // Declar led as output
 pinMode(10,INPUT_PULLUP);  // Declar switch as input device and Pullup connection
}

void loop(){
 if(digitalRead(10)==HIGH){   //switch press
  digitalWrite(13, HIGH);  //Led On
 }
 else{
    digitalWrite(13, LOW);   //Led Off
 }
}

 

Comments

Leave a Reply