Pushbutton Module with Arduino

Detect button presses with the Arduino

Written By: Marcus Schappi

Dash icon
Difficulty
Easy
Steps icon
Steps
5
The Arduino Uno R3 has a reset button, but you can add more buttons to control other components, the built-in LED and more. In this guide, you will learn to connect an external push button to the Arduino, and get it to turn turn the built-in LED on and off. The push button module is comprised of a momentary push button switch and an in-built resistor. After completing this guide, you will know how to add more buttons to your Arduino.

Step 1 The Pushbutton Module

Before we put together the circuit, let's take a closer look at the Pushbutton Module. There are three pins here:

S : This is the signal pin which we will connect to a GPIO pin on the micro:bit

3.3V : Though it is unlabelled on the module, this middle pin will need to be connected to 3.3V on the micro:bit

GND: In electronics, we define a point in a circuit to be a kind of zero volts or 0V reference point, on which to base all other voltage measurements. This point is called ground or GND. Voltage is the difference in potential between two points. As it is difficult to talk about voltage without a reference point, we need another point to compare it to.

Step 2 Connect GND to GND

Connect a black jumper wire from - on the button module to GND on the Arduino

Step 3 Connect 5V to the Middle Pin

Next, connect a red jumper wire from the middle pin of the button module to 5V on the Arduino

Step 4 Connect SIG to Digital Pin 3

Now connect a jumper wire from the signal pin, labelled "S" on the button module to Digital Pin 3 on the Arduino

Step 5

int led = 13; // Define the built-in LED pin
int buttonpin = 3; // Define the push button module's signal pin
int val; //Define a numeric variable

void setup()
{
        pinMode(led,OUTPUT);
        pinMode(buttonpin,INPUT);
}

void loop()
{
        val = digitalRead(buttonpin); // check the state of the button
        if(val==HIGH) // if button is pressed, turn LED on
        {
                digitalWrite(led,HIGH);
        }
        else
        {
                digitalWrite(led,LOW);
        }
}
Upload the following code to your Arduino and watch the LED blink! The built-in LED is found on Digital Pin 13 on the Arduino.