Push Button Interfacing with Arduino

This article is going to teach you all the steps required by a beginner to interface a Push Button with Arduino. In this article, you are going to learn about how to make a pin input in Arduino and how to read a Digital pin in Arduino. Things you should have before continuing

  • Arduino-Uno Board
  • Bread Board-for making the circuits.
  • Push button, jumper wire

The Project

In this project, I am going to control the On-Board LED from a Push Button. By this, you are going to learn about how to read and write a pin digitally.

Circuit Diagram

push button interfacing with arduino Below is the schematic that I have used, notice that I have introduced a pull-down resistor when the Switch is not connected to the Vcc.

The Program

The program is pretty much straightforward. In Arduino, every program had two functions, a setup function, and a loop function. So, in setup function, we have to declare things only because it is only going to execute only one time, but in loop program written in the loop, a function is going to execute until the microcontroller is powered. In this program, I have given all the declaration in the setup function. I have declared that the pin where pushbutton is connected as an input pin by a method called pinMode(int pin), where I have declared the pin where LED is connected as an output pin(It’s 13th pin in Arduino UNO).

int pin=13,push=2;
void setup() {
 
 pinMode(push,INPUT);
 pinMode(pin,OUTPUT);
}

void loop() {
 int status;
 status=digitalRead(push);
 digitalWrite(pin,status);
}

In the loop function, I am reading the status of the input pin, saving it to the variable and passing to the LED pin. As soon as the status of the input pin is “High”, it means that we have to turn on the LED.

push button with Arduinopush button with Arduino

So here we go, we are controlling the onboard LED by an input pin.

USE of PULL Down Register

Here, pull-down resistor is maintaining the logic of the input pin near zero. The status of the input pin is high when the switch is pushed, but what is the status of the pin when it is pushed up? So, push down resistor is used to maintain the logic of the input pin to near zero.  I am going to talk about these resistors in more detail in next article of -“There are no Dumb Questions“.

Share This