tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Controlling solenoid valves with Pi not working

Thu Jan 12, 2017 2:27 am

Hi, I am attempting to control 17 12v solenoid valves to control the flow of water using my Raspberry Pi's GPIO pins. I have tried connected them up with transistors and connected them the the GPIOs and the indicator LEDs lit correctly but the solenoids did not open. Here is a diagram I made of what my circuitry looks like to one of the solenoids:
Image

User avatar
Burngate
Posts: 6066
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling solenoid valves with Pi not working

Thu Jan 12, 2017 11:22 am

TIP120 is a Darlington; it's effectively two transistors, so two B-E junctions in series.
That means it needs 1½ - 2v on its base to switch on.

With the GPIO at 3v3 and the base at 2v, the current through your 180Ω resistor is going to be about 7mA
The valve wants 600mA to operate, so you're expecting the current gain of the transistor to be close to 1000

The Hfe (gain) of the TIP120 is supposed to be about 1000, but that's probably optimistic, since you're wanting it to be close to saturation.

I would reduce the 180Ω resistor to less than 100Ω and see what happens.

NicoVanDerDussen
Posts: 74
Joined: Sat Aug 24, 2013 2:41 pm

Re: Controlling solenoid valves with Pi not working

Thu Jan 12, 2017 11:34 am

Beware of the reverse voltage a solenoid can produce!

http://www.iluselectronics.com/q-why-is ... tric-lock/

Without proper protection you can (and most probably will) fry your Raspi.

I prefer using a relay module with opto-isolation to switch these kind of things.

It might be fortunate that the solenoid did not work as it should have :)
Setting up your Raspberry Pi to work with a 3G dongle http://nvdd.info/11gKrsZ

ElEscalador
Posts: 681
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Controlling solenoid valves with Pi not working

Thu Jan 12, 2017 1:14 pm

NicoVanDerDussen wrote:Beware of the reverse voltage a solenoid can produce!

http://www.iluselectronics.com/q-why-is ... tric-lock/

Without proper protection you can (and most probably will) fry your Raspi.

I prefer using a relay module with opto-isolation to switch these kind of things.

It might be fortunate that the solenoid did not work as it should have :)
This. Even if you throw in that flyback diode and "get away with it" by far best practice is to use opto-isolators. Lucky for you, it's no longer a pain in the but and a relay board with an optoisolator built in is available for a few bucks. Less than $1 if you check ebay and can wait for shipping. I use both sainsmart and sainsmart knockoffs...all have worked with all of my pis so far.
My Autonomous Robot Project and a few of my other projects below.

https://lloydbrombach.wordpress.com/

tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Re: Controlling solenoid valves with Pi not working

Thu Jan 12, 2017 10:40 pm

NicoVanDerDussen wrote:Beware of the reverse voltage a solenoid can produce!

http://www.iluselectronics.com/q-why-is ... tric-lock/

Without proper protection you can (and most probably will) fry your Raspi.

I prefer using a relay module with opto-isolation to switch these kind of things.

It might be fortunate that the solenoid did not work as it should have :)
How do I protect my Raspi? I have avoided using relays because they turn on and off relatively slow but I guess I might have to use them.
ElEscalador wrote: This. Even if you throw in that flyback diode and "get away with it" by far best practice is to use opto-isolators. Lucky for you, it's no longer a pain in the but and a relay board with an optoisolator built in is available for a few bucks. Less than $1 if you check ebay and can wait for shipping. I use both sainsmart and sainsmart knockoffs...all have worked with all of my pis so far.
If relays are the only option, I am happy to wait for ebay shipping. Can you point me to some relays I could use for my 17 solenoid valves?

NicoVanDerDussen
Posts: 74
Joined: Sat Aug 24, 2013 2:41 pm

Re: Controlling solenoid valves with Pi not working

Fri Jan 13, 2017 4:57 am

If you need relays, maybe

https://www.aliexpress.com/item/2015-Ch ... 81ba942641

The relay coils require 5V - Raspberry Pi gives 3.3V - you might need your transistor switch to up the trigger voltage - but can then use something like the 2N2222 - very little current required to trigger.

Don't feed the relay coils from the Raspberry Pi - use an external power supply
Setting up your Raspberry Pi to work with a 3G dongle http://nvdd.info/11gKrsZ

tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Re: Controlling solenoid valves with Pi not working

Fri Jan 13, 2017 6:28 am

NicoVanDerDussen wrote:If you need relays, maybe

