


This is because when we read values at pin 2, we want to get either a HIGH or a LOW reported. We also have pin 2 connected to ground at all times through a resistor. To turn on an LED by pressing the button, we simply make an if statement whose condition says something like “…if the voltage at pin 2 is HIGH, turn on the LED at pin 13…” It is really that easy. During the times the button is not being pressed, pin 2 reports LOW. When you press the button it completes an electrical connection, pin 2 will “see” the 5 volts and if we digitalRead() at pin 2, it will report HIGH. In this example we simply hook up 5 volts to one side of a button and to the other side of the button we connect pin 2. Using a button is as easy as you might think, but at the same time can be a source of frustration.
#ARDUINO PUSH BUTTON TO START PROGRAM HOW TO#
Knowing how to employ them in your projects is very beneficial. They are everywhere and there is a certain pleasure in pressing them. Get 10 tips every new Arduino coder should know ➜ Arduino Course for Absolute Beginners Using a Button with ArduinoĪnything cool has buttons.
