Push Button Switch Interfacing with Arduino UNO

If we want a system that works by user input then we need to understand the interfacing of push button switch with the arduino. Suppose We want to interface an led that will glow when we press a switch. We are understanding the small circuit that will be used to input the signal.

Input using External PULL-DOWN Resistor

In the first circuit, a pull-up resistor of 10Kohm is connected with the switch and when it is not pressed giving signal LOW at the output.
In the second circuit, when the switch is pressed the output will be high. This high or low signal goes to the arduino pin.
Here we have used pin no. 8 for input. Arduino will read the input signal if we have set that pin 8 to be input by this instruction pinMode(8, LOW).

Input using External PULL-UP Resistor

In the first circuit, a pull-down resistor of 10Kohm is connected with the switch and when it is not pressed giving signal HIGH at output.

In second circuit, when switch is pressed the output will be LOW. This high or low signal goes to the arduino pin.

And while programming we should notice that push button is connected in pull-up mode or pull-down mode. Accordingly we will do the programming in the arduino.

Hardware Required

  • Arduino Uno
  • Led
  • Resistor 1K ohm
  • Push Button Switch
  • Resistor 10K ohm
  • breadboard

Push Button Arduino Wiring

We can connect the led at any pin of arduino uno by simply changing led connection at desired pin and change in programming also.

Arduino Push Button Connection

Push Button Arduino Code

In this program, led connected at pin no.13 and switch at pin no. 8. We monitoring push button status continuously.

buttonStatus = digitalRead(button);

To read a digital input, you use function digitalRead(). It will return HIGH if input is +5v(High), or LOW if input is 0V.

//Led and Push Button Interfacing
const int button = 8;   //led connected here   
const int led =  13; //push button connected here   
int buttonStatus = 0;  
void setup() {
  pinMode(led,HIGH);
  pinMode(button,LOW);
}

void loop() {
  buttonStatus = digitalRead(button);
  if (buttonStatus == HIGH) {    
    digitalWrite(led, HIGH);
  }
  else {   
    digitalWrite(led, LOW);
  }
}