Un pushbutton is a button that allows to interrupt or send an electronic signal. With this simple element combined with other elements you can create projects for a multitude of applications. The use of this type of pushbuttons is very common when it comes to Arduino projects. And by combining several of these buttons you can create a somewhat more complex keyboard, although there are already programmable keyboards for these uses ...
By the way, you should not confuse the pushbutton with a switch. They are totally different things. The difference is that the switch or switch is activated or deactivated with each press that is made on it. Whereas the push button will only stay in one state while pressure is being exerted on it. I have commented that it can send or interrupt, that is because there are two fundamental types of buttons.
Exist NO or normally open pushbuttons and NC or normally closed pushbuttons. This will also sound to you from the relays. And yes, it is exactly the same operation. When you have an NC, it will let current pass through its terminals and it only interrupts while you are pressing it. On the other hand, the NA does not let current pass when pressure is not exerted on it and will only let it pass when you press it.
Knowing that, is almost everything you need to know about a push button to start your connection and programming using Arduino. The truth is that it is such a simple element that there is not much more to say about this type of pushbuttons.
Table of Contents
Push Button Integration with Arduino
La connecting a pushbutton to make it interact with Arduino could not be simpler. An example is the diagram that you can see on these lines. That would be all it takes to start experimenting. But of course, with that scheme you can do little. It would be necessary for you to put a little imagination to decide what that button is going to control. In fact, if you read hwlibre.es frequently you will have already seen some articles where we have used push buttons ...
Ways to connect it
One thing that you should know is the issue of anti-bounce and how to connect these pushbuttons. First we go to the way to connect them, which you already know can be with the pull-up and pull-down resistors:
- Pull-Up- With this resistor setting, when the pushbutton is pressed, the microcontroller or Arduino can see or read a zero on that pin. That is, it interprets it as a LOW signal.
- Pull-down: In this case it is the opposite, you can read or receive a 1 or HIGH signal through the connected pin.
Do not confuse it with the NC or NA, which is something else different as we have seen previously. This is independent of the other ...
The pushbuttons have a rebound effect when pressed. That is, when it is pressed or released there is a fluctuation in the signal that passes through its contacts and could cause it to go from a HIGT state to LOW or vice versa without really wanting that to happen. That can produce an unwanted effect on the Arduino and make it do strange things, like activate an element when we really wanted to turn it off with the push button, etc. That's because the Arduino interprets the bounces as if it had been pressed more than once ...
That negative effect it has a solution. For this, a small capacitor must be implemented in the anti-bounce circuit (hardware method) or software (modifying the source code), whether a pull-up or pull-down configuration has been used or if it is NC or NO. In all these cases, the solution must be implemented to avoid these rebounds.
For example, pull-up and pull-down circuits with the anti-bounce capacitor they would look something like this:
While the software method It could be seen in this code snippet:
if (digitalRead (button) == LOW) // Check if the button is pressed
pressed = 1; // The variable changes value
if (digitalRead (button) == HIGH && pressed == 1)
// Perform the desired action
pressed = 0; // The variable returns to its original value
Simple project example
Once we have learned the topic of the ways to connect our pushbutton and the anti-rebound circuit, we are going to see a practical example to control an LED with the pushbutton. The scheme is equally simple as you can see.
Once connected correctly, the next thing is to write the code in Arduino IDE to program your panel and start experimenting with the buttons. A simple code example to control our circuit would be the following:
// Example of sketch to control the button
int pin = 2;
pulsating int = 0;
void setup ()
pinMode (2, INPUT); // To read the pulse by making that pin input
pinMode (13, OUTPUT); // For the LED
void loop ()
if (digitalRead (2) == HIGH)
pin = 2;
antiBounce (); // Call to the anti-bounce function
// Software anti-bounce function
void anti-bounce ()
while (digitalRead (pin) == LOW);
state = digitalRead (13);
digitalWrite (13,! state);
while (digitalRead (pin) == HIGH);