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

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 8:04 am

The diodes can be anything capable of handling the voltage and current of the solenoid (which was 24V 0.5A max), so IN4001 would be Ok, or you could just use a full bridge rectifier package, pretty much any one of those will handle the current.

The resistor should be around 10K Ohms, just to keep the MOSFET turned off when the Pi isn't driving it. I would also add a 1K resistor between the FET's Gate and the GPIO for additional protection, but you don't really need that.

I'm not sure of a suitable FET, but there should be plenty available that will handle at least 50V (so as not to overload it) at at least 1A and (important bit) can be turned fully on with the 3.3V from the Pi.

Essentially, when the FET is off, no current will flow in the circuit, as the diodes will block in both directions. But when the FET turns on, it allows current to flow from one side of the bridge to the other and the diodes will then let the AC through the solenoid.

It's an interesting use of a bridge rectifier that I had not previously encountered. I'm somewhat surprised by that.

ThePiPeArtist
Posts: 18
Joined: Sun Jan 05, 2020 12:32 pm
Location: Australia

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 10:03 am

emma1997 wrote:
Sun Jan 12, 2020 7:51 pm
ThePiPeArtist wrote:
Sun Jan 12, 2020 1:21 pm
Would I need a MOSFET?
Strangely not that unusual to see a beginner bring up a better solution than the experts. :)

You don't 'need' a MOSFET as those classic BJT relay circuits do work (sort of). It's just old fashioned transistor is not the best solution for a variety of reasons (cost, component count, heat, EMF, EMI ). I just finished some tests this morning for another relay thread comparing NPN with FET and the latter demonstrated superiority in each area. Some significantly.

For DC applications I suspect a MOSFET may actually be the only component required unless extraordinary high voltages or other isolation issues are involved. For directly driving AC a triac (similar to back-to-back FETs) is best. I did manage to drive a 150a motor starter solenoid with just this:

Code: Select all

        d---solenoid---12v
GPIO---g
        s--gnd
Of course, as mentioned, the old method does work. For hobby sometimes busywork is desirable and cost/performance not always a factor for one-up. More than one way to skin a cat.
https://www.instructables.com/id/Raspbe ... on-System/ - Could I follow this design? to control the solenoid valve?

Otherwise what is your method to control the solenoid valve? Don't really understand what this means:

Code: Select all

        d---solenoid---12v
GPIO---g
        s--gnd
Thanks.

drgeoff
Posts: 10083
Joined: Wed Jan 25, 2012 6:39 pm

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 10:58 am

LTolledo wrote:
Mon Jan 13, 2020 2:27 am
the thought of the FET malfunctioning and inadvertently connecting the AC line to the RPi's GPIO line is quite horrifying.....
... and might produce some "spectacular results" ( most of us know what that means ) :mrgreen:
Same spectacular results as with any other circuit employing a malfunctioning FET/BJT with more than 3.3 volts on drain/collector and gate/base electrically coupled to a GPIO.

The FET and RPi are not exposed to any AC unless the bridge malfunctions. Not really any different than having a DC solenoid and the bridge providing DC to it in the usual way.

ThePiPeArtist
Posts: 18
Joined: Sun Jan 05, 2020 12:32 pm
Location: Australia

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 11:05 am

rpdom wrote:
Mon Jan 13, 2020 8:04 am
The diodes can be anything capable of handling the voltage and current of the solenoid (which was 24V 0.5A max), so IN4001 would be Ok, or you could just use a full bridge rectifier package, pretty much any one of those will handle the current.

The resistor should be around 10K Ohms, just to keep the MOSFET turned off when the Pi isn't driving it. I would also add a 1K resistor between the FET's Gate and the GPIO for additional protection, but you don't really need that.

I'm not sure of a suitable FET, but there should be plenty available that will handle at least 50V (so as not to overload it) at at least 1A and (important bit) can be turned fully on with the 3.3V from the Pi.

Essentially, when the FET is off, no current will flow in the circuit, as the diodes will block in both directions. But when the FET turns on, it allows current to flow from one side of the bridge to the other and the diodes will then let the AC through the solenoid.

It's an interesting use of a bridge rectifier that I had not previously encountered. I'm somewhat surprised by that.
Thanks for the help.
Could you include a diagram?

Also I'm sorry but I hate your profile picture.
Thanks.

pcmanbob
Posts: 7668
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 11:19 am

