I got a raspberry pi a week ago and just found your channel. You have the easiest to understand explanations of both the hardware and software side of things. Great video, and I'm looking forward to seeing more of your content.
hi i have issue, connected using 3.3v but relay doesnt work, red led indicator shown, however if connected to 5v the relay works but it will keep turned on. please advised on the steps or approach. Using SONGLE relay module 5v
Can i make this project with supplying power just to the raspberry pi instead of both the raspberry pi and solenoid? Like instead of needing 2 power sources.
We've got a separate video about a fingerprint scanner for Raspberry Pi, you could easily combine those two guides together if you were interested. Check it out here: ruclips.net/video/-IUae_-LqR4/видео.html
Absolutely. And if you needed to control even more that that I would recommend using this HAT core-electronics.com.au/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi-mini-kit.html
@@Core-Electronics Thanks so much for this video and your replies to comments. I would need to control 16 solenoid (DC 12V). COuld I use 16 relays connected to 16 solenoids? Would there be issue of the relays share the same 3.3V power from the PI? Regarding your suggestion about using the above HAT, I am not sure it work for solenoids that need 12 V (looks like it is for driving servo motor of 5 V). I am not very experienced so any comment suggestion super welcome. thanks a lot
Hello, I have a question about the raspberry nano and pico, they dont operate on 5v but 3,3v can they operate these relais, or do u need a stepup something in the middle?
The exact Relay you see in the video will work just fine with the Raspberry Pi Pico. In the Specification on the Product Page you will see this - While marked as a 5V supply voltage & input signals, we have found this to work fine at 3.3V - core-electronics.com.au/catalog/product/view/sku/CE05137
Rhanks, I am.still in doubt if I should go for arduno and a pi as server or everything pi. I lean more to everything pi. I want to connect everything by utp. And I dont like to solder, so I meed shields/hats for all sensors and.a couple.of.motors. real headach to figire it out.
Excuse my ignorance, by replacing the solenoid with a 230v electric motor, could I activate with the same scheme? Obviously I'll have to feed the engine with 230 instead of 12v, right?
Definitely so long as its a DC Motor. You need to have a Relay that can manage that level of Voltage and Current. Also 230Volts can easy stop your heart and kill you before you hit the floor. I'd only mess around with it if you are an electrician. DC Motors can run at various voltages with less efficiency. You may just be able to run your motor at a safer ~28V which, in that case, you could use this relay here - core-electronics.com.au/5v-2-channel-relay-module-10a.html
I have an application already built it C# which prints out a label. I would like to make changes so that when the user clicks on print a solenoid opens and sprays water into the box. Is this possible? Can I interact with Raspberry PI in C# ?
You can absolutely run, build and test Scripts written in C#. Here is a really nice guide to get you up to speed 😊 carmalou.com/raspberry-pi/2017/04/21/code-c-sharp-on-a-raspberry-pi-in-5-minutes.html
I want to make A mini jackhammer out of a push pull solenoid. I don't know how to make it work like a jackhammer?? like 'Push and pull' is one cycle like a jackhammer. I have been trying to find out how for like 4 days now. is there a little pcb board that can do this or control it?
Haha I love the idea, although once complete it will be more of a prop than a fully functioning Jackhammer. The solenoid doesn't have as much strength as compressed air. You can control the solenoid to open and close rapidly by altering the Python Scripts I provided here, you could also use an Arduino like this - core-electronics.com.au/guides/solenoid-control-with-arduino/
No problem mate. Take what you have learned here and apply it to the Face Recognition Script you can find in the guide here - core-electronics.com.au/tutorials/face-identify-raspberry-pi.html You'll be opening and closing doors in no time 😄
I have a question: I have a project which I just started working on that is similar to your video, my set up though has a 12v system using a momentary push button and I need to see the event using the RPI. My question is on the relay, are they bi-directional meaning if I hook the button to the 12v side and clicked the button would I see the event on the 3.3v side of the relay? Thank you in advance.
So take the time to check all the Specification Sheets, but with the right Relay you should be able to control a 12V system using a Raspberry Pi. That is one of the great things about relays allowing you to mechanisms on a higher voltage/current which are activated by a lower voltage/current device. Naturally plugging 12V electricity directly into a Raspberry Pi Board is a big no go though.
For the project I'm working on I need 6 12v solenoids which I planned on using an 8 channel relay for with the raspberry pi. How would I need to go about powering each solenoid? They would only be switched on one at a time for very short bursts. Is there any way to power them all with one supply? Thanks in advance
The Raspberry Pi needs to be at 5V, so to eliminate the need for that power-supply you can use a step down converter like this one and then pull the power for the Pi from the Solenoid Power supply - core-electronics.com.au/catalog/product/view/sku/ADA1385 Also check out this 4 channel relay module - core-electronics.com.au/catalog/product/view/sku/CE05279 Make a forum post and we can help you even more if you need 😊
Not on C# form application but I have got a video on using Tkinter to create GUI, perhaps worth a look. core-electronics.com.au/tutorials/Tkinter-Python.html
How wierd! If you make a forum post, link in video description, and copy and paste the error your having issues with, that would be the most effective way to troubleshoot and fix it.
The operating voltage of the GPIO pins is 3.3v with a maximum current draw of 16mA. As the Relay will be managing the heavy current/voltage needed for the pump, it isn't too important what current the Raspberry Pi can give out. Just so long as it is enough to activate the relay on and off.
You could, if your interesting in creating GUI to control the solenoid another option would be using Tkinter that works in the Python Programming Language
When the relay is actuated and it the solenoid changes states, is it constantly being powered until the relay is again actuated back? Or is the solenoid only powered in for a moment when it switches states?
I built this exactly the same as you - the green light on the relay turns on and off at intervals but it doesn't seem to power the 12V side - is it because my relay is too cheap and doesn't work with 3.3V ?
I have been using this setup for about two weeks no with no issues. However for the past 2 days whenever I turn on my rasberry pi and run the code, I will get to clicks (activations of the solonoid) and then the screen go black and the computer crash. Please if you have any fixes to this let me know. Thanks, Jdog
That is weird, perhaps the Micro-SD card has slightly corrupted. If re-flashing the card doesn't work send through some pictures of your set-up to our forum and we'll figure it out.
Is there such a thing as a normally closed solenoid of this same type for the pi? i.e. - when relay actuated, it makes solenoid rise, then falls back when relay opened again.
The lock solenoid designs that I have encountered are all extended when un-powered. Pop us a message on our forum and we can help you further - forum.core-electronics.com.au/
10 solenoids becomes a little bit of a challenge, 30 would be difficult, and 100 is an absolute monster of a project! The Raspberry Pi only has 26 IO pins that can turn a relay on and off, so the first challenge is getting more pins or efficiently using them. You can wire 20 pins up into a 10x10 matrix to get 100 outputs, search for something along the lines of "LED multiplexing" to find some good starting guides. The only issue with multiplexing is that you cant individually control all the solenoids, its better for only a few select at a time. If you want to individually control a lot of them at once, you might need to look for an IO expander, they ussually plug in via I2C and give you more IO pins. You will also need to manage your power which can add up really quickly. This sounds like a big project with a lot of moving parts, doing things at the scale of 100 is quite a challenge. If you are looking for some more guidance we have a community maker forum with lots of eyes over there that love these sorts of challenges, feel free to chuck a post there about your project! forum.core-electronics.com.au/
@@Core-Electronics Thank you for the detailed suggestions! I'll be looking for Expenders via I2C and also SPI. I've done some research and found 16 channel and 24 channel relays. I also found something called a I2C Multiplexer which I will also look more into to connect multiple I2C expenders so I can individually control each one of them. As for managing the power, that's a good point, I'll have to do some research. I'll definitely be reaching out to the community!
i've the exactly same schema, but i'm using Arduino and a solid state relay, i can see the led of the relay turning on, but the solenoid doesn't click...i don't have the short between the 2 pins of the relay...i really don't know why...
Would you have any idea why the output pin remains in high state once defined as output? As soon as one of my pins gets defined as GPIO.OUT, the state becomes GPIO.HIGH, yet when calling GPIO.output(pin, GPIO.LOW), the state remains high...
The first thing to troubleshoot would be to triple check you are plugged into the right pins, even after a decade of working with Pis its still sometimes a hiccup. If you are using a Pi 5 some libraries have had issues with the new way that the Pi 5 talks to the GPIO pins. You can try and use the GPIOZero library instead. Import the library with: from gpiozero import LED Initialise a pin with (this library calls them an LED output, but at the end of the day its the same digital on/off signal): solenoid_name = LED(14) And use it with: solenoid_name.on() solenoid_name.off() If these still don't work, feel free to post on our community forum topic for this post, we have lots of makers over there that can help! forum.core-electronics.com.au/t/how-to-control-a-solenoid-with-a-raspberry-pi-using-a-relay/10461/2
Absolutely a good point, those parenthesis are not needed for the script to run. I think it just helped me best understand the script as I was doing it.
Excellent question. This Relay is labelled as 5V but we can run it at 3.3V with no problem. To run this Relay the Supply Pin (Vcc) Voltage needs to be the same as the Logic Level Voltage (IN) Pin. Connecting the Relay to the 3.3V Pin means the High Signal will trigger at 3.3V and the Low Signal trigger at 0V. Max Signal Voltage from a Raspberry Pi GPIO is 3.3V so it can work. If instead we connected to the 5V Pin the High Signal would only be triggered at 5V and the Low Signal triggered at 0V. Max Signal Voltage from a Raspberry Pi GPIO is 3.3V so it would not be able to trigger the High Signal on the Relay. Hope this helps!
Is back EMF an issue to be worried about? When is it necessary to be using opt-isolated relays? PS. Love your videos and all the others by the Core Electronics team.
The relay used here has all the circuitry (most importantly a correctly placed diode on the PCB) to manage the Back EMF that this solenoid produces. If your working with much larger solenoids (or other back EMF producing hardware like DC Motors) with much higher voltages, an Optically Isolated Relay makes perfect sense. Thanks so much for your love 😊❤️ hope you have a fantastic week!
@@Core-Electronics so in general most relay modules have a back EMF diffuser mechanism such as flyback diode? I also wanna ask why it's fine to connect the 5V relay's VCC to 3.3V of RPi ? Thank you for this comprehensive tutorial
Thank you so much for the quick responce time! I just had one more question, could we use the 5v pins insted of the 3v pin. Because I am using three relays there are only two 3v headers and 2 5v. Or would I be able to attach two relays to one 3v header. Thank you so much for the help, keep up the helpful and amazing content!
Excellent question. So you won't be able to use the 5v pin. I wrote a comment below which explained the exact details of why. However there should be no issue attaching two relays to one 3.3v Pin if the relays are connected in parallel.
I've got a problem, I've done the connections just like you and connected everything, but it doesn't work, the green led switches from on and off but the solenoid lock doesn't work. The only thing different from your project is that i've used is a 12V 1A DC power supply, can this be the reason it doesn't work?
That relay is designed to work with a 5 Volt signal, but we've found it to work at the 3.3 Volt signals the Pico uses. We also have a dedicated guide to relays for the Pico if you want to check it out: core-electronics.com.au/guides/digital-electronics/getting-started-with-relays-examples-with-raspberry-pi-pico/
The main focus is how many relays can the Raspberry Pi control which will then be used to activate the Solenoid. You should be able to control at least 2 relays using this method but there are some fantastic Relay HATS for the Raspberry Pi which will let you control more. You can also use I2C expanders to control many many more (check the following links for examples of these). core-electronics.com.au/catalog/product/view/sku/CE04864 and core-electronics.com.au/catalog/product/view/sku/DEV-14150
You definitely can, Node.js is what I'd recommend if you were to start. Its not installed by default and there are some different versions to choose from. This should help - thisdavej.com/beginners-guide-to-installing-node-js-on-a-raspberry-pi/
@@Core-Electronics thanks for the info ☺️ my ultimate project is to make a small pinball machine using raspberry pi 4 using windows and javascript. Do you think that’s possible?
Oh yes I do! Just check out what I was looking at yesterday. This Pinball machine is all controlled via a Raspberry Pi 4 - ruclips.net/video/FajNEfTG89U/видео.html
Awesome video! Crazy how I thought to myself I'd never find a video of this, and here you were. Any recommendations on how you could link multiple solenoids to the raspberry pi? Say I wanted to have 5 latches (only opening one at any given time)
I'm attempting to do this remote through ssh with VS code, but from some reason after installing all the dependencies and packages I can't use "import RPi.GPIO" its like it doesn't exist
Heyya mate, using GPIO through SSH remotely seems to have some intricacies that I've only just become aware of. Come give this a look here - gpiozero.readthedocs.io/en/stable/remote_gpio.html and this here stackoverflow.com/questions/52678458/python-over-ssh-event-detect-not-working . Hopefully that will help solve your issues
Hi Tim, would this general set up work with the 36v solenoid for sale on your website? Also, could you power the raspi and solenoid with batteries, as opposed to mains power?
Heyya mate, if your talking about the 36V Solenoid I have linked then even though the datasheet states that the solenoid is rated for 36V they will work like a charm at 12V - core-electronics.com.au/solenoid-36v.html - And so long as you supplied the solenoid with 12V, the Raspi with 5V and had enough current available you absolutely can power the system from batteries.
@@Core-Electronics Thanks, I really want to operate it at the full 36V, because I need the solenoid to "pack a punch"!! I'll be using a separate 36V battery for the solenoid and probably a 5V/3A battery for the Pi, but do you think the 5V/3A battery will have enough "juice" to trigger the relay?
You are mistaken and missed details. The power supply is only supplying the load and the relay can work on the NO/NC contacts and common contact safely within the 10A/250V AC or 10A/30V DC specifications. The "VCC" pin that caused you confusion will have 5V because the Raspberry was powered by USB
Hi Tim, Excellent tutorial! I have a question, is it possible to connect six 5v solenoid with a raspberry pi working all together at the same time? I'm working on a Braille project for donate to blind kids. I hope you can help me. Thanks!
Hey mate 😊 big thanks. I think I found the perfect product for you, the linked product will give you 8 Relays on a HAT that you can use to control the 8 Solenoids. core-electronics.com.au/catalog/product/view/sku/CE08528 Love the idea of the project! Come do a write up at our forums when your done.
If you are looking at powering the Solenoid, you could definitely use a buck converter! As long as it can supply enough current for the solenoid to actuate.
Why not just suggest that people get a 3.3v relay or a relay hat designed for the Pi instead of using a 5v relay that "works fine"? I can imagine a scenario where someone buys a 5v relay off Amazon, finds it doesn't work with the 3.3v pin, tries it with the 5v pin, and fries their Pi. Would it be that hard to just stock a 3.3v relay or a hat?
You might be better using the pi for home assistant, then use esp32 boards or 8266 boards as the micro controller, to control the electrical signal, home assistant is a very powerful system and your already doing most of the processes required to utilise it, and affords a wider scope of operations/ functions, just a thought for anyone going down this route.
Using a solenoid like the one in this guide won't be powered in the locked position. If it was it would gradually overheat. The way that it locks is based on the shape of the latch. When it is in locked position it physically won't be able to open as it will bump up against the female side of the latch. Only when the solenoid is activated and pulls the latch back will you be able to open the door.
1:50 top red line goes to 3.3v on rpi, should be 5v for the 5v relay, on relay NC normally closed (here 12v power to solenoid = bad), NO normally open (no power to solenoid) 4:06 while (True): why add the () it is useless
I got a raspberry pi a week ago and just found your channel. You have the easiest to understand explanations of both the hardware and software side of things. Great video, and I'm looking forward to seeing more of your content.
Glad to help ! 😊
Thank you overwhelmingly.
Thanks to you, you saved a Korean college student.
문제 없어요 😊!
The way you explain things matches perfectly how my old brain learns. Thank you for this, great job.
Hi, thank you for this video. I liker your clear, consise and direct style of presenting info. It has all it needs.
I actually needed this information to do the same thing with a Raspberry Pi Pico! Same principle, really! THANK YOU!!!
Yay, hope your project is going well 🙂
@@Core-Electronics I shall endeavor to do so, good sir!
you do a great job on your videos!
hi i have issue, connected using 3.3v but relay doesnt work, red led indicator shown, however if connected to 5v the relay works but it will keep turned on. please advised on the steps or approach. Using SONGLE relay module 5v
10/10 tutorial
😊😊
Can i make this project with supplying power just to the raspberry pi instead of both the raspberry pi and solenoid? Like instead of needing 2 power sources.
Good info and video
This would be great to have in your room & unlock this with a fingerprint scanner or an LCD display.
We've got a separate video about a fingerprint scanner for Raspberry Pi, you could easily combine those two guides together if you were interested. Check it out here: ruclips.net/video/-IUae_-LqR4/видео.html
@@Core-Electronics Thanks! Your videos are amazing
Can I use multiple relays attached to the rassbeery pi? I would need around three total
Absolutely. And if you needed to control even more that that I would recommend using this HAT core-electronics.com.au/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi-mini-kit.html
@@Core-Electronics Thanks so much for this video and your replies to comments. I would need to control 16 solenoid (DC 12V). COuld I use 16 relays connected to 16 solenoids? Would there be issue of the relays share the same 3.3V power from the PI? Regarding your suggestion about using the above HAT, I am not sure it work for solenoids that need 12 V (looks like it is for driving servo motor of 5 V). I am not very experienced so any comment suggestion super welcome. thanks a lot
are you certain connecting the positive end of my 5v relay to the 3.3 pin wont burn out my raspberry pi?
use the 5v pin on the rpi
Hello, I have a question about the raspberry nano and pico, they dont operate on 5v but 3,3v can they operate these relais, or do u need a stepup something in the middle?
The exact Relay you see in the video will work just fine with the Raspberry Pi Pico. In the Specification on the Product Page you will see this - While marked as a 5V supply voltage & input signals, we have found this to work fine at 3.3V - core-electronics.com.au/catalog/product/view/sku/CE05137
Rhanks, I am.still in doubt if I should go for arduno and a pi as server or everything pi. I lean more to everything pi. I want to connect everything by utp. And I dont like to solder, so I meed shields/hats for all sensors and.a couple.of.motors. real headach to figire it out.
thank you so match ....great video
Excuse my ignorance, by replacing the solenoid with a 230v electric motor, could I activate with the same scheme? Obviously I'll have to feed the engine with 230 instead of 12v, right?
Definitely so long as its a DC Motor. You need to have a Relay that can manage that level of Voltage and Current. Also 230Volts can easy stop your heart and kill you before you hit the floor. I'd only mess around with it if you are an electrician. DC Motors can run at various voltages with less efficiency. You may just be able to run your motor at a safer ~28V which, in that case, you could use this relay here - core-electronics.com.au/5v-2-channel-relay-module-10a.html
Thanks for this. Some people say to use a diode to stop current flowing back?
I have an application already built it C# which prints out a label. I would like to make changes so that when the user clicks on print a solenoid opens and sprays water into the box. Is this possible? Can I interact with Raspberry PI in C# ?
You can absolutely run, build and test Scripts written in C#. Here is a really nice guide to get you up to speed 😊 carmalou.com/raspberry-pi/2017/04/21/code-c-sharp-on-a-raspberry-pi-in-5-minutes.html
I want to make A mini jackhammer out of a push pull solenoid. I don't know how to make it work like a jackhammer?? like 'Push and pull' is one cycle like a jackhammer. I have been trying to find out how for like 4 days now. is there a little pcb board that can do this or control it?
Haha I love the idea, although once complete it will be more of a prop than a fully functioning Jackhammer. The solenoid doesn't have as much strength as compressed air.
You can control the solenoid to open and close rapidly by altering the Python Scripts I provided here, you could also use an Arduino like this - core-electronics.com.au/guides/solenoid-control-with-arduino/
Super vid! Cheers
Thanks 😃
good, I want to realize that I can turn on my miner remotely, can I get it? which Raspberry P buy? Thank you
Come pop us a message on our forum 🙂 that way we can get our whole team to help you.
Thank you so much for the video! Do you have a project where facial recognition is carried out so that the relay can be opened?
No problem mate. Take what you have learned here and apply it to the Face Recognition Script you can find in the guide here - core-electronics.com.au/tutorials/face-identify-raspberry-pi.html
You'll be opening and closing doors in no time 😄
I have a question: I have a project which I just started working on that is similar to your video, my set up though has a 12v system using a momentary push button and I need to see the event using the RPI. My question is on the relay, are they bi-directional meaning if I hook the button to the 12v side and clicked the button would I see the event on the 3.3v side of the relay? Thank you in advance.
So take the time to check all the Specification Sheets, but with the right Relay you should be able to control a 12V system using a Raspberry Pi.
That is one of the great things about relays allowing you to mechanisms on a higher voltage/current which are activated by a lower voltage/current device. Naturally plugging 12V electricity directly into a Raspberry Pi Board is a big no go though.
it's works.. thank you bro
You're welcome!
For the project I'm working on I need 6 12v solenoids which I planned on using an 8 channel relay for with the raspberry pi. How would I need to go about powering each solenoid? They would only be switched on one at a time for very short bursts. Is there any way to power them all with one supply? Thanks in advance
The Raspberry Pi needs to be at 5V, so to eliminate the need for that power-supply you can use a step down converter like this one and then pull the power for the Pi from the Solenoid Power supply - core-electronics.com.au/catalog/product/view/sku/ADA1385
Also check out this 4 channel relay module - core-electronics.com.au/catalog/product/view/sku/CE05279
Make a forum post and we can help you even more if you need 😊
Also take a look at this - core-electronics.com.au/catalog/product/view/sku/DEV-14150
@@Core-Electronics thankyou! :)
Question: does the 5v relay module can also work in raspberry pi 3 b+ with this tutorials?
do have a video on how you will control this from c# form application?
Not on C# form application but I have got a video on using Tkinter to create GUI, perhaps worth a look. core-electronics.com.au/tutorials/Tkinter-Python.html
what is this connector called which is used to connect 12v supply with jumper cables?
I got you, its a DC Barrel Plug, you can find it here - core-electronics.com.au/dc-barrel-plug-to-2-pin-terminal-block-adapter.html
Great video! Do you know how much Ib this solenoid can handle? If I want to use this setup to build a trapped door for an ice dispenser, for example?
Can we operate more than 10000 12v which are connected in series and and can we have control which seluonoid to on or which to get off please advise
I'm getting a sudo verification error when trying to add my Rpi, can you give me guidance of what I need to look for or change ?
How wierd! If you make a forum post, link in video description, and copy and paste the error your having issues with, that would be the most effective way to troubleshoot and fix it.
Why are you not using a diode to protect against voltage spikes?
The relay is able to do the job of the diode in this set up as it has inbuilt voltage spike protection.
@@Core-Electronics however, since the relay also has a electromagnet built in, it needs a diode on it's own. Or not?
How much current can raspberry give out from gpi pin ,want to control a pump with solid state relay if possible, plzz reply
The operating voltage of the GPIO pins is 3.3v with a maximum current draw of 16mA. As the Relay will be managing the heavy current/voltage needed for the pump, it isn't too important what current the Raspberry Pi can give out. Just so long as it is enough to activate the relay on and off.
what do I do if I need to operate 6 solenoids with one rpi ? Is it possible at all?
can i know why i flw your step but also cannot if i use the solenoid in power supply can, but in the raspberry cannot.
can you integrate this to a c# window form application?
You could, if your interesting in creating GUI to control the solenoid another option would be using Tkinter that works in the Python Programming Language
When the relay is actuated and it the solenoid changes states, is it constantly being powered until the relay is again actuated back? Or is the solenoid only powered in for a moment when it switches states?
Hey Brett, the relay acts like a switch and when it changes state, it will keep powering the solenoid until the relay is turned back off
I built this exactly the same as you - the green light on the relay turns on and off at intervals but it doesn't seem to power the 12V side - is it because my relay is too cheap and doesn't work with 3.3V ?
i have the same problem. Any solution ??
HI, do know how can i connect this for facial recognition and use microsoft azure face api?
I have been using this setup for about two weeks no with no issues. However for the past 2 days whenever I turn on my rasberry pi and run the code, I will get to clicks (activations of the solonoid) and then the screen go black and the computer crash. Please if you have any fixes to this let me know.
Thanks, Jdog
That is weird, perhaps the Micro-SD card has slightly corrupted. If re-flashing the card doesn't work send through some pictures of your set-up to our forum and we'll figure it out.
Is there such a thing as a normally closed solenoid of this same type for the pi? i.e. - when relay actuated, it makes solenoid rise, then falls back when relay opened again.
The lock solenoid designs that I have encountered are all extended when un-powered. Pop us a message on our forum and we can help you further - forum.core-electronics.com.au/
would it be safe to have a normally open solenoid always not extended?
Heyya, if you keep a solenoid active for a long time (>20 minutes ) it will get too hot to touch. Thats the limiting factor.
What if I want to control 100 solenoids? Are there any hats I can stack on the raspberry pi? Or a way to connect multiple multi-channel relays?
10 solenoids becomes a little bit of a challenge, 30 would be difficult, and 100 is an absolute monster of a project! The Raspberry Pi only has 26 IO pins that can turn a relay on and off, so the first challenge is getting more pins or efficiently using them. You can wire 20 pins up into a 10x10 matrix to get 100 outputs, search for something along the lines of "LED multiplexing" to find some good starting guides. The only issue with multiplexing is that you cant individually control all the solenoids, its better for only a few select at a time.
If you want to individually control a lot of them at once, you might need to look for an IO expander, they ussually plug in via I2C and give you more IO pins. You will also need to manage your power which can add up really quickly. This sounds like a big project with a lot of moving parts, doing things at the scale of 100 is quite a challenge. If you are looking for some more guidance we have a community maker forum with lots of eyes over there that love these sorts of challenges, feel free to chuck a post there about your project!
forum.core-electronics.com.au/
@@Core-Electronics Thank you for the detailed suggestions! I'll be looking for Expenders via I2C and also SPI.
I've done some research and found 16 channel and 24 channel relays.
I also found something called a I2C Multiplexer which I will also look more into to connect multiple I2C expenders so I can individually control each one of them.
As for managing the power, that's a good point, I'll have to do some research.
I'll definitely be reaching out to the community!
Thank you so much. But, is it confirmed that 3.3V will make all the 5V relays work?
For this particular gear absolutely. Check the specification sheet to find out whether a particular component is capable of running at lower voltages.
@@Core-Electronics Thanks a lot
i've the exactly same schema, but i'm using Arduino and a solid state relay, i can see the led of the relay turning on, but the solenoid doesn't click...i don't have the short between the 2 pins of the relay...i really don't know why...
Would you have any idea why the output pin remains in high state once defined as output? As soon as one of my pins gets defined as GPIO.OUT, the state becomes GPIO.HIGH, yet when calling GPIO.output(pin, GPIO.LOW), the state remains high...
The first thing to troubleshoot would be to triple check you are plugged into the right pins, even after a decade of working with Pis its still sometimes a hiccup. If you are using a Pi 5 some libraries have had issues with the new way that the Pi 5 talks to the GPIO pins. You can try and use the GPIOZero library instead.
Import the library with:
from gpiozero import LED
Initialise a pin with (this library calls them an LED output, but at the end of the day its the same digital on/off signal):
solenoid_name = LED(14)
And use it with:
solenoid_name.on()
solenoid_name.off()
If these still don't work, feel free to post on our community forum topic for this post, we have lots of makers over there that can help!
forum.core-electronics.com.au/t/how-to-control-a-solenoid-with-a-raspberry-pi-using-a-relay/10461/2
Why put parenthesis around the "True" in the while loop?
Absolutely a good point, those parenthesis are not needed for the script to run. I think it just helped me best understand the script as I was doing it.
why do you attach the 3.3V pinout to a 5V relay?
Excellent question. This Relay is labelled as 5V but we can run it at 3.3V with no problem. To run this Relay the Supply Pin (Vcc) Voltage needs to be the same as the Logic Level Voltage (IN) Pin.
Connecting the Relay to the 3.3V Pin means the High Signal will trigger at 3.3V and the Low Signal trigger at 0V. Max Signal Voltage from a Raspberry Pi GPIO is 3.3V so it can work.
If instead we connected to the 5V Pin the High Signal would only be triggered at 5V and the Low Signal triggered at 0V. Max Signal Voltage from a Raspberry Pi GPIO is 3.3V so it would not be able to trigger the High Signal on the Relay.
Hope this helps!
Amazing answer! Thank you.
@@Core-Electronics thanks, it's useful
Is back EMF an issue to be worried about? When is it necessary to be using opt-isolated relays? PS. Love your videos and all the others by the Core Electronics team.
The relay used here has all the circuitry (most importantly a correctly placed diode on the PCB) to manage the Back EMF that this solenoid produces. If your working with much larger solenoids (or other back EMF producing hardware like DC Motors) with much higher voltages, an Optically Isolated Relay makes perfect sense.
Thanks so much for your love 😊❤️ hope you have a fantastic week!
@@Core-Electronics so in general most relay modules have a back EMF diffuser mechanism such as flyback diode? I also wanna ask why it's fine to connect the 5V relay's VCC to 3.3V of RPi ? Thank you for this comprehensive tutorial
Thank you so much for the quick responce time! I just had one more question, could we use the 5v pins insted of the 3v pin. Because I am using three relays there are only two 3v headers and 2 5v. Or would I be able to attach two relays to one 3v header. Thank you so much for the help, keep up the helpful and amazing content!
Excellent question. So you won't be able to use the 5v pin. I wrote a comment below which explained the exact details of why.
However there should be no issue attaching two relays to one 3.3v Pin if the relays are connected in parallel.
I've got a problem, I've done the connections just like you and connected everything, but it doesn't work, the green led switches from on and off but the solenoid lock doesn't work. The only thing different from your project is that i've used is a 12V 1A DC power supply, can this be the reason it doesn't work?
Will this also work with a raspberry pi pico and the very same relay?
That relay is designed to work with a 5 Volt signal, but we've found it to work at the 3.3 Volt signals the Pico uses.
We also have a dedicated guide to relays for the Pico if you want to check it out: core-electronics.com.au/guides/digital-electronics/getting-started-with-relays-examples-with-raspberry-pi-pico/
Hello dude, I have an 12 volts solenoid, is it okay to use 12v relay module?
Thank you
this is how to youtube
would this work if i used a smaller solenoid
Yes it will!
How many solenoids can one raspberry pi control independently?
The main focus is how many relays can the Raspberry Pi control which will then be used to activate the Solenoid. You should be able to control at least 2 relays using this method but there are some fantastic Relay HATS for the Raspberry Pi which will let you control more. You can also use I2C expanders to control many many more (check the following links for examples of these). core-electronics.com.au/catalog/product/view/sku/CE04864 and core-electronics.com.au/catalog/product/view/sku/DEV-14150
Great video would i work with the Pi Zero WH ?
It should be able to work, the Pi Zeros have the same 40 pin layout
Can you control raspberry pi with javascript instead of python?
You definitely can, Node.js is what I'd recommend if you were to start. Its not installed by default and there are some different versions to choose from. This should help - thisdavej.com/beginners-guide-to-installing-node-js-on-a-raspberry-pi/
@@Core-Electronics thanks for the info ☺️ my ultimate project is to make a small pinball machine using raspberry pi 4 using windows and javascript. Do you think that’s possible?
Oh yes I do! Just check out what I was looking at yesterday. This Pinball machine is all controlled via a Raspberry Pi 4 - ruclips.net/video/FajNEfTG89U/видео.html
Awesome video! Crazy how I thought to myself I'd never find a video of this, and here you were.
Any recommendations on how you could link multiple solenoids to the raspberry pi? Say I wanted to have 5 latches (only opening one at any given time)
Instead of an sd card, you can use an ssd, its far more stable,faster and alot more memory.
cab we use a 5V solenoid ??
You definitely can, just make sure to use a 5V Power supply 😊
I'm attempting to do this remote through ssh with VS code, but from some reason after installing all the dependencies and packages I can't use "import RPi.GPIO" its like it doesn't exist
Heyya mate, using GPIO through SSH remotely seems to have some intricacies that I've only just become aware of. Come give this a look here - gpiozero.readthedocs.io/en/stable/remote_gpio.html and this here stackoverflow.com/questions/52678458/python-over-ssh-event-detect-not-working . Hopefully that will help solve your issues
What happend if the realy is 12 vdc ? It will work at the same ?
If you tried to use a 12 Volt relay it would never actuate as the maximum voltage that the Raspberry Pi can provide is lower.
Hi Tim, would this general set up work with the 36v solenoid for sale on your website? Also, could you power the raspi and solenoid with batteries, as opposed to mains power?
Heyya mate, if your talking about the 36V Solenoid I have linked then even though the datasheet states that the solenoid is rated for 36V they will work like a charm at 12V - core-electronics.com.au/solenoid-36v.html -
And so long as you supplied the solenoid with 12V, the Raspi with 5V and had enough current available you absolutely can power the system from batteries.
@@Core-Electronics Thanks, I really want to operate it at the full 36V, because I need the solenoid to "pack a punch"!! I'll be using a separate 36V battery for the solenoid and probably a 5V/3A battery for the Pi, but do you think the 5V/3A battery will have enough "juice" to trigger the relay?
@@andrewrider3965 That should be a good amount of current, the Spec sheet recommends 2.7 amps at 36 Volts so you are within the ballpark.
Is the 12 v power supply damage the relay
You are mistaken and missed details. The power supply is only supplying the load and the relay can work on the NO/NC contacts and common contact safely within the 10A/250V AC or 10A/30V DC specifications. The "VCC" pin that caused you confusion will have 5V because the Raspberry was powered by USB
Hi Tim, Excellent tutorial! I have a question, is it possible to connect six 5v solenoid with a raspberry pi working all together at the same time? I'm working on a Braille project for donate to blind kids. I hope you can help me. Thanks!
Hey mate 😊 big thanks. I think I found the perfect product for you, the linked product will give you 8 Relays on a HAT that you can use to control the 8 Solenoids. core-electronics.com.au/catalog/product/view/sku/CE08528
Love the idea of the project! Come do a write up at our forums when your done.
Why can't you use a 5v dc to 12v dc boost convert instead of using 12v mains power?
If you are looking at powering the Solenoid, you could definitely use a buck converter! As long as it can supply enough current for the solenoid to actuate.
I have a excavator , can i control the solenoid by this ideas ? because my electric system is gone . Thank you
So long as you have power this system will be able to control a solenoid :) and you can scale if up if need be.
Why not just suggest that people get a 3.3v relay or a relay hat designed for the Pi instead of using a 5v relay that "works fine"? I can imagine a scenario where someone buys a 5v relay off Amazon, finds it doesn't work with the 3.3v pin, tries it with the 5v pin, and fries their Pi. Would it be that hard to just stock a 3.3v relay or a hat?
Why no pull down resistors?
Why do you tubers talk like that, with the upward inflections and enunciating every full stop? lol - great vid tho
Makes it easier to splice together different takes.
He’s just an Australian…
You might be better using the pi for home assistant, then use esp32 boards or 8266 boards as the micro controller, to control the electrical signal, home assistant is a very powerful system and your already doing most of the processes required to utilise it, and affords a wider scope of operations/ functions, just a thought for anyone going down this route.
I used the same code but the door is only unlocked. Lock part is not working
Using a solenoid like the one in this guide won't be powered in the locked position. If it was it would gradually overheat. The way that it locks is based on the shape of the latch. When it is in locked position it physically won't be able to open as it will bump up against the female side of the latch. Only when the solenoid is activated and pulls the latch back will you be able to open the door.
How would I know end the loop to a simple open then lock? Instead of it constantly looping the process???
Why do you write while ( True) :
How is this different to while True:
probably had some other code in it before, "while 1:" is also valid.
@@jyvben1520 thanks for letting me know - really appreciate it
Are any of these methods more preferred than the others I wonder ?
@@Keeping_IT_Simple no, it is just an unending loop, personal preference, i like typing less.
the brackets are for containing a logic statement like `while (x==1)`. the language allows you to remove the brackets. it changes nothing
@@nil0bject thank you for taking the time to let me know !
1:50 top red line goes to 3.3v on rpi, should be 5v for the 5v relay, on relay NC normally closed (here 12v power to solenoid = bad), NO normally open (no power to solenoid)
4:06 while (True): why add the () it is useless
You need a snubber diode