PCB design · 14 November 2026 · Shalaka engineering team
Driving relays from a microcontroller: what to check before production
A relay circuit that clicks happily on the bench can still fail in the field: a pin that runs hot, contacts that weld, or every relay switching on for a moment when the board powers up. These are the checks we run on any board that switches loads.
Never drive the coil from the pin
A common 12 V PCB relay with a 400 Ω coil draws about 30 mA; the 5 V version of the same relay draws about 70 mA. Many microcontrollers only guarantee their logic levels at around 8 to 20 mA per pin, and the absolute maximum in the datasheet is a limit, not a working point. Even when the coil “works” directly from a pin, the pin and the chip run hot and the supply droops each time it switches.
Use a driver: an NPN transistor or a logic-level MOSFET per relay, or a Darlington array such as a ULN2003 for several. Size the base resistor or gate drive for the coil current with margin.
The flyback diode
When the driver switches off, the coil’s stored energy has to go somewhere. Without a diode across the coil, the voltage spike can reach far above the supply and damage the transistor. A diode across the coil (a 1N4148 or 1N4007 is typical, or the one built into a driver array, connected to the right rail) is mandatory. If the relay has to release quickly, a zener in series with the diode shortens the release time.
What the relays do at power-up
Between power-on and the moment firmware configures the GPIOs, pins can float or sit in their reset state. Some pins also toggle during boot. If a relay is on one of those, the load can switch for a fraction of a second at every restart. For a pump or a heater, that can damage equipment.
We put a pull-down on each driver input so the relay stays off until firmware decides otherwise, and we avoid boot-time-sensitive pins (on ESP32, the strapping pins) for anything that switches a load.
Contact ratings and the load
A relay rated “10 A” is usually rated for a resistive load. Motors, transformers, solenoids and LED drivers with large input capacitors are harder on contacts, through inrush current and arcing. We check the relay’s rating for the actual load type and derate. For inductive AC loads, an RC snubber or a varistor across the contacts extends contact life.
Spacing and heat
Mains tracks need creepage and clearance to the low-voltage side that matches the working voltage and the safety standard the product is tested to. Relays and their tracks also get warm, and an enclosure in a sunny panel adds to it. We check the layout for both before fabrication, because both are expensive to fix afterwards.
If your board switches mains loads and you want a second pair of eyes before the production run, book a discovery call.