rpdom wrote:
Mon Jan 13, 2020 8:04 am

It's an interesting use of a bridge rectifier that I had not previously encountered. I'm somewhat surprised by that.
Well it not a circuit I have ever seen used in any industrial controls I have ever worked on and I don't know I would want to use it with a pi , I would want to have some isolation between the gpio and the 24V AC.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 11:56 am

You could replace the FET with an optoisolator.

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

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 12:30 pm

ThePiPeArtist wrote:
Mon Jan 13, 2020 11:05 am
Could you include a diagram?
Not at the moment, sorry.
Also I'm sorry but I hate your profile picture.
Well, I could change it for one the bigger spiders :lol: but that one has sentimental value for my wife (those are her hands in the picture).

JohnsUPS
Posts: 135
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 2:01 pm

I've used that bridge rectifier trick before and it is an elegant way of switching an AC load. The application at the time was a motor speed controller.

drgeoff
Posts: 10083
Joined: Wed Jan 25, 2012 6:39 pm

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 2:17 pm

pcmanbob wrote:
Mon Jan 13, 2020 11:19 am
rpdom wrote:
Mon Jan 13, 2020 8:04 am

It's an interesting use of a bridge rectifier that I had not previously encountered. I'm somewhat surprised by that.
Well it not a circuit I have ever seen used in any industrial controls I have ever worked on and I don't know I would want to use it with a pi , I would want to have some isolation between the gpio and the 24V AC.
Is it the 24 volts or the AC that is worrying you? If it was a 24 volt DC solenoid powered from a DC supply would you still want isolation between GPIO and FET?

pcmanbob
Posts: 7668
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 2:59 pm

drgeoff wrote:
Mon Jan 13, 2020 2:17 pm
Is it the 24 volts or the AC that is worrying you? If it was a 24 volt DC solenoid powered from a DC supply would you still want isolation between GPIO and FET?
I would probably still go with some isolation even if it was DC,

But my particular consideration was the AC in this instance , having help several people on here that were switching AC using a normal relay and the noise induced from the AC was causing problems with the pi rebooting or crashing, adding a opto isolator solved the problem,

and of course in this example we would be connecting one side of the bridge rectifier output to the pi ground,

But at the end of the day its up to the person using the circuit to make there own choice to isolate or not...
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

drgeoff
Posts: 10083
Joined: Wed Jan 25, 2012 6:39 pm

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 3:31 pm

pcmanbob wrote:
Mon Jan 13, 2020 2:59 pm
and of course in this example we would be connecting one side of the bridge rectifier output to the pi ground
And how is that different from powering the RPi from this type of PSU?
Attachments
CCI_000011.png
CCI_000011.png (10.2 KiB) Viewed 324 times

LTolledo
Posts: 2390
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 9:20 pm

drgeoff wrote: And how is that different from powering the RPi from this type of PSU?
Way back then I tried using that type of PSU to power my first RPi3B
5A rated rectifier and 3A rated linear regulator with big heatsink
the setup was really bulky with big capacitors
and a heavy step down transformer.
estimate weight of the setup: 7kgs

while it did power the RPi3B properly
it did not fix the problem it was "supposed to fix" (noisy audio from audio jack)

however....the PSU did became a good room heater :mrgreen:
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

askDrAlex
Posts: 9
Joined: Sat Dec 21, 2019 12:23 am

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 9:35 pm

LTolledo wrote:
Mon Jan 13, 2020 2:27 am
the thought of the FET malfunctioning and inadvertently connecting the AC line to the RPi's GPIO line is quite horrifying.....
Since the current flowing into the gate electrode of a FET is very small (even zero in an ideal world, where just the gate potential controls the source-drain current flow), you can easily put a 100 kOhm resistor in between. In case of a major "FET accident", it will protect the GPIO line.

drgeoff
Posts: 10083
Joined: Wed Jan 25, 2012 6:39 pm

Re: Controlling Solenoid valve with Raspberry Pi 3

Mon Jan 13, 2020 10:30 pm

LTolledo wrote:
Mon Jan 13, 2020 9:20 pm
however....the PSU did became a good room heater :mrgreen:
The regulator can equally be a switching type (buck) which will generate much less heat.

However my reason for posting that diagram was an attempt to elicit from pcmanbob the reason for his objection to connecting RPI ground to the output of a bridge rectifier.

