Hardware · Control family

Relays and contactors.

What these are
A switch a small signal can flip
They do
Turn a big load fully on or off
Open Agriculture Technology pick
A relay module to switch from a microcontroller

A relay is the simplest actuator there is: a switch that a small control signal can flip. Where a motor driver delivers variable, reversible power, a relay just makes or breaks a circuit, fully on or fully off. It is how a 3.3 volt controller turns a heater, a grow light, a pump, or a solenoid valve on and off, switching a load far larger than the controller could ever handle itself.

An electromechanical power relay board
Image: adafruit.com

What a relay does.

A relay is an electrically controlled switch. A small signal closes (or opens) a set of contacts that carry a much larger current, and the control side is kept electrically separate from the load side. That separation is the point: the controller never touches mains voltage, it only tells the relay to flip. A relay is purely binary, on or off, with nothing in between. If on-or-off is all you need, it is the cheapest, simplest part for the job.

Switching versus driving.

This is the fork that decides which part you want. Switching means turning a load fully on or off, and that is a relay: a grow light, a heat mat, a pump that runs at one speed. Driving means controlling how a load runs, its speed or direction, and that is a motor driver. A fan you only ever turn on and off wants a relay; a fan whose speed you vary wants a driver. Get this right first and the rest of the choice is easy.

Compare the types.

Four ways to switch a load, side by side. The tinted column is the everyday pick for switching something from a microcontroller, because it bundles the relay with the parts you would otherwise have to add yourself.

Ways to switch a load · verified 2026-06-23
Spec Mechanical relay Relay moduleOpen Agriculture Technology pick Solid-state relay Contactor
Switches with Physical contacts Contacts + logic input Semiconductor, no contacts Heavy contacts
AC or DC Both Both One type only Both, high power
Moving parts Yes Yes No Yes
Lifespan Thousands of cycles Same as its relay Millions, no wear High, heavy duty
Noise Audible click Audible click Silent Loud clunk
Best for Bare-board switching Switching a load from an MCU Frequent cycling, heaters Big pumps and heaters

For the deep dives, see the relay module, the board most people actually wire to a microcontroller, and the solid-state relay, the silent, long-lived choice for switching a heater on and off often. A contactor is just a big, heavy-duty mechanical relay for large pumps and heaters. If you want a ready-made switch with no wiring at all, a smart plug is the safer path.

Driving a bare relay.

A bare mechanical relay has the same problem as a motor: its coil needs more current than a controller pin can give, and when the coil switches off it kicks back a voltage spike that can damage the controller. So you do not wire a relay coil straight to a pin. You drive it through a small transistor and add a flyback diode across the coil to absorb the spike. The easy way to skip all of that is to buy a relay module, which puts the transistor, the diode, and usually an optocoupler for extra isolation on a board with a tidy logic-level input.

A word on mains power.

Switching wall voltage is genuinely dangerous and deserves respect. Use parts rated and certified for the voltage and current of your load, give mains wiring a proper enclosure, and never run a load near a relay’s limit. Note too that a solid-state relay leaks a tiny current even when off, so it is not a true disconnect for safety. For a beginner, or any time wiring mains is not worth the risk, a plug-in smart plug does the same job with no exposed wiring.

Where they fit, and where they don’t.

Where they fit

  • Switching a grow light or heat mat on and off.
  • Turning a pump or fan on at one speed.
  • Opening and closing a solenoid valve.
  • Cycling a heater for temperature control (SSR).

Where they don’t

  • Varying speed or reversing; use a motor driver.
  • Precise positioning; use a servo or stepper.
  • Tiny signal switching, where a transistor is enough.
  • Mains, if you would rather not wire it; use a smart plug.

Guides and parts.

Straight from the makers; these open in a new tab:

Adafruit relay basics ESPHome GPIO switch Smart plugs & relays Actuators & Control

Frequently asked questions.

What is a relay used for?

A relay is an electrically controlled switch: a small signal from a controller flips it to turn a much larger load fully on or off, while keeping the controller separate from the load. In a grow setup it switches a heater, a grow light, a pump, or a solenoid valve from a 3.3 or 5 volt microcontroller.

What is the difference between a relay and a motor driver?

A relay switches a load fully on or off, nothing in between. A motor driver controls how a motor runs, its speed and direction. If you only ever turn a load on and off, like a grow light, use a relay. If you need to vary speed or reverse, like a fan you slow down, use a motor driver.

What is the difference between a mechanical and a solid-state relay?

A mechanical relay uses physical contacts moved by a coil; it clicks, switches AC or DC, and wears over many cycles. A solid-state relay switches with a semiconductor, so it is silent, fast, and lasts millions of cycles, ideal for frequent on-off like heater control. The trade-offs: a solid-state relay is usually AC-only or DC-only, leaks a little when off, and needs a heatsink at higher current.

Can I connect a relay straight to a microcontroller pin?

Not a bare relay. The coil needs more current than a pin supplies and kicks back a voltage spike when it switches off. Drive it through a transistor with a flyback diode across the coil, or simply use a relay module, which builds in the transistor, diode, and an optocoupler and gives you a clean logic-level input.

Is a relay safe for switching mains power?

It can be, with care. Use parts rated and certified for your load’s voltage and current, enclose the wiring, and stay well under the limits. Remember a solid-state relay leaks a small current even when off, so it is not a true safety disconnect. If wiring mains is not worth the risk, a plug-in smart plug does the same job with no exposed wiring.