Blink an LED
Wire up your first circuit and write the code that makes a light blink on and off.
About 20 min
or read the story first0 of 5 steps done
What are we making?
Every robot starts with a single blinking light. In this project you'll wire an LED into a simple circuit and write a few lines of code that turn it on and off.
It's the same on/off logic that powers status lights, alarms, and indicators in real robots.
What you need
Microcontroller board × 1
The brain of your project. It runs the code that tells the LED when to turn on and off.
Breadboard × 1
Lets you connect parts together without soldering.
LED × 1
Lights up when electricity flows through it in the right direction.
220Ω resistor × 1
Protects the LED from too much current so it doesn't burn out.
Jumper wires × a few
Carry electricity between the board, breadboard, and LED.
Let's build it
- 1
Place the LED on the breadboard
Push the LED's two legs into two different breadboard rows. The longer leg (anode) is positive.
LED polarity diagram
Not drawn yet. We only publish a diagram once someone has built this with real parts and checked it — so rather than guess at the connections, we are telling you they are missing. The written wiring notes are accurate.
- 2
Add the resistor
Connect the 220Ω resistor in series between the LED's positive leg and an open row.
Resistor placement diagram
Not drawn yet. We only publish a diagram once someone has built this with real parts and checked it — so rather than guess at the connections, we are telling you they are missing. The written wiring notes are accurate.
- 3
Wire it to your board
Run a jumper wire from the resistor's row to a digital pin, and another from the LED's negative leg to GND.
Board wiring diagram
Not drawn yet. We only publish a diagram once someone has built this with real parts and checked it — so rather than guess at the connections, we are telling you they are missing. The written wiring notes are accurate.
- 4
Upload the blink code
Connect your board to your computer and upload the code below.
How it all connects
Blink an LED wiring diagram
Not drawn yet. We only publish a diagram once someone has built this with real parts and checked it — so rather than guess at the connections, we are telling you they are missing. The written wiring notes are accurate.
The LED's longer leg (anode) connects through the resistor to a digital pin; the shorter leg (cathode) connects to GND. Confirm the exact pin against the pin named in your code below.
The code
1const int ledPin = 9; // update to match the pin you wired2 3void setup() {4 pinMode(ledPin, OUTPUT);5}6 7void loop() {8 digitalWrite(ledPin, HIGH); // LED on9 delay(500);10 digitalWrite(ledPin, LOW); // LED off11 delay(500);12}13 - Line 1: ledPin stores which pin the LED is wired to — change this to match your circuit.
- Line 9: delay pauses the program, in milliseconds, before moving to the next line — that's what makes the blink visible.
Try it!
- 1Upload the code and watch the LED.
- 2It should turn on for half a second, then off for half a second, repeating.
- 3Try changing 500 to 100 and re-upload to see it blink faster.
Not working yet?
Nothing works the first time for everyone. Here's what to check.
- The LED doesn't light up at all.
- Check that the LED's longer leg (anode) is on the resistor side, not reversed.
- Nothing happens after uploading.
- Confirm ledPin in your code matches the pin you actually wired the LED to.
- The LED stays on constantly.
- Double-check your code uploaded successfully and that you're running the latest version.
Try changing it
Change the rhythm
Speed up or slow down the blink by changing the delay values.
Add a second LED
Wire in a second LED and make the two blink out of sync with each other.
Send a Morse code message
Use short and long blinks to spell out "SOS".
Do you know how it works?
1. What happens if you leave out the resistor?
2. In your code, what does the delay control?
3. Why does the code repeat in a loop?
What should you make next?
You just learned how to:
- Building a basic circuit
- Controlling a digital output
- Using timing and loops in code
Move a Servo
Control a small motor with code and turn it to exact angles, just like a robot arm.