ThePiPeArtist
Posts: 18
Joined: Sun Jan 05, 2020 12:32 pm
Location: Australia

Re: Controlling Solenoid valve with Raspberry Pi 3

Tue Jan 14, 2020 4:39 am

As a beginner reading this thread makes my head hurt. I will try to research and keep up on what you guys mean.

Honestly, I am very confused:

But here's my parts list (These are the things that I haven't bought which is essentially everything except for my solenoid valve):
  • High-Speed Optoisolator - 6N137 Or a N-Channel MOSFET 60V 30A
  • Diode Rectifier 1N4001 - 1A 50V
  • Mains Adaptor 24VAC 1A
  • Some kind of bridge Rectifier

Anything else? I really need help. :(
Thanks.

LTolledo
Posts: 2390
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Controlling Solenoid valve with Raspberry Pi 3

Tue Jan 14, 2020 11:32 am

drgeoff wrote:
Mon Jan 13, 2020 10:30 pm
LTolledo wrote:
Mon Jan 13, 2020 9:20 pm
however....the PSU did became a good room heater :mrgreen:
The regulator can equally be a switching type (buck) which will generate much less heat.
Hehehe.... I was trying to do a "true-blue old-school" DIY PSU back then.... and yeah it was also an expensive setup
buck converters was not yet within my interest at that time...
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

LTolledo
Posts: 2390
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Controlling Solenoid valve with Raspberry Pi 3

Tue Jan 14, 2020 11:48 am

ThePiPeArtist wrote:
Tue Jan 14, 2020 4:39 am
As a beginner reading this thread makes my head hurt. I will try to research and keep up on what you guys mean.

Honestly, I am very confused:

But here's my parts list (These are the things that I haven't bought which is essentially everything except for my solenoid valve):
  • High-Speed Optoisolator - 6N137 Or a N-Channel MOSFET 60V 30A
  • Diode Rectifier 1N4001 - 1A 50V
  • Mains Adaptor 24VAC 1A
  • Some kind of bridge Rectifier

Anything else? I really need help. :(
if it were me (yes, that means me!)... I'd just use this
RPiRelayBoard.jpg
RPiRelayBoard.jpg (74.58 KiB) Viewed 205 times
and save a lot of trouble....

others want to be adventurous.... I cant blame them for doing so.... :mrgreen:
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

pcmanbob
Posts: 7668
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Controlling Solenoid valve with Raspberry Pi 3

Tue Jan 14, 2020 12:59 pm

drgeoff wrote:
Mon Jan 13, 2020 10:30 pm
However my reason for posting that diagram was an attempt to elicit from pcmanbob the reason for his objection to connecting RPI ground to the output of a bridge rectifier.
My concern was the introduction of electrical noise on to the pi ground, I may well be wrong , I often am after all I am only human,

As I said before its the individuals choice on how they control things and what they connect to their pi.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ThePiPeArtist
Posts: 18
Joined: Sun Jan 05, 2020 12:32 pm
Location: Australia

Re: Controlling Solenoid valve with Raspberry Pi 3

Wed Jan 15, 2020 3:51 am

LTolledo wrote:
Tue Jan 14, 2020 11:48 am
ThePiPeArtist wrote:
Tue Jan 14, 2020 4:39 am
As a beginner reading this thread makes my head hurt. I will try to research and keep up on what you guys mean.

Honestly, I am very confused:

But here's my parts list (These are the things that I haven't bought which is essentially everything except for my solenoid valve):
  • High-Speed Optoisolator - 6N137 Or a N-Channel MOSFET 60V 30A
  • Diode Rectifier 1N4001 - 1A 50V
  • Mains Adaptor 24VAC 1A
  • Some kind of bridge Rectifier

