Lesson 1 of 10

Meet the LED β€” Your First Blink

Turning code into light πŸ’‘

Mission Briefing

By the end of this mission, you will be able to:

  • Explain what an LED is and why polarity (direction) matters

  • Explain why a resistor is needed with an LED

  • Describe how a microcontroller turns an LED ON and OFF using HIGH and LOW

  • Build and code a circuit that blinks an LED every second

Let's Get Started

Have you ever wondered how the tiny lights in toys, robots, and gadgets turn ON and OFF? In this lesson, you'll meet the LED (Light Emitting Diode), one of the most popular electronic components. You'll learn how to safely connect an LED, why it needs a resistor, and how to use your ESP32 to make it blink.

Robo says: β€œEvery great electronics project starts with a single blinking LED β€” it's basically a rite of passage! Let's wire one up and bring it to life.”

Polarity (Direction Matters!)

LEDs have two legs, and they are not interchangeable:

  • Anode (+): the longer leg, connects to positive voltage

  • Cathode (–): the shorter leg, connects to ground

If connected the wrong way, the LED will not light up.

Current (Why We Need A Resistor)

LEDs require a limited amount of current to operate safely. Too much current can damage or burn out the LED.

  • A resistor is used in series with the LED to control current flow.

  • Typical value: 220Ξ© – 330Ξ© for Arduino/ESP32 projects.

Digital Output (Controlling With ESP32/ARDUINO)

A microcontroller (like an ESP32) controls an LED using a digital pin:

  • HIGH (1): sends voltage, LED turns ON

  • LOW (0): no voltage, LED turns OFF

This simple ON/OFF control is the foundation for more advanced projects like blinking patterns, dimming (PWM), and interactive electronics.

Equipment

  • ESP32 board
  • 1 LED
  • 220Ξ© resistor
  • Breadboard + jumper wires

Activity

Make an LED blink every second.

Challenge step

Wire your LED to the board: anode through the 220Ξ© resistor to a digital pin, cathode to ground.

Double-check the longer leg (anode) goes to the resistor side β€” see the wiring diagram at the end of this lesson if you're not sure.

Code

int ledPin = 2;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}

Did You Know?

  • β€’ LED stands for Light Emitting Diode β€” a diode that gives off light when current flows through it in the correct direction.
  • β€’ LEDs use far less energy and last far longer than old-fashioned incandescent bulbs, which is why they're used almost everywhere today.
  • β€’ The first practical LED was created in 1962 by engineer Nick Holonyak Jr.

πŸ”§ Try It Yourself

Try these challenges with your code, then write down what you changed:

Example: Changed both delay(1000) values to delay(500) to double the blink speed.

β€’ Change the blink speed from 1 second to 0.5 seconds.

β€’ Make the LED stay ON for 2 seconds and OFF for 1 second.

β€’ Count how many times the LED blinks in 10 seconds.

int ledPin = 2;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
Challenge step

Upload this code and confirm the LED blinks once per second.

Challenge step

Modify the code so the LED stays ON for 2 seconds and OFF for 1 second, then re-upload and observe the new pattern.

That's two different delay() values instead of matching ones β€” one controls the ON time, the other the OFF time.

Think About It

πŸ€” Discuss With a Partner or Write Your Answer

What do you think would happen if you swapped the LED's legs (reversed its polarity) in the circuit? Use what you learned about anode and cathode to explain your answer.

Quick Recap: Fill In The Blanks

1. The longer leg of an LED is called the ________ and connects to positive voltage.

2. The shorter leg of an LED is called the ________ and connects to ground.

3. A ________ is used in series with an LED to limit current and protect it from damage.

4. Sending ________ to a digital pin turns the LED ON.

Match It!

Draw a line (or write the matching letter in the blank) to connect each word to its meaning.

Check Your Understanding

  • I can explain what an LED is and why polarity (direction) matters

  • I can explain why a resistor is needed with an LED

  • I can describe how a microcontroller turns an LED ON and OFF using HIGH and LOW

  • I can build and code a circuit that blinks an LED every second

Quiz Time!

Question 1: What happens if you connect an LED backwards?

πŸ” Reveal answer (drag-select the blank space): B

Question 2: Why do we use a resistor with an LED?

πŸ” Reveal answer (drag-select the blank space): B

Question 3: Which ESP32 command turns a digital pin ON?

πŸ” Reveal answer (drag-select the blank space): B

Challenge Zone

πŸ† Level Up

Can you make the LED blink 10 times, then stop completely?

Challenge step

Make the LED blink exactly 10 times, then stop completely.

Robot Journal

In your own words, explain what would happen to your circuit if you forgot to include the resistor. Why does that matter?

Key Vocabulary

Term
Definition
LED
Light Emitting Diode β€” lights up when current flows through it correctly.
Anode
The longer leg of an LED; connects to positive voltage.
Cathode
The shorter leg of an LED; connects to ground.
Resistor
A component that limits current flow to protect the LED.
Digital Pin
A pin that can be set to HIGH (on) or LOW (off).

Lesson Wrap-up

πŸ€– Robo Says

You just built and coded your first electronic circuit β€” nice work! Next up: Lesson 2 β€” we'll give your LED some rhythm with custom blink patterns.

Wiring Diagram

Meet the LED β€” Your First Blink β€” wiring diagram

Quick Check

Quick check

Which leg of an LED is the anode (+)?

Prediction

What do you think happens if you wire the LED in backwards β€” anode to ground, cathode to the resistor?

Quick check

Complete the sentence: A ______ limits the current flowing to the LED so it doesn't burn out.

Quick check

Fill in the missing value: this pattern keeps the LED on for the same length of time it's off.

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(______); // same as the LOW delay below
  digitalWrite(LED_PIN, LOW);
  delay(1000);
}
Quick check

Match each term to what it means.

Anode
Cathode
Resistor
Digital Pin
Quick check

Put these steps in the order you'd follow to wire and blink an LED for the first time.

1Upload the code to the board
2Connect the cathode to ground
3Connect the anode through a resistor to a digital pin
4Write digitalWrite(pin, HIGH) in your code
Quick check

In your own words: why does an LED circuit need a resistor?

Finished this lesson?

Marks it complete and unlocks the next one.

Lesson list
Lesson 1 of 10