Switching on a solenoid

Indeed. I went to Uni after I supposedly retired from Linfox. I’ve met some brilliant young people and some exceptionally lazy young people. Like pretty much all aspects of life.

My parents kicked me out because I was too much of a ratbag!

What counts is what’s between the ears, in my opinion.

Anyway, it looks like there are 2 options now.

  1. The IRLB8721
  2. The DFR0457

Hi Gerard
Plan A: You could try the IRLB8721 but you will have to drive it directly from the MCU. The logic level converter will not charge the gate cap I don’t think, the one shot to get the extra bit of current is only on for 30nSec. The 3.3V is above gate threshold but not turned fully on. The solenoid would only be for intermittent use so you will probably get away with it and the Mosfet might not get too hot. Use a 330Ω gate resistor to limit MCU current to a safe value.

Plan B: Try driving the IRLB8721 with the logic level converter. Use a 150Ω base resistor to keep the initial current below 50mA. This may or may not work.

In both Plan A & B monitor Mosfet temperature as it may or may not get hot

Plan C: Use DFR0457 as a high side switch as in above circuit. This would be my personal preference as it will work without the perhaps situations in Plan A & B. You also have your MCU isolation via the Opto Coupler which you wanted.
Cheers Bob
Add on:
Or the TC4420 as an interface to the IRLB8721. But DigiKey wait time and Element 14 postage might be game changers for you.

Quick update form me.
My circuit i posted using the IRLB8721 was tested last night.
My diagram has a 1k resistor in series with the solenoid and the mosfet. The 1k resistor makes it too weak an action and, as rob suggests, you can remove it entirely.
My application wants slightly less power and in the end the value I settled on was 150ohms.

Rob circuits is more robust than mine because my circuits work on hope so probably better to start with his ideas :stuck_out_tongue: . :exclamation:
I’m writing because I said I would update on my results and just wanted to follow through on what I promised :slight_smile:

1 Like

Hi Pix
Thanks. As point of interest what is your 5V gate drive source?
Cheers Bob

On the day it was a 5v power supply which I turned on and off manually for sake of testing :stuck_out_tongue:

The way I want to do it is with a PNP transistor and a microcontroller.
I’m imagining the gate of the mosfet connected to the collector of the transistor and the transistor brought to saturation with the microcontroller IO via a 46k resistor (depending on the model of transistor I choose).

Haven’t tried that yet but it should be ok provided I get my voltages correct.

EDIT: Oh and for this to work I’d need to swap my pull-down resistor for a pull-up. The circuit would be “active low” from the micro-controllers perspective.

Hi Pix

That is correct.
This sort of thing was a common Gate drive before “logic level” Mosfets. The PNP transistor will turn ON when the base goes to Gnd and charges the Gate cap but it requires an NPN transistor to turn on and discharge the cap when the logic goes high.

The logic voltage has to go as high or preferably a little higher than the dc voltage on the PNP emitter or this transistor will not turn off and you will finish up with a short to ground via the 2 transistors.

So if you are using the dreaded 3.3V logic you are probably going to be behind the 8 ball as the saying goes.

You could level shift and get the logic back the right way by inserting a NPN transistor as an inverting amp with a supply voltage of 5V or even more. That way you get the logic the right way up and a decent voltage to work with. But the whole thing requires 3 transistors. 2 NPN and 1 PNP. By the way the PNP/NPN pair driving the Gate should be a complementary pair.
Cheers Bob
PS: I think we wandered a bit off topic here

1 Like

I am coming into this dialogue a little late but I am surprised by the huge amount of discussion on the simple subject of turning on a solenoid. I thought I would share with you what has worked well for me.

  • The board/solenoid operates at 3.3V which is the same logic level as the electronics thus simplifying the wiring and operation. No logic converters needed.
  • The solenoid pulls 100mA which is within the 3.3V/300mA provided by a Raspberry Pi Pico.
  • The input has an optocoupler for isolation which is important for reactive loads such as motors. As well as providing safety it allows the solenoid to be directly driven by Raspberry Pi pins (measured 2.4mA draw).
  • When the solenoid operates a red LED comes on which is useful for trouble shooting.
  • It has NO/NC contacts for flexibility.
  • Despite the nameplate rating for legal and safety reasons I would not go higher than a 24VDC load.

