Level 2Unit B · Session 11
11

Unit B · Things that move, things that show

The click that switches something bigger

What we are making: a relay clicking on and off under program control — the bridge between your little circuit and the rest of the world.

The idea

An Arduino pin can supply about 40 milliamps. A desk lamp needs thousands. So the board can never switch a lamp directly, no matter how clever the program is.

A relay solves this by being two separate circuits in one box. Your board operates a small electromagnet on one side; the electromagnet pulls a metal switch closed on the other side. The two sides never touch. That is why a 5 volt board can control something far larger than itself — and why you can hear the click.

New words
RelayAn electrically operated switch. Two circuits, kept apart.
COMCommon - the middle contact on the switching side.
NONormally Open. Disconnected until the relay operates.
NCNormally Closed. Connected until the relay operates.
Arduino UnoUSB to the laptop5VGND75V relay modulethe click you can hearVCCGNDINCOMNONCon / offLow-voltage loads only. Nothing from a wall socket, ever.
The relay. Your program switches the left side; the right side switches something else entirely.
Click, and click again
1int relayPin = 7;
2 
3void setup() {
4 pinMode(relayPin, OUTPUT);
5}
6 
7void loop() {
8 digitalWrite(relayPin, HIGH); // relay closes - you will hear it click
9 delay(3000);
10 digitalWrite(relayPin, LOW); // relay opens - another click
11 delay(3000);
12}

Do it

  1. Wire the three wires on the left side only. Leave COM, NO and NC empty today.
  2. Upload. Listen. You should hear a click every three seconds, and see the little red light on the module change.
  3. Put your finger on the relay body. You can feel it operate.
  4. Now wire a battery and a small torch bulb through COM and NO, and watch it switch.
⚠ Careful
Nothing from a wall socket. Not today, not in your project, not ever. These modules are printed with a mains voltage rating, and it is true of the metal parts inside — but a school breadboard, with bare wires and thirty pairs of hands around it, is not the place to use it. Batteries and battery-powered devices only. This is the one rule in this book with no exceptions.

Change it

  1. Change the timing so it is on for one second and off for five.
  2. Move the control wire from pin 7 to pin 6, and change the code to match.
  3. Wire your bulb through NC instead of NO. Predict what happens before you upload.
What you seeWhyWhat to do
No click at allNo signal, or no power to the module.Check IN is on pin 7, and that both VCC and GND are connected.
It clicks, but the bulb stays darkThe switched circuit is not complete.A relay only closes a switch. The bulb needs its own battery through COM and NO.
It clicks constantly, very fastThe delays are missing or in setup().Both delay lines belong inside loop().
The board resets whenever it clicksThe relay draws too much current.Power the relay from its own battery, sharing GND with the board.

What you learned

  • A relay is a switch your program can operate, and the two sides are separate.
  • NO and NC let you choose whether the default state is on or off.
  • A small circuit can control a large one. That is most of industrial control.
Challenge optional — only if you finish early
  • Make the relay run to a schedule — five seconds on, twenty-five off, all lesson.
10. How far away is that?