Learning Objective
Control high-power devices safely using a relay.
Relay Control & Electrical Isolation


Hardware: Single-channel relay module (low-voltage classroom use only)


Dashboard: Relay Control Card
See How the Relay Works
Read the picture from left to right: the command → what happens inside → the result.

1 · What it receives
A small, low-voltage signal from MakerBuddy.
2 · How it works
Current in a coil makes a magnet that moves a metal contact. The control and load circuits stay electrically separate.
3 · Why it matters
MakerBuddy can switch a separate classroom device (the load) with no direct electrical path between them.
Where might we use it?
- Low-voltage lamps
- Low-voltage fans
- Small classroom water pumps
Student sentence: A relay uses an electromagnet to flip an isolated switch for a separate load.
Teacher/parent prompt: Ask, “What goes in on the left, what happens inside, and how does it help someone?”
Theory: Relay Operation
Small Signals, Big Devices
So far we controlled low-voltage parts that run on 3.3-5V DC. Fans, lights and heaters at home use dangerous 120-240 V AC. Never connect household AC to an ESP32: it would destroy the ESP32 instantly. A relay is an electromagnetic switch. It lets a low-voltage signal control another circuit, with no electrical connection between the two sides.
How a Relay Works
An electromagnet is a coil of wire that becomes a magnet when current flows. When the ESP32 sets pin 23 to 3.3 V, a small transistor on the relay module switches on. It sends current from the board's 5 V supply through the relay coil. The coil becomes a magnet and pulls a metal arm (the armature) to open or close the contacts, which switch a separate circuit. Only magnetism links the two sides: this is galvanic isolation. So dangerous high voltage can't "leak back" to damage your ESP32.
The NO, NC and COM Terminals
A relay has three terminals: COM (Common), NO (Normally Open) and NC (Normally Closed). When off, COM connects to NC. When on, COM connects to NO instead. We wire the load between COM and NO, so it stays off until the relay switches on. The "click" you hear is the metal arm moving. Relay modules are often printed with ratings such as 10A 250VAC. Those ratings are for trained electricians working inside proper enclosures. In this course you only switch the supplied 5 V lamp or fan.
Real-World Applications
Smart home automation uses relays to switch lights, fans and heaters. Irrigation systems run water pumps with them.
For Teachers
A relay isolates the two sides and lets a tiny ESP32 signal switch a bigger load. The click shows the relay has moving parts, unlike a transistor. Safety: use only low-voltage demos in class. Never connect mains electricity in a student activity.
For Parents
Your child is learning about relays, which let smart devices switch big appliances safely. A small signal flips the switch, with no direct connection to dangerous household voltage.
Try It: Switch a Safe Load
Interactive demo · no kit needed
Play with a pretend MakerBuddy board and its web page, right here.
Follow the steps one at a time. Got the kit? You can switch to the real board inside.
Hands-On Activity: Relay Switching
Activity Duration: 20-25 minutes
Switch the relay from the dashboard, then use it to switch the supplied 5 V lamp or fan.
Step-by-Step Instructions:
- Connect the Relay Module: Unplug the USB cable. Plug the relay module into the 3-pin connector marked 23 on the bottom edge of your MakerBuddy IoT Board (it only fits one way), then plug the USB cable back in. Find the relay, its indicator LED and the low-voltage load connection.
- Open the Dashboard: Connect to your board and find the Relay card. Under Power Control is a switch labeled Relay On/Off.
- Activate the Relay: Turn the Relay On/Off switch on. Listen for the "click".
- Observe the LED Indicator: The module's small indicator LED lights up. (Some modules also have a power LED that stays on.)
- Deactivate the Relay: Turn the Relay On/Off switch off. A spring pulls the arm back with another click, and the LED goes off.
- Rapid Switching Test: Switch it ON and OFF quickly a few times. It acts the same way every time.
- Visual Inspection: Watch the blue relay as you switch it. In a clear-cased relay you can see the arm move!
- Connect the Supplied Load: With your teacher, and with the USB cable unplugged, connect the supplied 5 V lamp or fan through the relay's COM and NO terminals, powered from the board's two-pin 5V plug (5V → COM, NO → lamp, lamp → GND). Plug the USB cable back in, press 🔌 Connect again and switch the relay.
What Students Should Observe:
- A "click" every time the relay switches on or off
- The indicator LED lights only when the relay is on
- The relay answers dashboard commands almost instantly
- The dashboard switch always matches the relay's real state (ON/OFF)
Safety Note
Use only the supplied 5V bulb or 5V fan, powered through the MakerBuddy IoT Board’s 2-pin connector. Never connect 120-240 V mains electricity in a student activity. If you need a different load, use a teacher-approved low-voltage load such as 12V, never household mains.
Challenge
Your Mission: Understanding Electrical Isolation and Safety
Test how relays work, and think through electrical safety and isolation.
Challenge 1: Timing the Relay
Try to time the relay, then try automation:
- Start a stopwatch as you turn the Relay On/Off switch on; stop it at the click. The relay takes about a hundredth of a second, but pressing a stopwatch takes you about 0.2 seconds, so you are mostly timing yourself.
- Compare your times with a partner: what were you really measuring?
- Preview (you'll learn this in Week 26): in the 🎛️ Rule Engine, a 🎯 Condition rule with 🔘 Push Button Equal to (==) True and the steps ⚡ Relay On (Delay 2000 ms) → ⚡ Relay Off switches the relay from the board's button. Hold the button for about 2 seconds, never 10 seconds (that erases the Wi-Fi settings). Delete the rule afterwards so the Relay card unlocks.
- Which is faster? The dashboard switch acts at once. The rule waits for the board's once-a-second reading and a 0.3-second check, so it takes about 0.3 to 1.3 seconds.
Challenge 2: The Isolation Question
Answer by research and reasoning:
- Why can't we connect 120-240 V AC to the ESP32? (Hint: it runs on 3.3V DC.)
- What does "galvanic isolation" mean? Explain it in your own words.
- If the high-voltage side fails, can it damage the ESP32? Why or why not?
- Why use electromagnets instead of electronic switching? Find out why relays are still used.
Challenge 3: Design a Smart Home Application
Design a complete relay-controlled system.
Choose ONE scenario:
- Automatic Fan: Turn on the supplied 5 V fan when Temperature (DHT11) goes above 28 °C
- Motion-Activated Light: Turn on the supplied 5 V lamp (a model porch light) when the PIR detects motion
- Smart Irrigation: Switch a model pump (use the supplied fan as a stand-in) when Soil Moisture drops below 30 %
Write down:
- The sensor
- The threshold (trigger value)
- What the relay switches
- The rule in IF-THEN form
- Why that threshold is safe and efficient
Discussion Questions:
- Why is the "click" good? (It shows the relay is working)
- What do relays do better than transistors? (Full isolation, much higher currents)
- What are their downsides? (Slower switching, mechanical wear, noise)
- What if the contacts weld (stick) together? (Safety hazard: the load stays ON)
Bonus Challenge: A solid-state relay (SSR) has no moving parts. How is it different from a normal relay, how does it work, and when would you pick one? (Answer: SSRs switch with semiconductors. They are silent and faster, but cost more and get hotter. Use them for fast, repeated switching like LED dimming or motor speed control.)
Key Takeaways
✓ Relay Operation
When the ESP32 sends a 3.3 V signal to the relay module, the module powers its coil, which pulls a metal arm to switch the contacts. That is the click.
✓ Electromagnets
Current in a wire coil makes a temporary magnet. When the current stops, a spring pulls the arm back.
✓ NO vs NC Terminals
When off, COM connects to NC; when on, COM connects to NO. A load on COM and NO stays off until the relay switches on.
✓ Galvanic Isolation
Only magnetism links the ESP32 side and the load side. A high-voltage fault can't leak back to damage the ESP32.
Coming Up Next Week:
Week 16: Term 2 Project — The Data Logger
Learning Support
Use this quick guide to help every learner understand, practice and explain Relay Control & Electrical Isolation.
For students
Try it in three steps
- Say it: explain the main idea in one simple sentence.
- Show it: Trigger the relay and use it to switch only the supplied low-voltage classroom load.
- Stretch it: Diagram a safe automated circuit for a teacher-approved low-voltage fan or lamp.
Checkpoint: What was your input, what decision or process happened, and what was the output?
For teachers & parents
Coach without taking over
- Before: ask the learner to predict what will happen and why.
- During: use prompts such as “What changed?” and “What could you test next?” instead of giving the answer.
- After: ask for a 30-second explanation, one piece of evidence and one improvement.
Look for: safe handling, correct vocabulary, a result the learner can demonstrate, and an explanation in their own words.
Did you get it?
Three quick questions. Pick an answer to see whether it is right, and why.
1Why is a relay used to switch a bigger device instead of wiring it straight to the ESP32?
2What does the click you hear from the relay mean?
3Which load may you switch with the relay in class?
