A solenoid is an electromechanical device that converts electrical energy into linear motion. When you energise the coil, a plunger moves in or out — and this simple action powers everything from door locks and water valves to pinball machines and vending machine dispensers. This guide covers solenoid types, how to safely drive them with Arduino using relays and MOSFETs, and practical project ideas for automation.
Solenoid Types
Push-Type Solenoid
The plunger pushes out when energised and retracts via a spring when de-energised. Used for door lock bolts and ejector mechanisms.
Pull-Type Solenoid
The plunger pulls in when energised. Used for latches, lever actuation, and valve opening.
Solenoid Valves
Solenoid with an integrated valve body. Normally closed (NC) valves open when energised, normally open (NO) valves close when energised. Used for water, air, and gas flow control.
Electromagnetic Locks
Holding solenoids that create a strong magnetic field to hold a door or gate. Release when power is cut (fail-safe for fire safety).
Understanding Specifications
| Specification | Meaning |
|---|---|
| Voltage | Operating voltage (5V, 12V, 24V). Must match your supply. |
| Current | Continuous draw when energised. Typically 0.3-2A. |
| Force | Push or pull force in Newtons or grams. |
| Stroke | Distance the plunger travels (5-30mm typical). |
| Duty Cycle | Maximum on-time percentage before overheating. |
Driving Solenoids Safely
Never connect a solenoid directly to Arduino. Solenoids draw far more current than Arduino pins can supply (40mA max). Use a relay module or MOSFET with a flyback diode.
The flyback diode is critical — when a solenoid de-energises, its collapsing magnetic field generates a voltage spike (back-EMF) that can destroy transistors and microcontrollers. A diode placed across the solenoid absorbs this spike.
Relay Circuit
The simplest approach uses a relay module to switch the solenoid power:
- Arduino digital pin → Relay module IN
- Relay module VCC → Arduino 5V, GND → GND
- Relay COM → 12V supply positive
- Relay NO → Solenoid positive
- Solenoid negative → 12V supply negative
const int relayPin = 7;
void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Relay off (active low)
}
void loop() {
digitalWrite(relayPin, LOW); // Activate solenoid
delay(1000); // Hold for 1 second
digitalWrite(relayPin, HIGH); // Release
delay(3000);
}
MOSFET Circuit
For faster switching and PWM control, use an N-channel MOSFET (like IRF540N):
- Arduino PWM pin → 220 Ohm resistor → MOSFET gate
- MOSFET drain → Solenoid negative
- MOSFET source → GND
- Solenoid positive → 12V supply
- 1N4007 diode across solenoid (cathode to positive)
- 10K resistor from gate to GND (pull-down)
Project Ideas
- RFID Door Lock: Read an RFID card, verify the UID, activate the solenoid lock for 3 seconds.
- Automatic Plant Watering: Solenoid valve opens based on soil moisture sensor readings.
- Sorting Machine: Solenoid pushers activated by colour or weight sensors to sort objects into bins.
- Smart Letterbox: Solenoid locks the letterbox; notifies via WiFi when mail is detected.
Frequently Asked Questions
Why does my solenoid get very hot?
Solenoids are designed for intermittent duty. Keeping them energised continuously overheats the coil. Use PWM to reduce holding current after initial pull-in, or choose a solenoid rated for continuous duty.
Can I control a solenoid valve with PWM?
Solenoid valves are binary (open/closed), so PWM does not provide proportional flow control. However, you can use PWM to reduce holding power after the valve opens — full power to open, then 50% PWM to hold, reducing heat.
What is a flyback diode and why is it important?
When a solenoid de-energises, its coil generates a reverse voltage spike that can reach hundreds of volts. A flyback diode (1N4007) placed across the solenoid absorbs this spike, protecting your MOSFET, relay, or Arduino from damage. Never omit this diode.
Conclusion
Solenoids are the simplest actuators for on/off linear motion. Whether you need to lock a door, open a valve, or push an object, a solenoid driven by a relay or MOSFET from Arduino provides a reliable, cost-effective solution. Just remember: use a flyback diode, never exceed the duty cycle, and always use external switching — never drive a solenoid directly from Arduino pins.
Shop solenoids, valves, and electromagnets at Zbotic.in.
Add comment