Skip to content
FlintMindsHigh School
High 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 this build is

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.

How it works

System architecture

  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.

Parts

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

  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.

Expected behaviour

  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.

Diagnosis

Symptoms and their usual causes. Work down the list — each check rules out a subsystem.

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.

Open problems

Extensions

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.

Check your understanding

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?

Where this leads

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.

The engineering brief for this project has not been written yet.

The problem statement, the constraints, the design decisions and the validation procedure are the parts of a project that make it worth an engineering student’s time, and this one does not have them yet. Writing them means building it with real components and measuring what it does — so rather than approximate, we are telling you they are missing. Why we do this.