Short answer
A relay is an electrically operated switch. A small current through its coil creates a magnetic field, which pulls a movable arm called the armature. The armature opens or closes a set of contacts. The control circuit and the switched load stay electrically separate, so a small signal can switch a larger load.
What is inside a relay
- Coil: wire wrapped around a core. Current through it makes an electromagnet.
- Armature: a movable metal lever that the magnetic field pulls.
- Contacts: metal pads that the armature moves to make or break the load circuit.
- Return spring: pulls the armature back to its resting position when the coil is de-energized.
When the coil is energized, the armature moves and changes the state of the contacts. When the power is removed, the spring returns the armature.
Normally open, normally closed, and common
Each set of contacts has a common (COM) terminal, plus one or two others:
- NO (normally open): the contacts are apart when the relay is at rest, and they close when the coil is energized.
- NC (normally closed): the contacts touch when the relay is at rest, and they separate when the coil is energized.
A relay with both NO and NC contacts on one common terminal is called SPDT. Its COM connects to NC at rest, and to NO when energized.
Contact types: SPST, SPDT, DPST, and DPDT
- SPST (single pole, single throw): one set of contacts, giving one on/off path. It suits simple switching, such as a fan or a headlamp.
- SPDT (single pole, double throw): one common terminal that can connect to either of two other terminals. It can switch between two loads.
- DPST (double pole, single throw): two sets of contacts that switch together. It suits switching two circuits at once.
- DPDT (double pole, double throw): two SPDT sets switched by the same coil. Wiper motors, which have several settings, are a typical use.
Car relays are often sold in these four types. In car wiring, a relay can take power directly from the battery for a headlamp or starter motor, while the original switch only triggers the relay’s coil.
Check the coil and contact ratings
Two sets of ratings matter:
- Coil voltage and current: the coil must be driven at its rated voltage. Common DC coil voltages include 5 V, 12 V, and 24 V. Many small coils draw tens of milliamps, which is more than most microcontroller pins can supply.
- Contact rating: the maximum voltage and current the contacts can switch. Contact ratings are often given separately for AC and DC. The DC rating is often lower, because a DC arc is harder to extinguish.
The coil also has a pull-in voltage, which is the voltage needed to close the contacts, and a lower drop-out voltage, at which the contacts release.
Drive a relay from a microcontroller
A microcontroller pin usually cannot supply a relay coil directly. A common approach uses a transistor as a low-side switch:
- Connect the relay coil between the supply and the transistor’s collector, or the drain of a MOSFET.
- Connect the transistor’s emitter, or the MOSFET’s source, to ground.
- Put a resistor between the microcontroller pin and the transistor’s base. A resistor in the 1 kΩ range is a common starting point for 3.3 V or 5 V logic, but check the transistor and coil current.
- Place a flyback diode across the coil, with its cathode toward the positive supply. A 1N4007 or 1N4148 is a common choice.
- Connect the microcontroller’s ground to the relay’s ground, so the switching signal has a common reference.
As a rough check on the base current, a 70 mA coil driven by a transistor with a current gain of 100 needs at least 0.7 mA of base current. Designing for more than the minimum gives margin, but the transistor’s datasheet sets the real limits. For a MOSFET, add a pull-down resistor from gate to source, so the gate stays off when the pin is floating.
Why use a relay?
A relay keeps high-current wiring short and direct. The control signal can travel on thin wire from a switch or sensor, while the heavy load current stays close to its source. Car wiring follows the same idea, where the headlamps or starter motor get current directly from the battery through the relay.
Relay or MOSFET?
A relay has moving contacts. It keeps the control circuit isolated from the load, it can switch AC, and it gives a clear open circuit when off. It is slower than a transistor, it has a limited number of switching cycles, and it makes an audible click. A MOSFET has no moving parts and switches faster. A single MOSFET is usually a DC switch, so switching AC needs a different arrangement. Power transistor vs MOSFET compares the two in more detail.
Mains loads need extra care
Relays are often used to switch mains-powered equipment, and mains voltage can be lethal. Use a relay module that is rated and certified for mains loads, keep high-voltage wiring enclosed and insulated, and have a qualified person check the work. If you are not sure, do not connect the load to mains.
For the relay coil’s flyback diode, see types of diodes. A solenoid works on a similar principle, as explained in what is a solenoid?. For relay symbols and the NO and NC labels on drawings, see schematic labels decoded.