Skip to content
FlintMindsMiddle School
Middle School

Elementary

Blink an LED

Wire up your first circuit and write the code that makes a light blink on and off.

Level
Explorer
Time
20 min
Parts
5
Hardware-checked
Not yet

0 of 5 build milestones complete

What are we building?

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.

The mechanism

How it works

  1. Program

    Your code tells the pin to turn on.

  2. Digital Pin

    The pin outputs voltage when the code says HIGH.

  3. LED

    Current flows through the LED and it lights up.

What you'll pick up

  • Understand how current flows through a simple circuit
  • Learn why LEDs need a resistor
  • Write and upload your first program to a microcontroller
  • Use a loop and a delay to control timing

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.

Build it

  1. 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. 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. 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. 4

    Upload the blink code

    Connect your board to your computer and upload the code below.

Wiring

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.

Code

arduino
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.

Does it work?

  1. 1Upload the code and watch the LED.
  2. 2It should turn on for half a second, then off for half a second, repeating.
  3. 3Try changing 500 to 100 and re-upload to see it blink faster.

Make it yours

What can you change?

Small change

Change the rhythm

Speed up or slow down the blink by changing the delay values.

Add something

Add a second LED

Wire in a second LED and make the two blink out of sync with each other.

Design it yourself

Send a Morse code message

Use short and long blinks to spell out "SOS".

You decide how it works. No steps for this one.

If something's off

The usual causes, in the order they're worth checking.

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.

Do you know why 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 to build next

You now know:

  • Building a basic circuit
  • Controlling a digital output
  • Using timing and loops in code
  • What this leads to

    Move a Servo

    Blink an LED leads straight into this one.