The part costs less than $3.00. It has been working reliably in the CE garage door opener for some time.

1 Like

Thanks for the detailed post.

I presume you mean ‘relay’ for ‘solenoid’?

Problem is that I’m using the Espressif ESP32 and any GPIO pin is limited to 40mA max and recommended 20mA. While your solution is great for a Pi, I don’t have 100mA to play with. If I did, we could resolve the issue pretty easily, as you say.

The other constraint is that I really need to get a solution that I can incorporate into the existing 100mm x 100mm PCB so I can get the factory to whiz them out 100 at a time!

The 100mA figure is the load on the relay power (the power needed to do the actual switching) not the GPIO load. The GPIO load is mentioned as 2.4mA.

Hi Fractal
Have not seen that one. Who manufactures and or markets it. I note that 3V relays are used instead of 5V and a claim to “work” at 3.3V.

If you read the little bit of info under “jumper caps” I think you have “load starts” and “load stops”
reversed.
Cheers Bob

In response …

Yes it is of course a relay, not a solenoid. Blame my mistake on old age.

A short from VCC to IN measured 2.4mA. This is ok for 3.3V micros and the spec states the relay is suitable for ARM /PIC /AVR /MCU/Raspberry/CNC machine/NodeMCU/ ESP8266 etc. The relay draws about 100mA when it operates but this is from VCC, not IN. The Raspberry Pi Pico provides a handy 3.3V/300mA for external use. I am not familiar with the ESP32.

The spec states the relay is suitable for 3V and 3.3V although the relay is marked 3V.

The board is unbranded but from the chinglish it obviously comes from China. As Bob pointed out the outputs are reversed in the diagram.

Noteworthy is that 3V relays are available. Also that the opto coupler is a single IC but without a circuit diagram I do not know the part.

Agree that it may not be your solution. Although fine for the hobbyist it may not be suitable for commercial use. Just mentioned it because it worked well for me and no transistors are harmed in the process.

Five of these cost an amazing (sic) $13.89.

1 Like

Hi Fractal
Found this device on Amazon.
On this Forum we are trying to offer reliable advice remotely. I had a look at this and with the information available (almost none) and the lack of a schematic to reasonably evaluate “fit for purpose” I personally would not recommend its use without having possession of one to try. And I am not going out to purchase one just to do that. It does have the advantage of a 3V relay though if a contributor wished to experiment.

But that is just me. I tend to be somewhat on the cautious side and as said above I would not use or recommend use if enough information is not readily available. I mean “readily” not something that takes hours of searching to find.
Cheers Bob
PS: We are wandering a bit here I think.

1 Like

Bob’s comments prompted me to examine the board a little closer.

The relay P/N SRD-03VDC-SL-C appears to be the 3VDC version of the common 5VDC and 12VDC relays which have been around for yonks. The manufacturer is Songle Relay from Zhejiang in China although board suppliers use their own branding. Mine is branded DSSRQI. It has all the usual relay certifications.

I have purchased 5VDC relay boards from reputable suppliers but have never been supplied a schematic, just the relay data sheet. I am not sure this is an issue, it is not a complex board and if you turn it over you can “see” the circuit diagram.

The photocoupler is an EF817.

I have found the relays invaluable for direct connection to 3.3V pins and great for hobbyist applications safely controlling lights, motors etc. So far they have worked reliably with no failures although they have not been used anywhere near their limits. Anyone considering it should be mindful that Bob would not use it or recommend its use though.

Hi Fractal

and everything you say is very true.
BUT.
You have a unit to examine. What I am getting at is you should not have to purchase a device (of any description ) and wait for postage to establish if it will do your job.

My solution is simple. If I can’t readily get enough information to evaluate fit for purpose I will not purchase (or only purchase in desperation) or recommend purchase in this Forum. I don’t mind going as far as the product Wiki if available but i draw the line going through endless searches trying to find a information about a device or a suitable product. I sometimes use some suppliers catalogues with their comprehensive filters and data sheets with some success.

