Dear friends welcome to the Arduino Easy Button Tutorial! In this tutorial, we are going to see the easiest way to connect a button to any Arduino Board. We are taking advantage of the internal pull-up resistor of the digital pins of the Arduino board, and the connection is extremely easy.

Intro to the Arduino Easy Button Tutorial

 

In previous videos, we learned how to connect a button to Arduino and how to debounce it. You can check them out now before watching this video. Then, a couple of viewers commented that there is an easier way to connect the push button to Arduino. I tried it and it works! That’s the power of our community. It’s a kind of collective knowledge and wisdom. Thank you, guys! Let’s see.

——————–
WHERE TO BUY
——————–

1. Cheap Arduino Uno: https://educ8s.tv/part/ArduinoUno

2. A pushbutton: https://educ8s.tv/part/Buttons

3. LED: https://educ8s.tv/part/LEDs

4. Small Breadboard: https://educ8s.tv/part/SmallBreadboard

5. Wires: https://educ8s.tv/part/Wires

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

Every digital pin of Arduino has an internal pull-up resistor. The value of that resistor is between 20-50KΩ depending on the microcontroller chip. Imagine this as a resistor which is connected to 5V. We can enable that resistor by software. So, if we enable that internal pin resistor and connect a LED to that pin, the LED will dimly light as it is now connected to 5V via a 50KΩ resistor. So, the idea is that we can exploit this internal pin resistor in order to get rid of the external resistor we were using so far in order to connect a button to Arduino. So, the new easy connection of the button to Arduino is this: One leg of the button goes to Arduino GND and the other goes to any digital pin we like! Now, if we run the simple program that lights up the LED each time we press the button, we can see that it works fine! Easier, isn’t it? We don’t use a resistor anymore and the connection can’t be easier.

Now, let’s see the code of the project. As you can see, the code of the project is a modified version of the button sketch of Arduino examples. In order to enable the internal pull-up resistor, we have to declare the pin that the button is connected to as INPUT and then write HIGH to it, even though it is declared as INPUT. That way, we can enable the internal pull-up resistor of the pin. If we now run the program, we are going to notice a strange behavior. The LED stays on if the button is not pressed and goes off when the button is pressed. That’s the opposite of what we want, isn’t it? The reason for that is that our circuit now works as ACTIVE_LOW, because when the button is not pressed, it is connected to 5V and when it is pressed it is connected to Ground.

All we need to do is to make a small change to the code and we are ready. We define the state of the button as ACTIVATED when it is LOW which means that it is connected to Ground and that happens when the button is pressed. Then we change this line here. If the button is ACTIVATED we light up the LED. That’s it. As you can see, the program is working now as expected. As you can see, with a few changes in the code, we can connect a button to Arduino much easier. I am going to follow this procedure from now on when I plan to use a button in a project because it is easier and of course it uses fewer parts!

 

——————–
CODE
——————–

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv