

This is how you initialize the push button in your code. What we do here is to initialize Serial communication, so that we can use the Serial Monitor to print the data we got from the button. The void setup() function will be called first, only once. This way you just need to modify one line of the code, which is at the top of the program – and thus easy to find. This will make your life easier, especially if you want to plug the button to another pin later on. Code to setup the push button #define BUTTON_PIN 4įirst we create a #define for the button pin, so we don’t need to write “4” every time we want to use this pin in our code. Here is the code to print the button’s state 10 times a second. > Watch this video as an additional resource to this tutorial section:Īfter watching the video, subscribe to the Robotics Back-End Youtube channel so you don’t miss the next tutorials! Print the push button’s state What we’re trying to do here is to simply read the state from the button and print it 10 times per second. Also, if you want to know more about Arduino pins, check out this Arduino Uno pinout guide. In the following of this post we’ll talk more about this. This other wire goes to a digital pin, for example 4.Īs for now there is no resistor involved in the circuit.

If you have plugged the GND wire on the left side, then plug another wire on the right side, so they are not connected together. The top left and bottom left legs of the button are connected together, and the top right and bottom right legs are connected together.On one button’s leg, plug a wire (black if possible) to a GND pin on the Arduino board.Plug the push button in the middle of the breadboard, like on the picture.You are learning how to use Arduino to build your own projects?Ĭheck out Arduino For Beginners and learn step by step. Arduino push button with external pull down resistor.Arduino push button with external pull up resistor.Improvement: Print a more explicit message.Arduino code to read push button’s state.
