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

Arduino

pin 13

Breadboard

13t e

Resistor

pin 1

LED

anode (+)

LED

cathode (-)

Breadboard

tn 16

Breadboard

tn 3

Arduino

GND

See it

Every program has setup() and loop()!

Your first sketch: turn an LED on and off forever.

Blinking lights show power or status on almost every gadget.

The story

The problem

You need to understand how Arduino code is organized before anything else.

Think of it like

setup() is like getting dressed once; loop() is your daily routine on repeat.

Meet the parts

Connects components in rows like a real breadboard

Breadboard

Workspace

Loading part…

Decides when the LED is on or off

Arduino

Brain

Loading part…

Shows output from the code

LED

Light

Loading part…

Limits current to the LED

Resistor

Safety

Loading part…

How it works

1

setup() runs once

When power turns on, setup() configures pin 13 — then never runs again.

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

Turn LED on

Pin 13 goes HIGH and current flows through the LED.

digitalWrite(LED_PIN, HIGH);
3

Wait a moment

The light stays on for half a second.

delay(500);
4

Turn off and repeat

LED off, another pause, then loop() jumps back to step 2 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 added across breadboard rows 13 and 14!

    Loading part…
  4. 4

    Place LED

    Place the LED (led1) on the breadboard.

    LED ready on the breadboard!

    Loading part…
  5. 5

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

    Arduino pin 13 to breadboard row 13 e

    Tip: Arduino pin 13 to breadboard row 13 e

    Signal on the breadboard!

  6. 6

    Connect Resistor (r1) 1 to LED (led1) anode (+)

    Resistor to LED anode on the breadboard

    Tip: Resistor to LED anode on the breadboard

    LED linked to resistor!

  7. 7

    Connect LED (led1) cathode (-) to Breadboard (bb1) tn.16

    LED cathode to breadboard ground rail at column 16

    Tip: LED cathode to breadboard ground rail at column 16

    Ground rail linked!

  8. 8

    Connect Breadboard (bb1) tn.3 to Arduino GND

    Breadboard ground rail to Arduino GND

    Tip: Breadboard ground rail to Arduino GND

    Circuit complete!

Try it

  • Press Run — the LED should blink in the simulator.
  • Remember: setup() once, loop() forever!

Peek at code

Pin name constant

const int LED_PIN = 13;

LED_PIN is a friendly name for pin 13 — use it everywhere instead of repeating the number.

setup() — runs once

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

setup() runs one time when the board starts. pinMode says pin 13 is an output.

loop() — blink forever

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

loop() turns the LED on, waits, off, waits — then Arduino runs loop() again automatically.

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. Sets brightness to 500
  • C. Turns pin 500 on
Why: Correct—500 milliseconds is half a second between blinks.

Q2. Which function runs only once when the board starts?

  • A. setup()
  • B. loop()
  • C. delay()
Why: Correct — setup() runs one time at the start.

Code lab — try on your own

  1. Make the LED blink faster by lowering both delay() numbers.

    Hint: Try 200 or 300 instead of 500.

  2. Add a short comment on the line that turns the LED on (digitalWrite).

    Hint: Use // at the end or start of that line.

  3. Add a comment on line 1 explaining what LED_PIN means.

    Hint: Example: // external LED on pin 13

Code walkthrough

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

Program overview

Technical

Sketches have globals, then setup() once, then loop() forever.

In this project

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

Why here

Read from top to bottom. Hover words or lines for help!

const int LED_PIN = 13;

setup()

Technical

Runs one time when the board turns on.

In this project

Sets up pins and libraries for Blink LED.

Why here

One-time setup belongs here—not in loop().

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

loop()

Technical

Runs again and again after setup() is done.

In this project

This is the main action you see in Blink LED.

Why here

Repeating work (blink, read sensors) goes here.

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

Try this: Change numbers in loop(), then compile and run the simulator.

pinMode

Technical

Tells a pin if it listens or drives something.

In this project

Gets the Blink LED circuit ready in the simulator.

Why here

Goes in setup() because we only set pins once at the start.

  pinMode(LED_PIN, OUTPUT);

digitalWrite

Technical

Turns a pin ON or OFF.

In this project

Controls lights, motors, or buzzers in Blink LED.

Why here

Goes in loop() so it can keep changing while the program runs.

  digitalWrite(LED_PIN, HIGH);

delay

Technical

Waits for some time. Nothing else runs during the wait.

In this project

Controls speed so you can see Blink LED in the simulator.

Why here

Right after an action that should stay the same for a moment.

  delay(500);