Push Button

Introduction

The using of a push button will help you to understand how the input works in Arduino Uno.

Be aware, even if the push button has 4 pins, it’s a dipole. In fact, the pins are linked two by two.

Advice to not plugged in the wrong way

The pins in diagonals of the push button are not always connected together. Therefore, to not make mistake of sense you can choose the two diagonals. (We use that in our circuits).

Advice "beauty"

You can choose the color of each button thanks to this kit.

Also, you can change the size like this one.

Pick up the state of the push button

1) By using the resistor pull-up external

To connect the push button, we link the supply (5V) and the ground (GND). To pick up the state of the push button, we link to the pins 2. You can’t link directly the supply to the Arduino card, we need a resistor.

If the push button is pushed, the serial monitor display 0. Otherwise, it displays 1.

2) By using the resistor pull-up internal

To simplify the circuits, it is possible to modify the program for that the pull-up is inside the Arduino Card.

pinMode(2, INPUT_PULLUP) permits you to initialize the pin 2 as an input with the resistor of pull up.

Turn on the LED with a push button

When we push the button, the led turn on. When we release it, the led turn off.

Why is it so important to put a resistor ?

The supply of the Arduino is 5V, therefore it’s required to put a resistor to not burnt the led. One advice is using a resistor of 220 ohms.

Why pinMode(2, OUTPUT) ?

We initialize the led on the pin 2 of the Arduino card. We choose output because the signal go out of the Arduino card to control the LED.

With this circuit you have to push the button to see the LED turn on. This is not really practical, therefore you have to use a switch. In fact, the switch will keep the state unlike the push button. That’s mean you don’t to stay with your finger pressed on the push button to see the light turn on with a switch.

Transform a push button into a switch

Transform a push button into a switch

A push button has unexpected functionalities. This is an example of it : We will use the push buttons as keypad.
To know if the password taped by the user is good you have to check the serial monitor.

To go further...

To simplify the circuit, you can buy a matrix module at 16 buttons

If you liked the keypad and you want to improve the system you can buy a matrix keyboard.

If you prefer a keypad with a professional look, you can buy this one.