Lesson 1 of 5

Meet the Relay β€” Switching High Power with Low Power

A tiny signal that controls a big device βš‘πŸ”Œ

Mission Briefing

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

  • Explain what a relay module is and what problem it solves

  • Describe the difference between active-HIGH and active-LOW relay modules

  • Wire a relay module to the ESP32 safely

  • Turn a relay ON and OFF using code

Let's Get Started

The ESP32's pins can only handle a tiny bit of power β€” nowhere near enough to run a lamp, fan, or appliance directly. So how do smart plugs and home automation systems control full-powered devices? The answer is the relay.

Robo says: β€œA relay is like a tiny robotic hand that flips a real power switch for you, based on a signal from your code. Let's meet it.”

What Is A Relay?

A relay is an electrically-controlled switch. A small, safe signal from the ESP32 (just a few volts) controls an internal switch that can turn a completely separate, much higher-power circuit on or off β€” without the two circuits ever touching each other directly. This is what lets a tiny microcontroller safely control something like a lamp, fan, or appliance.

Active High Vs. Active Low

Important: many relay modules are β€œactive LOW,” meaning they turn ON when the signal pin receives LOW, and OFF when it receives HIGH β€” the opposite of what you might expect from earlier lessons. Always check your specific module before wiring it up.

Safety First

In this unit, you'll always demo with a simple LED circuit, never a real mains-powered appliance. Working with mains voltage (the power from a wall outlet) is dangerous and should only ever be done by a qualified adult under proper safety conditions.

Wiring

This lesson's circuit connects the relay like this:

  • VCC β†’ 5V

  • GND β†’ GND

  • IN β†’ GPIO 5

  • Relay NO (normally open) β†’ LED circuit for demo

Meet the Relay β€” Switching High Power with Low Power β€” wiring diagram

Equipment

  • ESP32
  • Relay module (5V, single-channel)
  • Jumper wires
  • LED + 220Ξ© resistor (for safe demonstration)

Activity

Turn the LED ON and OFF via the relay.

Code

int relayPin = 5;
void setup() {
pinMode(relayPin, OUTPUT);
}
void loop() {
digitalWrite(relayPin, HIGH); // Relay ON
delay(2000);
digitalWrite(relayPin, LOW); // Relay OFF
delay(2000);
}

Did You Know?

  • β€’ Relays are what let a tiny β€œsmart plug” you can buy online control a lamp or fan using just a phone app.
  • β€’ The clicking sound you sometimes hear from an appliance turning on and off is often literally the relay's internal switch physically snapping open or closed.

πŸ”§ Try It Yourself

Run the code and observe the relay, then write down what you noticed:

Example: The relay clicked audibly every 2 seconds as it switched.

β€’ Did you hear the relay click as it switched?

β€’ Was your module active HIGH or active LOW?

int relayPin = 5;
void setup() {
pinMode(relayPin, OUTPUT);
}
void loop() {
digitalWrite(relayPin, HIGH); // Relay ON
delay(2000);
digitalWrite(relayPin, LOW); // Relay OFF
delay(2000);
}

Think About It

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

Why do you think it's safer to control a high-power appliance through a relay, instead of connecting the appliance's wiring directly to the ESP32?

Quick Recap: Fill In The Blanks

1. A relay is an electrically-controlled ________.

2. A relay lets a low-power signal control a completely separate, ________-power circuit.

3. A relay module that turns ON when it receives LOW instead of HIGH is called active ________.

4. In this unit, you will only ever demo relays using a safe ________ circuit, never a real appliance.

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 a relay module is and what problem it solves

  • I can describe the difference between active-HIGH and active-LOW relay modules

  • I can wire a relay module to the ESP32 safely

  • I can turn a relay ON and OFF using code

Quiz Time!

Question 1: What problem does a relay solve?

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

Question 2: What does β€œactive LOW” mean for a relay module?

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

Question 3: In this unit's lessons, what do you use to safely demonstrate a relay instead of a real appliance?

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

Challenge Zone

πŸ† Level Up

Can you make the relay switch on and off in a specific pattern (like two short clicks, then a long pause) instead of a steady 2-second interval?

Robot Journal

Explain in your own words why a relay is needed to safely control something like a lamp or fan with a microcontroller.

Lesson Wrap-up

πŸ€– Robo Says

You just safely switched real power with code! Next up: Lesson 2 β€” you'll add a button so you can flip that switch yourself.

Finished this lesson?

Marks it complete and unlocks the next one.

Lesson list
Lesson 1 of 5