https://www.aliexpress.com/item/2015-Ch ... 81ba942641

The relay coils require 5V - Raspberry Pi gives 3.3V - you might need your transistor switch to up the trigger voltage - but can then use something like the 2N2222 - very little current required to trigger.

Don't feed the relay coils from the Raspberry Pi - use an external power supply
That is only 16 channel and I need 17. Will 17 of these do the job? https://www.aliexpress.com/store/produc ... 99916.html

ElEscalador
Posts: 681
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Controlling solenoid valves with Pi not working

Fri Jan 13, 2017 1:14 pm

tap wrote:
NicoVanDerDussen wrote:If you need relays, maybe

https://www.aliexpress.com/item/2015-Ch ... 81ba942641

The relay coils require 5V - Raspberry Pi gives 3.3V - you might need your transistor switch to up the trigger voltage - but can then use something like the 2N2222 - very little current required to trigger.

Don't feed the relay coils from the Raspberry Pi - use an external power supply
That is only 16 channel and I need 17. Will 17 of these do the job? https://www.aliexpress.com/store/produc ... 99916.html
Sure would. And while I've often powered a few of the coils from the pis gpio 5v pin, I would certainly power this many with a separate power supply. And note that there are two terminal for vcc on those boards -one is vcc and one id jd-vcc. I can never remember which is which but just put 5v to one of them and if LEDs come on - that is the one that gets powered from the pi (the pins require a "low" signal trigger the relays - a high signal keeps them off). I've never had a problem putting 5v from the pi to this pin, sharing ground and running straight from the gpio pins - all this does is light half of the optoisolator. The OTHER vcc/jd-vcc pin is what powers the relay coils.
My Autonomous Robot Project and a few of my other projects below.

https://lloydbrombach.wordpress.com/

User avatar
Burngate
Posts: 6066
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling solenoid valves with Pi not working

Fri Jan 13, 2017 6:20 pm

NicoVanDerDussen wrote:Beware of the reverse voltage a solenoid can produce!
http://www.iluselectronics.com/q-why-is ... tric-lock/
ElEscalador wrote:... Even if you throw in that flyback diode and "get away with it" by far best practice is to use opto-isolators...
Hang on a tick!

There's a diode in tap's diagram, and if that's not enough protection there's a meaty transistor in the way, and then there's a 100Ω resistor, as well.
Just how is the back EMF supposed to get into the Pi's GPIO?

Yes, I've read that aliexpress page.
All he does is explain why the diode is necessary - and tap knows this, because he's already put a diode in!

You're telling tap to use a relay, with a separate supply ... which is just a coil with a diode across it, just like his circuit ... how is that better?

tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Re: Controlling solenoid valves with Pi not working

Sat Jan 14, 2017 3:23 am

Burngate wrote:
NicoVanDerDussen wrote:Beware of the reverse voltage a solenoid can produce!
http://www.iluselectronics.com/q-why-is ... tric-lock/
ElEscalador wrote:... Even if you throw in that flyback diode and "get away with it" by far best practice is to use opto-isolators...
Hang on a tick!

There's a diode in tap's diagram, and if that's not enough protection there's a meaty transistor in the way, and then there's a 100Ω resistor, as well.
Just how is the back EMF supposed to get into the Pi's GPIO?

Yes, I've read that aliexpress page.
All he does is explain why the diode is necessary - and tap knows this, because he's already put a diode in!

You're telling tap to use a relay, with a separate supply ... which is just a coil with a diode across it, just like his circuit ... how is that better?
So he's saying I don't have the necessary protection and I should buy relays and transistors and your saying I do have the necessary protection and I do not have to change anything... :?

User avatar
rpdom
Posts: 15441
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Controlling solenoid valves with Pi not working

Sat Jan 14, 2017 5:34 am

Burngate wrote:TIP120 is a Darlington; it's effectively two transistors, so two B-E junctions in series.
That means it needs 1½ - 2v on its base to switch on.

With the GPIO at 3v3 and the base at 2v, the current through your 180Ω resistor is going to be about 7mA
The valve wants 600mA to operate, so you're expecting the current gain of the transistor to be close to 1000
A current gain of 1000 from 7mA would be 7000mA (7A) surely?
tap wrote:So he's saying I don't have the necessary protection and I should buy relays and transistors and your saying I do have the necessary protection and I do not have to change anything...
I'd agree with Burngate on this.

tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Re: Controlling solenoid valves with Pi not working

