Wire it on a real board
Using only the on-screen board? You can skip this step.
You need a push button, a 10K ohm resistor, a breadboard and three wires4.
Wire the button
- Run a wire from pin 2 to one leg of the button4.
- From that same leg, connect the 10K resistor to GND4.
- Connect the other leg of the button to 5V4.
Why the resistor?
With the button up, the resistor joins pin 2 to GND, so it reads LOW4.
With the button down, the button joins pin 2 to 5 volts, so it reads HIGH4.
Without the resistor, pin 2 is floating. It reads HIGH or LOW at random5.
Upload it and press
- Lesson 1, step 3 shows how to upload. Upload the sketch from step 2 the same way.
- Hold the button down. The light on pin 13 comes on, and it goes out when you let go3.
Not working? Start with the Stuck? checklist.
Sources for this page
- Arduino example: Button.ino: public domain
- Arduino tutorial: How to Wire and Program a Button: pull-down resistor; a floating pin
- Arduino reference: digitalRead