The threshold voltage of the BS170 is too high to operate off 3.3V.
if you look at the BS170 datasheet you will see from Fig1 on page 3 that at 3.3v it will only pass about 200 mA which is almost certain not enough to drive the solenoid.
The MOSFET will possibly pass enough current to heat up significantly so be careful operating in this state.
You depict a TO220 package - the only data sheet I could find was for smaller packages - is it really a BS170?
You need to find a device that will turn on adequately with only 3.3v drive or amplify the voltage up to a reasonable drive level.
Older MOSFETs we designed for 10V gate drive, a number of logic-level devices were the designed to be driven by 5V logic. There are even fewer that will work from 3.3v.
You need to know how much current the solenoid requires in order to select the MOSFET.
http://www.mouser.com/ds/2/308/BS170-1118810.pdf
Answer from Kevin White on Stack ExchangeHello all,
So to give a brief summary, I'm developing a control board for some of my milling machine's peripherals. The bit that has been giving me trouble is a solenoid valve for the misting system. I've gone through a few tests a few times now that seemed to work, and then ordered a PCB with the changes, but problems seem to keep coming up (hence I'm asking here now as I'm a bit tired of it).
The hardware
The output voltage of the GPIO on my mill's controller (MicroMill 2000HD/LE)seems to be 5mA @ 3.3V (I was told 5mA @ 5V by the manufacturer, but this turned out to be wrong. Waiting on further responses from them...). I found out that the parallel port pins of my mill PC was being passed directly through to this GPIO port, with a 1K pull-up to 5V (diagram). It seemed to happily source ~53mA when quickly shorted, but I presume somewhere in the range oif 10mA is safer.
The solenoid I am using operates at 12V DC (7W), consuming ~600mA.
The schematic
Here's the schematic. The OUT1 pin is 3.3V. On the right side, the optocoupler should control the solenoid connected to J9.
I decided to use an optocoupler (CPC1301GR) in order to control the solenoid with the GPIO, as this one has a low input control current. My choice of resistor (900ohm) should draw ~3.67mA. I am also aiming to isolate the peripherals (e.g. solenoid) from the rest of controller, hence another reason why I chose an optocoupler.
The results
Unfortunately, it's misbehaving (as you may have guessed). If I briefly toggle OUT1 (thus not fully saturating the solenoid coil), the optocoupler is able to 'shut off'. However, leaving OUT1 high for a few moments (thus saturating and actuating the solenoid valve), then setting OUT1 low, causes the optocoupler to remain conducting (across pins 3/4) until I remove power.
I am noticing now in the optocoupler datasheet in the "CTR vs. LED Current (IF)" graph, I should have a CTR at around 4000% from the 3.67mA that should be sourced from OUT1, thus resulting in ~147mA that can be drawn across the optocoupler pins 3/4 (if I have understood the datasheet correctly). However, I don't understand how the solenoid could be actuating with this little current (unless the optocoupler has become damaged at this point).
So obviously my design is bad, and I should redo this. So I am wondering, how should this circuit actually be properly designed (i.e. did I miss anything important?), or should I consider an alternative approach not using an optocoupler? If any more info is needed, I would be happy to provide.
Thanks for reading all this, and any help/advice is appreciated!
Some updates: I have updated the design to this using some advice on designing around parallel port data pins. The Microcap sim of the design with OUT1 high can be seen here as well.
From playing around with it so far, this looks like it will be a more reliable design.
I should have a CTR at around 4000% from the 3.67mA that should be sourced from OUT1, thus resulting in ~147mA
Which would exceed the 150mA dissipation rating, burning your opto and possibly making it short out?
Why not use a MOSFET? I use AO3400 for this sort of thing all the time, works great - just don't forget the flyback diode
Current limiting in the FAQ and Wiki:
https://www.reddit.com/r/AskElectronics/wiki/faq#wiki_power
https://www.reddit.com/r/AskElectronics/wiki/faq#wiki_current_limiting_resistors
https://www.reddit.com/r/AskElectronics/wiki/design/leds
Please check the FAQ/Wiki before posting. If those pages don't help, please let us know here and we'll use the feedback to help improve them. Thanks!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
I'm looking for a solenoid that I can control from an Arduino pro mini 3.3V. The solenoid would be used as a means to open a springloaded hinged box. I'd want that solenoid to pull in for a short time freeing the lid to open. I'm thinking the 'movable pin' part should be about an inch or two long and have at least 0.5 inch travel. Can this be powered by one of the io pins or will I need to use a relay to provide power? I know nothing about solenoids and their power consumption so perhaps what I'm planning is a bad idea.
The threshold voltage of the BS170 is too high to operate off 3.3V.
if you look at the BS170 datasheet you will see from Fig1 on page 3 that at 3.3v it will only pass about 200 mA which is almost certain not enough to drive the solenoid.
The MOSFET will possibly pass enough current to heat up significantly so be careful operating in this state.
You depict a TO220 package - the only data sheet I could find was for smaller packages - is it really a BS170?
You need to find a device that will turn on adequately with only 3.3v drive or amplify the voltage up to a reasonable drive level.
Older MOSFETs we designed for 10V gate drive, a number of logic-level devices were the designed to be driven by 5V logic. There are even fewer that will work from 3.3v.
You need to know how much current the solenoid requires in order to select the MOSFET.
http://www.mouser.com/ds/2/308/BS170-1118810.pdf
Do you have an actual schematic of your circuit? The graphic you showed has the gate on the middle leg of the MOSFET's package, that isn't the case for the MOSFET whose datasheet you linked. Values of your pull-down resistors would be helpful too.
Without further information, I would say the threshold voltage is too large to be turned on by the 3.3V logic. The max threshold voltage of your transistor under tested conditions is 2V, this isn't a huge amount of leeway.
Measuring 12V between drain and source doesn't mean that the solenoid should be activated. If you measure across a 12V battery whose terminals are unconnected you will measure 12V. The transistor is not turned on so there is effectively an open circuit between the drain and source, you will measure 12V but not current will flow.
You sure could. Make sure the 12V supply is able to accept current flowing into it, as well as providing current flowing out.
But it's more efficient to use an "H-bridge" circuit to reverse both ends.
To move in one direction, you put one end at 0V and the other end at 24V.
To move in the other direction, you put one end at 24V and the other end at 0V.
The half-H-bridge is just a pair of switches, one to 24V and one to 0V, so that the output can be either 24V or 0V depending on which one you turn on. Turning on both at the same time creates a short circuit, so don't do that. The H-bridge is just two halves, one for each end of the solenoid.
Of course, the solenoid has to be mechanically designed to work in both directions, too. There's no point moving a solenoid both ways, if one way causes it to bump into an end stop and not move.
The solenoid must use a permanent magnet in the moving piece, because iron that isn't magnetized will be attracted to either a north or south field equally well - reversing the current will reverse the magnetic field but that won't achieve anything.
Could you use an opamp to raise and lower S2 to control the flow of current through the solenoid?
Thats fine, there are a few problems. One is overvoltage from the solenoid actuating. If it simply to turn the solenoid on and off, then an opamp would be an expensive way to do this.
You can use hit and hold if circuits if you need different current/voltage levels: How do I use a hit and hold circuit with a solenoid?
The Rds(on) is only guaranteed with a minimum drive voltage of 4.0V. 3.3V is less than 4.0V.
Possibly the MOSFET is heating up which typically decreases the Vgs for a given current. If you got the IRLZ44 from some dodgy source it's possible it does not meet specs. Although it's bad design to use an IRLZ44 with 3.3V drive, I would expect it to typically work under nominal conditions. That kind of time constant sounds like thermal or possibly leakage (as in an open or almost open connection to the gate).
There are many, many MOSFETs which are rated with 3V, 2.5V and even 1.8V drive, but few, if any, in a through-hole package. Here is one example, 0.005\$\Omega\$ maximum with 2.5V drive and 0.075\$\Omega\$ maximum with 1.8V drive.
If the MOSFET fails with a drain-gate short it could damage (ie. destroy) the MCU. Electrical noise could reset the MCU. You could use an optocoupler or add some transistors to drive the MOSFET which would provide protection. You might also be worried about the solenoid lock being destroyed if the MOSFET fails on- I think most of them are only rated for very intermittent duty.
Although it is stated that it is a "logic-level gate drive" where "Gate Threshold Voltage: 1<VGS<2" in the mosfet datasheet, mosfet is acting weirdly with a gate voltage of 3.3V.

It is specified for Vgs of 4V, but not 3V3.
Why does it take 10 seconds for the current to rise to 1.8 amps (Gate: 3.3v)? While working perfectly with a gate voltage of 5.0v.
Most MOSFETs have negative tempco on their threshold voltage, and positive tempco on RdsON.
My guess is that there isn't enough voltage on the gate to turn it on fully. You can confirm this by measuring Vds and Id, which will give you RdsON. If it is much higher than the specified datasheet RdsON, then it's not turned on enough. So the MOSFET works in linear mode, and as it heats up, its threshold voltage decreases, which means it turns on more, and current increases. If current increases over 10 seconds, you should feel the MOSFET get hotter.
You either need a MOSFET that will turn on with a Vgs below 3V3 (so, another MOSFET). If you have a 5V power supply on your board, you can use a 3V3 to 5V level converter/driver, for example a 74HCT logic gate, to drive this MOSFET with 5V.
I think I have three options:
(a) 3.7 V li-ion + boost converter to drive solenoids
(b) 12 V lead-acid + buck converter to drive MCU
(c) 3.7 V + 12 V dual-battery system
How to decide between these options?
I've named your options (a)..(c). I've also deduced that these are in order of preference: (a) would be best because the battery's smallest, then (b) then (c) least.
The below explanations don't account for falling battery voltages as they drain down. You'll have to factor that in yourself from the battery manufacturer's data. But the calculation results will each be distinct enough to select your option before that anyway.
For (a), the 3.7 V battery 'batt3V7' has to be large enough for 6 months of the MCU anyway. So you're looking at the additional battery capacity needed for the solenoid.
This extra capacity is: (Isol x 12/3.7 x (100/boosteff) x ton x 3600) Ah
Where: Isol is solenoid average current drawn, across pull-in current to hold-in current (best measured with scope, while loaded with your actual mechanics); 12/3.7 is the step-up voltage ratio; boosteff is the boost converter efficiency as a percentage; ton is the on-time in seconds; 3600 is number of seconds in an hour.
You can then decide if the new capacity of batt3V7 is suitable and practical.
For (b), it's a similar method in reverse, with the MCU loading 'batt12V' and the capacity being the sum of the solenoid and MCU capacity requirements.
The solenoid capacity needed is: (Isol x ton x 3600) Ah
The MCU capacity needed is: (Imcu x 3.3/12 x (100/buckeff) x 3600) Ah
Where: ton is the solenoid on-time in seconds; 3600 is number of seconds in an hour; Imcu is MCU average current drawn including any use sleep modes; 3.3/12 is the step-down voltage ratio; buckeff is the buck converter efficiency as a percentage.
For (c), the size of each battery can be determined by applying the methods shown above.
Definitely the second option: cheaper, smaller, requires a single battery charger. A DC-DC converter to power the MCU is smaller because the MCU takes less power than the solenoids. Also, the DC-DC converter that powers the MCU isolates from the MCU the voltage dips as a solenoid is turned on and the high voltage spikes as a solenoid is turned off. (In the first option, when you turn on and off a solenoid the MCU power supply is affected, which may reset it.)
There is a common misconception:
The solenoid is physically installed inside the machine, and I have no access to place a flyback diode directly on the solenoid terminals
The source of the flyback, is the element whose effective resistance changes suddenly: the transistor.
The flyback diode must be placed at the transistor.
This is an oft missed point, and I have even seen misinformation claiming the opposite is true. It is not. The fundamental is as above, simple as that, nothing more, nothing less.
There are circumstances where putting the diode at the solenoid works out anyway -- but this is not counterproof, this is simply a tolerable case along a continuum of cases more distant from the fundamental. Namely, the stray wiring inductance between switch and diode, still itself incurs flyback. The amount of flyback might be negligible (say the switch takes some ~ms to transition from closed to open, and the cable is only some meters long -- a few µH, charged to, say, less than an ampere), but this is a mitigative solution to a non-fundamental situation.
When a diode is sufficient (given other operating constraints), and you are free to place the diode anywhere in the system, place it by the switch, and place a bypass capacitor between GND and +V. All three (bypass, switch and diode) are best co-located to minimize stray inductance in the loop between them.
The proof of this fact is underlined by its universality. What if the switch is carrying 100A, not just 1A? What if the cable is 100m long? What if it switches in 10ns? Or 1ns? A switching power supply is not a separate case, based on unique fundamentals; it is a specific case of the same fundamental. Keep the "fast" loop small.
(Mind, the bulk of the above is not so much addressed to the OP; a simple statement of fact suffices for that. It's mainly directed at those who lack understanding on this topic. I'll repeat this as often and as loudly as necessary until the message is received. Sadly this platform doesn't have any sort of "pinned comment" function, so repetition it shall be.)
So, with that covered, it seems the bulk of this question is, where to wire the power supply.
If PCB ground plane cannot be joined with chassis ground, then it would seem the remaining issue is isolation.
Provide a power supply that can be joined to chassis ground, and electronic (logic signal) isolation to couple the signal source to the driver.
A simple phototransistor optoisolator will suffice at this frequency. If a separate power supply is not available, or an external unit cannot be provided (for cost or space reasons, say), a DC-DC isolator module can be placed on the PCB, or the equivalent circuitry built out using a typical flyback/forward controller/regulator and associated components. (Beware EMC issues due to common-mode currents, i.e. switching noise injected into the ground-return path.)
Supply reversal is then an independent issue, easily solved with a polarity protection diode, or if the voltage is low enough that a diode drop would be problematic, a PMOS wired in the usual way. (Pay mind to transient and sudden-reversal protection, if applicable.)
Isolation also solves ground lift, as there simply isn't a closed circuit path so that nothing works, as expected (at least, I would hope no one expects the thing to work when it's wired entirely wrong, whether by accident or otherwise..!).
Illustration of isolated scheme:

simulate this circuit – Schematic created using CircuitLab
Input filtering not shown, REG could be any linear or switching reg, 5V could be 3.3V or whatever else the logic/control supply is, XFMR1 is actually a proper DC-DC converter, SW1 represents the logic source, and maybe M1 has a better gate drive circuit. Maybe current limiting or thermal protection or whatever, too.
Note that this particular arrangement is unfavorable for CM noise purposes (solenoid switching voltage is applied to the isolation barrier), which might not be a problem at the slow rate (particularly with rise time control, i.e. drive the MOSFET slowly, but maybe some other considerations like an R+C snubber between G-D). Mainly, showing it this way to illustrate how, with isolation, you don't much care how it's driven, allowing a cheaper NMOS to be used. Otherwise, making it common-ground with a PMOS in the obvious manner is perfectly fine too.
You can shift the heat dissipation from the Zener diode to the MOSFET, but this is only helpful if the thermal margin of the FET allows it.
If you allow a larger negative voltage swing, a snubber circuit can also absorb some of the energy.
The simulator's component pool does not contain a 20 V Zener diode, so I connected two in series.
A typical solenoid coil with 4.8 Ω DC resistance has far more inductance than 40 µH, but it could be a special coreless coil.
With reversed supply polarity, the FET body diode conducts, the solenoid receives almost full voltage and the FET must dissipate around 2 W. I estimate this from 0.8 V diode forward voltage and 2.5 A coil current.

simulate this circuit – Schematic created using CircuitLab
