FAQ
TL;DR: Use a logic‑level N‑MOSFET (e.g., BS170: ~500 mA continuous, ~1.2 A pulse). “Make sure the ground of the solenoid power supply is connected to the ground of your Spark Core power supply.” This setup works with 3.3 V control and a higher solenoid voltage. [Elektroda, Screaming Circuits, post #21673753]
Why it matters: This FAQ helps makers drive 6–12 V solenoids from 3.3 V GPIO safely and reliably, avoiding blown parts and noise issues.
Quick Facts
- Pick a logic‑level N‑channel MOSFET; BS170 is a common starter choice for 3.3 V GPIO control. [Elektroda, Screaming Circuits, post #21673752]
- BS170 capability: Approx. 500 mA continuous, ~1.2 A pulse; choose a higher‑rated MOSFET if your coil needs more. [Elektroda, Screaming Circuits, post #21673753]
- Always include a flyback (Schottky) diode across the solenoid; anode to ground, cathode to MOSFET side. [Elektroda, Screaming Circuits, post #21673752]
- Keep relay/solenoid and logic grounds separate in layout; add a capacitor across the relay supply. [Elektroda, richard gabric, post #21673758]
- If using a separate coil supply, tie grounds together for a common reference. [Elektroda, Screaming Circuits, post #21673753]
What MOSFET works best to drive a 12 V solenoid from 3.3 V logic?
Use a logic‑level N‑channel MOSFET. The thread recommends BS170 as an accessible option for 3.3 V GPIO control of small coils. If your solenoid current is higher, select a MOSFET with a larger continuous current rating. [Elektroda, Screaming Circuits, post #21673752]
How should I wire the MOSFET—high‑side or low‑side?
Use the N‑MOSFET as a low‑side switch. Put the solenoid between +V and the Drain, and connect the Source to ground. This keeps the required gate‑to‑source voltage low and ensures full enhancement from a 3.3 V GPIO. [Elektroda, Pieter Kruger, post #21673762]
Why do I need a flyback diode, and what problem does it fix?
When you switch off an inductive load, the collapsing magnetic field generates a high reverse‑voltage spike (back‑EMF). That spike can destroy the MOSFET. A flyback diode provides a safe path for this current and protects the switch. “You need a flyback diode anytime you switch an inductive load.” [Elektroda, Screaming Circuits, post #21673757]
How do I orient the flyback diode across the solenoid?
Place the diode directly across the solenoid terminals. Connect the anode to ground and the cathode to the MOSFET/solenoid positive side. It looks reversed in normal operation, but it conducts only during turn‑off to clamp the spike. [Elektroda, Screaming Circuits, post #21673752]
What current can a BS170 handle, and what if my coil draws more?
BS170 supports about 500 mA continuous and around 1.2 A in brief pulses. If your solenoid’s hold current exceeds ~250 mA margin, choose a MOSFET with a higher continuous rating and lower RDS(on). That reduces heating and improves reliability. [Elektroda, Screaming Circuits, post #21673753]
Can I power the solenoid from a separate 6–9 V supply and still use 3.3 V control?
Yes. Drive the MOSFET gate from the 3.3 V GPIO, power the solenoid from its own supply, and tie the grounds together. “Make sure the ground of the solenoid power supply is connected to the ground of your Spark Core power supply.” [Elektroda, Screaming Circuits, post #21673753]
How do I reduce noise and protect my microcontroller board?
Do not mix high‑current and logic grounds in the same traces. Route coil current separately, then join grounds at a single point. Add a decoupling capacitor across the relay/solenoid supply to tame transients and dips. [Elektroda, richard gabric, post #21673758]
Why is my MOSFET only showing ~0.5 V on the output when I turn it on?
Check the MOSFET pinout against the datasheet. Some parts flip the usual Gate‑Drain‑Source order, causing miswiring and weak conduction. Correct pin mapping typically restores full switching behavior. [Elektroda, Screaming Circuits, post #21673760]
Is the control signal considered active‑high or active‑low in this setup?
With the suggested N‑MOSFET low‑side switch and pulldown on the gate, a logic high at the GPIO turns the solenoid on. A logic low turns it off. That’s an “Active High” configuration. [Elektroda, Screaming Circuits, post #21673752]
What gate resistor or pulldown do I need?
Include a gate‑to‑ground resistor so the MOSFET stays off during reset or boot. Connect the GPIO to the gate, and the pulldown to ground. This prevents accidental activation from a floating gate. [Elektroda, Screaming Circuits, post #21673752]
Can I buy a ready‑made driver board instead of wiring parts?
Yes. The SparkFun MOSFET power driver board integrates the MOSFET and protection parts, matching the thread’s guidance. It simplifies wiring and reduces common mistakes for beginners. [Elektroda, Joel Funk, post #21673761]
Will a 9 V coil supply work with the Spark Core’s 3.3 V GPIO?
Yes, if you use the MOSFET as a low‑side switch and share grounds. One participant confirmed planning a +9 V solenoid while keeping 3.3 V logic control. Add the flyback diode for protection. [Elektroda, Luke Weston, post #21673755]
Any quick wiring steps for a low‑side N‑MOSFET driver?
- Connect solenoid between +V and MOSFET Drain.
- Connect MOSFET Source to ground; tie logic and coil grounds together.
- Drive Gate from 3.3 V GPIO; add gate pulldown and a flyback diode across the solenoid. [Elektroda, Pieter Kruger, post #21673762]
What’s an edge case that can still bite me even with a diode?
If the MOSFET is mis‑pinned on your board, it can half‑turn‑on and show a small voltage, misleading debugging. Always confirm the package pinout before powering. “Double check the pin‑out in the datasheet.” [Elektroda, Screaming Circuits, post #21673760]
Do grounding practices affect reliability as much as parts choice?
Yes. Poor ground routing can inject switching spikes into the micro, causing resets or sensor glitches. Keep high‑current return paths away from logic returns and use local supply decoupling near the coil. [Elektroda, richard gabric, post #21673754]