Skip to content
RoboLearn
Not completed

Project: blink and button

What you’ll build

An LED you control with code, then with a push button, then a toggle switch made from code: press once for on, press again for off. This is exactly how a robot reads a bump sensor.

Parts

Part Qty
Arduino UNO (or compatible) + USB cable 1
Breadboard 1
LED (any colour) 1
Resistor: 330 Ω (UNO R3 / clones) or 470 Ω–1 kΩ (UNO R4) 1
Push button (4-leg tactile) 1
Jumper wires 4

Wiring

Arduino pin 8 ──── resistor ──── LED long leg (+)
LED short leg (−) ──── GND
Arduino pin 2 ──── button ──── GND
  1. Unplug the USB cable while wiring.
  2. Connect an Arduino GND pin to the breadboard’s blue − rail.
  3. Put the LED in the breadboard. Connect its short leg to the − rail.
  4. Connect the resistor from the LED’s long leg to an empty row, then a jumper from that row to pin 8.
  5. Place the button across the centre gap so its legs sit in two rows, say rows 20 and 22. Connect row 20 to pin 2 and row 22 to the − rail, both on the same side of the gap. (The legs facing each other across the gap are always joined; pressing connects row 20 to row 22.)

If it doesn’t work

Symptom Check
LED never lights LED backwards? GND wired? Code uses pin 8 and the wire is on pin 8?
LED always on (step 2) Button wired to 5V instead of GND, or INPUT instead of INPUT_PULLUP
Button does nothing Button rotated 90°. Its legs are joined in pairs, so try rotating it
Toggle flips twice or randomly Increase the debounce delay to 100

Still stuck? Work through My robot doesn’t work.

Finished this lesson?