Anything else? I really need help. :(
if it were me (yes, that means me!)... I'd just use this
RPiRelayBoard.jpg

and save a lot of trouble....

others want to be adventurous.... I cant blame them for doing so.... :mrgreen:
I found this tutorial on controlling the solenoid valve:
https://madlab5.blogspot.com/2017/07/wa ... ry-pi.html

Could I follow this to create my setup?
Attachments
Sprink_diag_fixed_cropped.jpg
Sprink_diag_fixed_cropped.jpg (35.3 KiB) Viewed 156 times
Thanks.

pcmanbob
Posts: 7668
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Controlling Solenoid valve with Raspberry Pi 3

Wed Jan 15, 2020 10:03 am

You could follow the relay board side of the the diagram ( if you were building your own relay board ) , but you can't use the solenoid side as that's for a DC solenoid and yours is AC.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: Controlling Solenoid valve with Raspberry Pi 3

Wed Jan 15, 2020 10:19 am

If you replaced the 12V DC supply with an AC supply, the only thing that wouldn't like AC would be the LED, and that could be cured by putting a diode across it in reverse.

Your relay board is pretty much the same as a shop-bought one

ThePiPeArtist
Posts: 18
Joined: Sun Jan 05, 2020 12:32 pm
Location: Australia

Re: Controlling Solenoid valve with Raspberry Pi 3

Wed Jan 15, 2020 10:43 am

Burngate wrote:
Wed Jan 15, 2020 10:19 am
If you replaced the 12V DC supply with an AC supply, the only thing that wouldn't like AC would be the LED, and that could be cured by putting a diode across it in reverse.

Your relay board is pretty much the same as a shop-bought one
Not building my own relay board, buying one.

Would I need the fuse and the resistor? I've seen tutorials without them.
Thanks.

LTolledo
Posts: 2390
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Controlling Solenoid valve with Raspberry Pi 3

Wed Jan 15, 2020 11:18 am

ThePiPeArtist wrote:
Wed Jan 15, 2020 10:43 am
Not building my own relay board, buying one.

Would I need the fuse and the resistor? I've seen tutorials without them.
buying one is a good choice... however...do note that those single relay boards are designed for use in 5v systems, the RPi GPIO voltage output is about 3.3v.
there have been numerous questions on how to adapt those.... and surely its pcmanbob to the rescue as always.

now, if you were to get a relay board specifically for the RPi system
and since you only need one relay (is that correct?) then this is another recommendation
automation_pHAT.jpg
automation_pHAT.jpg (193.33 KiB) Viewed 97 times
having a fuse on the solenoid side is not required but is recommended.

for light indication, the resistor and LED on the AC side is not recommended
better use 24vAC neon lights instead
or inquire at some industrial automation supply sites.
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

ThePiPeArtist
Posts: 18
Joined: Sun Jan 05, 2020 12:32 pm
Location: Australia

Re: Controlling Solenoid valve with Raspberry Pi 3

Wed Jan 15, 2020 12:59 pm

LTolledo wrote:
Wed Jan 15, 2020 11:18 am
ThePiPeArtist wrote:
Wed Jan 15, 2020 10:43 am
Not building my own relay board, buying one.

Would I need the fuse and the resistor? I've seen tutorials without them.
buying one is a good choice... however...do note that those single relay boards are designed for use in 5v systems, the RPi GPIO voltage output is about 3.3v.
there have been numerous questions on how to adapt those.... and surely its pcmanbob to the rescue as always.

now, if you were to get a relay board specifically for the RPi system
and since you only need one relay (is that correct?) then this is another recommendation
automation_pHAT.jpg

having a fuse on the solenoid side is not required but is recommended.

for light indication, the resistor and LED on the AC side is not recommended
better use 24vAC neon lights instead
or inquire at some industrial automation supply sites.
So the Raspberry Pi Phat is essentially a relay board but it works with Raspberry Pi?
I could just go with a 4 channel relay board.
Also I'm getting "raspberry pi compatible" relay board.
https://www.jaycar.com.au/arduino-compa ... d/p/XC4419

Also I'm guessing I need them resistor in the diagram.
Thanks.

LTolledo
Posts: 2390
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Controlling Solenoid valve with Raspberry Pi 3

Wed Jan 15, 2020 1:25 pm

ThePiPeArtist wrote:
Wed Jan 15, 2020 12:59 pm

So the Raspberry Pi Phat is essentially a relay board but it works with Raspberry Pi?
yes as those are specifically designed and tested for use with the RPi boards
ThePiPeArtist wrote: Also I'm getting "raspberry pi compatible" relay board.
https://www.jaycar.com.au/arduino-compa ... d/p/XC4419
sorry to bust your party but the relay board in the link is labled
Arduino Compatible 5V Relay Board
CAT.NO: XC4419

so it needs 5v to turn ON, the RPi GPIO cannot/will never output 5v

but you're free to try it yourself.....if you like to insist....
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

Return to “Automation, sensing and robotics”