Solenoid tap on an Arduino Uno
An Uno taps a 12 V solenoid once a second through a MOSFET, with a diode across the coil to catch the kick when it lets go. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Intermediate Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Solenoid tap: an Uno taps a 12 V push-pull solenoid once a second through
// a MOSFET, with a diode across the coil to catch the kick.
//
// solenoid one lead to the 12 V supply, the other to the MOSFET's drain
// MOSFET IRLZ44N: gate -> pin 9, source -> GND
// diode 1N4007 across the coil: cathode to 12 V, anode to the drain
// supply 12 V, its - to GND, shared with the Uno
//
// The coil draws 300 mA, fifteen times what a pin can give, so the pin only
// drives the MOSFET's gate and the MOSFET carries the current.
//
// The diode is the part people leave out. A coil's current cannot stop at
// once: when the MOSFET turns off, the coil keeps pushing current and the
// drain voltage climbs until something conducts. Without the diode that is
// the MOSFET itself, at well over its 55 V rating. With it, the current goes
// around the diode and the coil instead, and the drain sits one diode drop
// above the supply while the current dies away.
//
// Things to try. Watch the plunger: it moves a few milliseconds after the pin
// goes high, while the current builds, and takes its travel time to seat.
// Put a multimeter on the drain and delete the diode: run it again and see
// how high the drain goes.
const int GATE_PIN = 9;
const unsigned long PULSE_MS = 120;
const unsigned long PERIOD_MS = 1000;
unsigned long taps = 0;
void setup() {
Serial.begin(9600);
pinMode(GATE_PIN, OUTPUT);
digitalWrite(GATE_PIN, LOW);
Serial.println("Solenoid ready");
}
void loop() {
digitalWrite(GATE_PIN, HIGH);
taps++;
Serial.print("Tap ");
Serial.println(taps);
delay(PULSE_MS);
digitalWrite(GATE_PIN, LOW);
delay(PERIOD_MS - PULSE_MS);
}
Parts list
6 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Full-size breadboard
- 1 × MOSFET
- 1 × Diode
- 1 × Solenoid
- 1 × Bench power supply
How it is wired
4 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; MOSFET pin S; Bench power supply pin V-
- Arduino Uno R3 pin 9; MOSFET pin G
- MOSFET pin D; Diode pin A; Solenoid pin 2
- Diode pin C; Solenoid pin 1; Bench power supply pin V+
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.
Free forever. Every board and part. Saves your projects. Works on Chromebooks.