Lesson 3 of 3 in Step 5 · Electricity and magnetism

Relays

By Mihai Dumitru · · 7 min read

On this page

A relay is a switch operated by an electromagnet. A small current through its coil pulls a metal lever, and the lever opens or closes a set of contacts. The circuit that drives the coil and the circuit that the contacts switch are completely separate, which is the main reason relays are used. This page builds on the transistor switch, diodes and electromagnets from the previous lesson in this step.

How it is built

Inside the plastic case is a coil of wire on an iron core, and next to it a hinged iron lever called the armature. When current flows through the coil, the core becomes a magnet and pulls the armature towards it, with an audible click. A spring pulls it back when the current stops. The armature carries a moving contact that touches one of two fixed contacts.

  • COM (common) is the moving contact.
  • NO (normally open) is connected to COM only while the coil is energised.
  • NC (normally closed) is connected to COM while the coil is off, and disconnected when it is on.

"Normally" means with the coil off. To switch a lamp on when the coil is energised, wire the lamp circuit through COM and NO. To keep something on until the relay operates, use COM and NC.

Why use a relay

The coil and the contacts are not electrically connected at all. The coil side can run on 5 V from a small circuit, while the contacts switch a 12 V motor or a lamp on a completely separate supply. This separation is called isolation. Relay contacts don't care whether they switch AC or DC, and a closed contact has almost no voltage drop, so it barely warms up.

Relays have downsides too. They are slow compared with a transistor, taking a few milliseconds to switch. They click, they use a fair amount of coil current, and their contacts wear out after many thousands of operations. For switching LEDs or small motors quickly, a transistor is usually the better choice. Relays shine where isolation, or switching AC, matters.

Driving the coil

A typical small relay with a 5 V coil has a coil resistance of about 70 Ω, so it draws about 5 ÷ 70 = 71 mA. That is several times what a microcontroller pin can supply, so a transistor switches the coil, exactly as on the transistor switch page. With a minimum hFE of 100, the smallest base current is 71 ÷ 100 = 0.71 mA. Multiplied by about five for a reliable switch, that is 3.6 mA. From a 5 V pin the base resistor is (5 − 0.7) ÷ 0.0036 = 1,190 Ω, rounded down to 1 kΩ.

A schematic. A control pin connects through a 1 kΩ resistor to the base of an NPN transistor whose emitter goes to ground. The relay coil sits between plus 5 V and the collector, with a diode across the coil, its cathode towards plus 5 V. The relay contacts COM and NO switch a lamp on a separate 12 V battery.
The relay driver: a transistor switches the coil, a diode catches the spike, and the contacts switch a separate 12 V circuit.

The flyback diode

A coil resists changes in its current. When the transistor switches off, the current through the coil can't stop instantly, and the collapsing magnetic field produces a short voltage spike, often many times the supply voltage and in the opposite direction. Without protection, that spike appears across the transistor and can destroy it in one switching operation.

The cure is a diode connected across the coil, pointing backwards: its cathode to the positive supply side, its anode to the transistor side. In normal operation it is reverse-biased and does nothing. When the spike comes, the diode conducts and lets the coil's current circulate through it until the energy has faded, usually within a millisecond. An ordinary 1N4001 or 1N4148 is enough for a small relay. This diode is called a flyback diode, and every coil switched by a transistor needs one, including motors.

Check yourself

  1. What do COM, NO and NC mean on a relay?

    Show the answer

    COM is the moving contact. NO is connected to it only while the coil is energised. NC is connected to it while the coil is off.

  2. A relay coil with 5 V across it has a resistance of 100 Ω. What current does it draw?

    Show the answer

    5 ÷ 100 = 0.05 A, which is 50 mA.

  3. Why does a relay coil switched by a transistor need a diode across it?

    Show the answer

    When the current stops, the coil's collapsing field produces a large voltage spike that can destroy the transistor. The diode gives the coil current a safe path until the energy fades.

  4. Which way round does the flyback diode go?

    Show the answer

    Reverse-biased in normal operation: cathode to the positive supply side of the coil, anode to the transistor side.

Read next