Interfacing Pushbutton - Arduino Basics

Introduction: Interfacing Pushbutton - Arduino Basics

The pushbutton is a component that connects two points in a circuit when you press it.

When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to ground, so that we read a LOW. (The pin is still connected to 5 volts, but the resistor in-between them means that the pin is "closer" to ground.)

Step 1: Components Required:

1. Arduino UNO

2. Breadboard

3. Pushbutton

4. Resistor

5. Jumper wire

Step 2: Circuit Diagram:

Connect three wires to the board. The first goes from one leg of the pushbutton through a pull-down resistor (here 10k ohm) to ground. The second goes from the corresponding leg of the pushbutton to the 5 volt supply. The third connects to a digital I/O pin (here pin 2) which reads the button's state.

When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to voltage, so that we read a HIGH. (The pin is still connected to ground, but the resistor resists the flow of current, so the path of least resistance is to +5V.) If you disconnect the digital I/O pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, not connected to either voltage or ground. It will more or less randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.

Step 3: Code:

For more interesting projects connect with me on:

Youtube:https://www.youtube.com/channel/UCTS10_CRYJhT-vb9...
Facebook page:https://www.facebook.com/techeor1/

Instagram:https://instagram.com/official_techeor?igshid=uc8...

int button=2;

int a;

void setup()
{
  Serial.begin(9600);
  pinMode(button, INPUT);
}
void loop()
 {  
 a = digitalRead(button); 
   
Serial.print(" Value of button =");    
Serial.println(a);  
 }

Be the First to Share

    Recommendations

    • Micro:bit Contest

      Micro:bit Contest
    • Space Contest

      Space Contest
    • Lamps and Lighting Contest

      Lamps and Lighting Contest

    Comments