Mission 01 · Stage 1

Blink LED

setup() and loop() program structure

Blink an external LED on a half breadboard through a current-limiting resistor connected to pin 13.

Blink LED circuit diagram

Pin connections

Part 1Part 2

Resistor

pin 1

Breadboard

6t b

Resistor

pin 2

Breadboard

10t b

LED

anode (+)

Breadboard

4t b

LED

cathode (-)

Breadboard

3t b

Arduino

pin 13

Breadboard

10t e

Breadboard

6t e

Breadboard

4t e

Breadboard

3t e

Arduino

GND

See it

Let's make a light blink!

Your very first program turns a tiny light on and off, over and over.

Blinking lights are everywhere — on TVs, toys, and even rockets!

The story

The problem

Before we build cool robots, we need to learn how an Arduino program is put together.

Think of it like

setup() is like getting dressed in the morning — you do it once. loop() is like brushing your teeth every day — you do it again and again.

Meet the parts

Holds all the parts and joins them, like a LEGO baseplate.

Breadboard

Our building board

Loading part…

It thinks and tells the light when to turn on and off.

Arduino

The brain

Loading part…

A tiny light that glows when it gets power.

LED

The light

Loading part…

Slows the power down so the light does not get hurt.

Resistor

The protector

Loading part…

How it works

1

setup() runs once

When the board turns on, setup() gets pin 13 ready. Then it never runs again.

void setup() {
  pinMode(LED_PIN, OUTPUT);
}
2

Turn the light ON

Pin 13 turns ON and the light glows.

digitalWrite(LED_PIN, HIGH);
3

Wait a little

The light stays on for half a second.

delay(500);
4

Turn it OFF and repeat

The light turns off, waits again, then loop() jumps back and does it all over — forever!

digitalWrite(LED_PIN, LOW);
delay(500);

Then loop back to step 2

Build the circuit

Follow these steps in order. Match the wires to the colors shown.

  1. 1

    Place Breadboard

    Place the Breadboard (bb1) on the breadboard.

    Breadboard placed — build like the real world!

    Loading part…
  2. 2

    Place Arduino

    Place the Arduino (uno) on the breadboard.

    Arduino placed — ready to build!

    Loading part…
  3. 3

    Place Resistor

    Place the Resistor (r1) on the breadboard.

    Resistor plugged into the breadboard across columns 6 and 10!

    Loading part…
  4. 4

    Place LED

    Place the LED (led1) on the breadboard.

    LED plugged in — anode in column 4, cathode in column 3!

    Loading part…
  5. 5

    Connect Arduino pin 13 to Breadboard (bb1) 10t.e

    Arduino pin 13 into the resistor's column 10 — use any free hole in that column

    Tip: Arduino pin 13 into the resistor's column 10 — use any free hole in that column

    Signal reaches the resistor through the breadboard!

  6. 6

    Connect Breadboard (bb1) 6t.e to Breadboard (bb1) 4t.e

    Jumper the resistor's column 6 to the LED's anode column 4 — any free hole in each column

    Tip: Jumper the resistor's column 6 to the LED's anode column 4 — any free hole in each column

    Resistor linked to the LED through the breadboard!

  7. 7

    Connect Breadboard (bb1) 3t.e to Arduino GND

    LED cathode column 3 straight to Arduino GND — any free hole in column 3

    Tip: LED cathode column 3 straight to Arduino GND — any free hole in column 3

    Circuit complete!

Try it

  • Press the green Run button — the light should start blinking!
  • Remember: setup() runs once, loop() runs forever.

Peek at code

The light's nickname

const int LED_PIN = 13;

LED_PIN is a nickname for pin 13. Using the nickname makes the code easy to read.

setup() — runs once

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

setup() runs one time when the board turns on. pinMode gets pin 13 ready to power the light.

loop() — blink forever

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

loop() turns the light on, waits, turns it off, waits — then starts over all by itself!

Show full sketch (blink-led.ino)
const int LED_PIN = 13;
void setup() {
  pinMode(LED_PIN, OUTPUT);
}
void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

Quick quiz

Q1. What does delay(500) do?

  • A. Waits half a second
  • B. Makes the light brighter
  • C. Turns on pin 500
Why: Yes! 500 means half a second between blinks.

Q2. Which part runs only one time when the board turns on?

  • A. setup()
  • B. loop()
  • C. delay()
Why: Right! setup() runs once at the very start.

Code lab — try on your own

  1. Make the light blink faster by making both delay numbers smaller.

    Hint: Try 200 or 300 instead of 500.

  2. Add a little note (comment) on the line that turns the light ON.

    Hint: Type // and your words at the end of that line.

  3. Add a note (comment) on line 1 that tells what LED_PIN is.

    Hint: Like: // my light is on pin 13

Code walkthrough

A line-by-line tour of the sketch — the same steps as in Robot Gurukul Studio.

Program overview

Big idea

Every Arduino program has a top part, a setup() part that runs once, and a loop() part that runs again and again.

In this project

We make a little light blink on and off forever.

Tip

Read from the top to the bottom. Tap any word or line if you need help!

const int LED_PIN = 13;

setup()

Big idea

setup() runs one time when the board turns on.

In this project

It gets pin 13 ready for our light.

Why here

Things we do only once go inside setup().

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

loop()

Big idea

loop() runs again and again, forever.

In this project

This is where the light blinks on and off.

Why here

Things that repeat go inside loop().

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

Try this: Change a number inside loop(), then press Run to see what happens.

pinMode

Big idea

pinMode tells a pin if it will listen or push power out.

In this project

It makes pin 13 ready to push power to the light.

Why here

It goes in setup() because we only set it once.

  pinMode(LED_PIN, OUTPUT);

digitalWrite

Big idea

digitalWrite turns a pin ON or OFF.

In this project

ON lights up the LED, OFF turns it dark.

Why here

It goes in loop() so the light can keep changing.

  digitalWrite(LED_PIN, HIGH);

delay

Big idea

delay means wait. Nothing else happens while it waits.

In this project

It keeps the light on (or off) long enough for us to see.

Why here

Right after we turn the light on or off.

  delay(500);