I might make suggestions and provide suggested schematics on the Forum but at the end of the day what happens and what is used for is out of my control.
Cheers Bob

1 Like

I received the…

  1. The IRLB8721
  2. The DFR0457

…today.

I’ll test them out tomorrow and advise back. If you see a glow on the horizon, it may be my workshop ablaze!

The DFR device looks really nice.

Gerard

Hi Gerard
OK, Plan A and plan C. Plan A is a low side switch (earlier circuits) and will probably work although I would like to see something like 5V (native, not via a level converter) gate voltage.

Plan C would be my go to as it is a positive switch (high side as per circuit above) and there should be no “perhaps” situations which I hate.

Let us know how it all goes.
Have been side tracked a bit the last couple of days, sorry about that.
Cheers Bob

Plan A:-

The new MOSFET is a direct drop-in for the TIP.

I tested it with just +5v and it works the solenoid no problem but I did realise the importance of the drain resistor on the gate. When I removed the yellow wire from +5v, the FET kept on keeping on until I touched the ground pin on the 7805. Actually, after a few seconds, the FET started partly switching on so I had to short to ground a second time. Residual capacitance I suppose.

Then I hooked up the level shifter as per the pic. The 3v3 side input (pin A1 on the PCB) floats high so the corresponding pin B1 goes high to +5v. In this state, the MOSFET switches on quite reliably, which is good. The gate series resistor is 510R. Unsure if it’s needed or not, I just wanted a current limiter (probably unnecessary).

I better put in a 10k drain R on the gate though.

Edit: The 3 diodes at the bottom make the 3v3 supply. Crude, but it works.

1 Like

Hi Gerard
I have mentioned this a few times now. There is a capacitor (internal) from Gate to source. When you turn it on as you did it will stay on for probably weeks as the input resistance for the Mosfet probably runs into GΩ or even TΩ and takes a very long time to discharge this cap. When driven by I/O this cap should be discharged when the I/O goes low. If it is not driven in this manner about 10k is required from Gate to Source (in this case Ground).

The level shifter also has to be driven high AND low or as you have found out it will float and in doing so the output will go high. When being driven by I/O this is not a problem as the I/O will take the input low. So once again you are chasing phantoms by not using a device in the design manner.

The Gate resistor is required to keep the “inrush” cap charging current to a safe level for the converter (<50mA). This cap is a short circuit at switch on so is required.

No you don’t if using the converter . It has a source resistance of 4k plus the 0.5k Gate resistor and a resistor to ground will form a voltage divider and reduce the gate voltage to what could be a “perhaps it will be reliable” level (3.45V). The gate will have to be discharged by the converter going low which it is designed to do. The same gate resistor will limit the discharge current to a safe value.

Don’t think of cheating by putting the pull down on the 3.3V side either. The same voltage division will occur and you will finish up with 2.36V instead of 3.3V. Once again could be in the “perhaps” reliability area.

At this stage I think the electronics (basic) course is just about finished. By now you should have a pretty good understanding of how everything works. At the end of the day it is entirely up to you. As I said I personally would use the DFR switch where everything is done for you. Connect the MCU I/O, solenoid supply to the VIN and solenoid to VOUT. All done. The Mosfet would be easier to include on your board I suppose but as in most things there is a trade off.
Cheers Bob

Of course I didn’t leave the input floating.

In the end, I opted for the DFR module:-

  1. I can use it without modifying the prototypes.
  2. As luck would have it, there is an unused set of header pins to just happen to have gnd, 3v3 and the spare (only one) GPIO pin side by side matching the DFR PH 3 pin connector exactly on the prototype.
  3. The cost of the DFR is only A$6.80 and that roughly matches the cost saving removing the MOSFET and associated components (plus saved factory assembly time).
  4. I have the benefit, as you pointed out, of the whole mess being optically isolated where needed.

I’ve handed it off to the software bloke to do some testing but I did some basic on/off testing first.