Sat Jan 14, 2017 6:22 am

rpdom wrote:
Burngate wrote:TIP120 is a Darlington; it's effectively two transistors, so two B-E junctions in series.
That means it needs 1½ - 2v on its base to switch on.

With the GPIO at 3v3 and the base at 2v, the current through your 180Ω resistor is going to be about 7mA
The valve wants 600mA to operate, so you're expecting the current gain of the transistor to be close to 1000
A current gain of 1000 from 7mA would be 7000mA (7A) surely?
tap wrote:So he's saying I don't have the necessary protection and I should buy relays and transistors and your saying I do have the necessary protection and I do not have to change anything...
I'd agree with Burngate on this.
Should I trust NicoVanDerDussen and ElEscalador or Burngate and rpdom? :? I think I have the enough protection but I don't want to fry my Raspi...

User avatar
rpdom
Posts: 15441
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Controlling solenoid valves with Pi not working

Sat Jan 14, 2017 6:44 am

tap wrote:Should I trust NicoVanDerDussen and ElEscalador or Burngate and rpdom? :? I think I have the enough protection but I don't want to fry my Raspi...
I certainly think you do. You have the diode in place, which is the normal way of handling the back EMF from an inductive component. Not sure why people are arguing that point.

If you want total isolation, then you can just add an opto-isolator into your existing circuit (plus the odd resistor). A relay is totally superfluous.

tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Re: Controlling solenoid valves with Pi not working

Sat Jan 14, 2017 7:00 am

rpdom wrote:
tap wrote:Should I trust NicoVanDerDussen and ElEscalador or Burngate and rpdom? :? I think I have the enough protection but I don't want to fry my Raspi...
I certainly think you do. You have the diode in place, which is the normal way of handling the back EMF from an inductive component. Not sure why people are arguing that point.

If you want total isolation, then you can just add an opto-isolator into your existing circuit (plus the odd resistor). A relay is totally superfluous.
Ok, thanks for saving me from wasting my transistors and $20 for relays :) Anyway, I burnt through my Raspi's power cord (while it was off) with my solder :| so I'm waiting for my new one to be delivered. After I get it, I can test the circuits again.

User avatar
Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: Controlling solenoid valves with Pi not working

Sat Jan 14, 2017 10:25 am

Hi tap,

Use a voltmeter to measure the voltage across ce of your tip120. It must be around 2 V.
It is better to use a n channel mosfet.
See this 'article': http://sensitiveresearch.com/elec/DoNot ... x.html#hfe

Success with your project!
Success with your project!
Ferdinand

bcavan
Posts: 1
Joined: Wed Jan 18, 2017 4:12 pm

Re: Controlling solenoid valves with Pi not working

Wed Jan 18, 2017 6:40 pm

Hi All, it was my understanding that Mosfet's are such a good fit for the rpi since the GPIO output voltage is low.
Is this correct?

Thanks,

Brian

tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Re: Controlling solenoid valves with Pi not working

Thu Jan 19, 2017 12:40 am

bcavan wrote:Hi All, it was my understanding that Mosfet's are such a good fit for the rpi since the GPIO output voltage is low.
Is this correct?

Thanks,

Brian
Hi, I don't think that is the case for all Mosfet's. I suggest making a new thread for your question to get a better answer and also so others can find it just in case they have the same question.

Texas-Mark
Posts: 100
Joined: Wed Dec 28, 2016 3:30 pm

Re: Controlling solenoid valves with Pi not working

Thu Jan 19, 2017 1:16 am

Personally, I would use some of those opto isolator boards mentioned early on. It would be like $10 and no need to mess with transistors and resistors. It would be fool proof protection of the Pi and over all easier to wire up.

tap
Posts: 8
Joined: Thu Jan 12, 2017 2:03 am

Re: Controlling solenoid valves with Pi not working

Tue Jan 31, 2017 11:44 pm

Thanks everyone for your help, the circuit is working fine now and it all works. I just wanted to ask why, when I remove the negative connection to the power source, the circuit still works perfectly? I don't understand how the circuit flows in that circumstance.
Texas-Mark wrote:Personally, I would use some of those opto isolator boards mentioned early on. It would be like $10 and no need to mess with transistors and resistors. It would be fool proof protection of the Pi and over all easier to wire up.
I agree that using relays is easier, but for me, using transistors and resistors is a great learning experience because I have never used them before and this project has taught me how they work and how to use them.

Return to “Automation, sensing and robotics”