Drive a solenoid valve from a GPIO
A microcontroller GPIO must switch a 12 V, 200 mA solenoid valve. Then a 24 V, 2 A valve. Then make the valve drop to a lower "hold" current after it pulls in.
| Level | ● screening |
| Track | Embedded & wearables |
| Really testing | A simple question that goes deep. |
Going deeper
Extra explanation that is not in the book: worked numbers, where people go wrong, and how to say it in the room.
Worked example — release time. Example coil: 12 V, 200 mA (60 Ω), assume 50 mH.
- Plain diode: the current decays with τ = L/R ≈ 0.8 ms; it takes about 2 ms to fall to 10%. The valve releases slowly.
- Diode + 24 V Zener: the coil sees about 37 V of reverse voltage, so the current falls in roughly 0.3 ms.
- Cost: the FET now sees 12 + 24 + 0.7 ≈ 37 V → use a 60 V part.
Energy per turn-off. ½·L·I² = ½ × 50 mH × (0.2 A)² = 1 mJ — easy for a small diode or Zener.
Hold mode. With a PWM period much shorter than L/R, the coil current follows the average voltage: about 30% duty for 30% hold current.
Where people go wrong
- No pull-down on the gate: the valve clicks during reset.
- A slow GPIO edge driving a large FET in its linear region.
- Forgetting the 24 V rail's bulk cap — the valve's pull-in current pulls it down.
Errata
No corrections known for this question. All errata
Ask about this question
Stuck on a step, or think something is wrong? Send it with EM-03 in the subject. Good questions get answered on this page, and corrections go into the next printing.
Related
← EM-02 Sizing I²C pull-upsEM-04 Power-on to main(): what takes time? →