A pushbutton is highly essential when it comes to connecting two points in your circuit once pressed. For instance, you can use it to turn on the LED once you press your push button. This means that a pushbutton is a vital component in most projects.
Therefore, mastering how to connect your push button switch to Arduino is vital for almost all your projects. As a result, in this article, we shall be discussing how to connect a pushbutton switch to Arduino. In this article, we shall be taking you through an example where we hook LED to push button switch using an Arduino.
Connecting a push button switch to Arduino
When connecting a push button switch to Arduino, you will require the following components:
- Arduino Uno
- Push button
- 220 Ohms and 10 KOhms resistors
However, you should note that these components will differ significantly depending on the project you will be working on.
To connect, you will take your push button and place it on a breadboard and then go ahead and put your LED with the longer end into pin 13 while the shorter end will be connected to the GND of your Arduino.
One end of your resistor should then be connected to 5 volts while the other end you should connect it to the switch terminal. The corresponding terminals should be connected to GND. Usually, the corresponding terminal is located on the same side as the first terminal.
Your first terminal, which has a resistor should be connected to pin 2 on your Arduino and then go ahead to load the program using correct codes. Once that is complete, you will be done with the connection, and you can now press your push button, and your LED will turn on.
Usually, when a push button is open or not-pressed, there will be no connection between two legs of your push button. As a result, the pins will be connected to ground via a pull-down resistor, and you will read LOW.
On the other hand, when the push button is closed or pressed, it will create a connection between the two legs hence connecting it to a 5 volts pin allowing you to read HIGH.
Point to note
You might as well consider wiring this circuit in the opposite direction using a pulp resistor allowing you to keep the input HIGH and then LOW once you press the button. If so, you will have to reverse the behavior of this sketch, allowing the LED to turn on and off once the push button is pressed.
When the digital I/O pin is disconnected from everything, your LED will end up blinking erratically. This often occurs as a result of the input floating, which randomly returns either LOW or HIGH. This is the reason as to why you will require a pull-up or a pull-down resistor in your circuit.
Point to note when connecting your push button switch to Arduino
When connecting your push button switch to Arduino, you will need to keep the following in mind:
- You should always connect one of your Arduino GND pins to a long power rail of a breadboard. This is often considered as the ground rail.
- Once that is in place, you should consider connecting the short leg of your LED to the same ground rail present on your breadboard, and the long one should be connected to a row on your breadboard.
- Your 220-ohms resistor should be connected from pin 13 onto the row where your LED’s long leg has been attached.
- Have your push button placed on your breadboard. Usually, most of the pushbuttons tend to straddle at the center trench of a breadboard.
- Connect the wires from the 5-volt pin to any side of your push button.
- From pin 2, connect a wire to the other side of your push button.
- One side of your 10 KOhms resistors should be connected from your ground rail on a breadboard to the other side of your push button. It should be on the same side as pin 2 connects.
- With a USB cable, you should go ahead and plug in your Arduino board.
- Open your Arduino IDE software
- Go ahead and open up the sketch for this particular section.
- On the top left, you should click the verification button. Once that is done, it will turn orange and then return to blue.
- When you click the upload button, it will turn orange before going back to blue once the sketch has been uploaded to the Arduino board.
- You can press your button several times in order to see how your LED will react at the pin 13.
Now you try! 🙂
How does a push button switch work?
For the electrical circuit to work, they need to be complete. This means that electricity has to flow uninterruptedly via wires and components. However, circuits are usually not complete throughout it has to be completed when you want to use it. This is where the push button switch comes in. The pushbutton switch has been designed to help in completing electricity flow in an electrical circuit.
They are often used in various applications including elevators, electric cars and stereos, among other vital functions. When turning on, the switch conducts electricity and allows for uninterrupted flow of electricity. On the other hand, when turned off, the push button will be suspended or float, meaning that electricity will be interrupted.
Anything cool is equipped with a switch button. This means that they are everywhere, and usually, there is a pleasure of pressing them. Furthermore, understanding how you can incorporate switches in your project is highly essential. There is no doubt that using a switch is as easy as you think and so is connecting one to an Arduino.
If you love carrying out DIY projects, understanding how to connect a pushbutton switch to Arduino will be beneficial. By adhering to the tips discussed in this article, you will come to understand how easy it is to connect a pushbutton switch to an Arduino. As we conclude, we hope that you have found this article beneficial.