Pete - thanks for this comprehensive guide - it's really been helpful. Having said that and having wired everything up as you said, I too have suffered some of the same issues that others have been reporting here and I believe I have found a work-around that requires no additional components and is very straightforward. I'm using a RPi 3, GrovePi sensor board and a 16 channel relay board very similar to yours except mine is a 5V input rather than 12V. What I eventually established is that you only need one 3V3 connection from the RPi to the relay 5V pin. Leave the other 5V pin unconnected. Then only connect 1 ground wire from the RPi to the GND pin on the relay board - making sure you connect the GND on the same row as the 5V pin you have connected to the RPi. So instead of having 20 wires connecting the RPi to the relay board I only have 18. I have had no problems whatsoever since doing this and all of your scripts have worked as they should. Hope this helps everyone else.
Spent an hour researching why the relays would turn on, but not turn off. Then I saw Eric Steed's post below. Changing the VCC connection from Pin 2 (5V) to Pin 1 (3.3v) and everything worked as expected.
Hi. Wonderful job! Many thanks for that huge work. I was searching for "how to connect a SainSmart 16 channel board in the most simpliest way" and I founded it! Thanks! In my project, I want to use the 16 channels board directly on a RspiB mounted with Domoticz and an Arduino in USB mounted with "MySensors" and several sensors in a hydroponic project 100% automatized. You helped me to leave the first stone. Respect to all people sharings skills and passions over Internet. Following you now.
I have hooked up my 16 port relay and Raspberry 3 per your video. The problem is when the script runs, the relays lock on and won't go off. Not really sure what is going on? Can you help? Thanks
I have the same relay switch except that it runs on 5v instead of 12v (I'm powering it from a 5v 2A dc adapter). Your scripts worked like a charm. Thanks man :-)
When I get my man cave built, thinking of creating a smart garden with lights and auto plant watering. Thanks for the videos, really clear and understandable.
Thank you for replying , I' ll try to post a video, I have a 4 channel relay running some of your scripts, I have connected 1 LED light strip on each relay, running your script2 I thought the lights would turn on/off in the order the relay is switching (wave like), instead all the 4 led strips light up at the same time, what I wanted to accomplish was to have a sequence in the order the relay is switching like a light show, I know I may be confusing you with this question, so will try to post a video as soon as I can , i ordered all the same parts listed on your 4 channel relay video. Thank you so much!
Great video, i too can't get it to work how you have it shown. Some of the comments have had people connect the 5V rail on the relay to the 3.3v on the PI. While this appears to work, several people said it fried the PI. I think I will have to just use two 8 channel relays for what I want to control. I wasn't too happy about needed a 12v external power source anyway.
Check the amperage of the 5+v on the board, if it is higher than what your pi requires it will fry your pi, if it it is too much under the amperage then your pi will not work.
I know this video is 5 years old but I wanted to put it out there that I have a raspberry pi 4 B and I was getting all relays on at the same time when GND and 5V were supplied to both or just one. I switched that to a single row of GND and 3V3. I also had to not use GPIO4 and GPIO22, not sure why but they were supplying power in LOW and HIGH states. I changes the code for GPIO4 and 22 to GPIO23 and GPIO24 and that solved my power leak issue. Summary: use 3V3(only one row) and if any voltage leak change GPIO to another one.
I figured out what my problem was. I was using the 5 V connection from my pi zero to the board. When I switched it over to 3.3 V, everything worked like a chanp. I'm using the same exact really is you, the same smart 16 channel really with Opto couplers.
The problems that various people describe here that all the relays immediately turn on all together isquite explainable when you know the anatomy of this board: It isnt really made for 3v3. The input consists of an optocoupler that has its anode tied to +5Volt via a 1k resistor. The GPIO of the Raspberry then connects to the cathode of the optocoupler. On the secundary side of the optocoupler the collector is tied to 5Volt and the emitter is pulled to earth via a 10k resistor. The emitter then drives an ULN2803 which is an open collector, so it has the relay between the output and the 12 Volt. So here is what happens with the signal: Raspberry LOW -> optocoupler +serieresistor get 3V3 ->optocoupler opens ->emitter goes HIGH -> INPUT ULN2803 goes HIGH ->OUTPUT ULN2803 goes LOW -> Relay activated. So, as you can see from this, and which is clear from the script, you need a LOW to activate the relays and a HIGH to deactivate the relays. Now that is where the problem is. The 3V3 RASPI has no problems creating a LOW to activate the relay, but what happens if you send a HIGH. For arguments sake lets say that a HIGH on the raspi is 3Volt. That means that the optocoupler + serieresistor will still see 2 Volt.Not much, but it might be enough to open up the optocoupler, which will activate the relay, just as a LOW signal did. So why did not everybody have that problem, why did it work for Pete and not for others? Simply because of variation in components. So, what to do? Well, the easiest is to add 16 transistor leveladapters that have their collectors connected to the input of the board. added bonus is that they also invert the signal so you get an active HIGH contraption another solution is to bypass the LM2576 and feed the primary optocoupler with 3V3. Though adding the 16 resistors is a good solution, it is kinda ironic that those 16 resistors by itself already are capable of driving 16 relays
@@matthewdornfeld2126 it is about the one in the link in the discription. Further discussed here: arduinodiy.wordpress.com/2018/09/04/the-16-relay-module-and-the-raspberry-pi-not-an-ideal-marriage/
Thanks for the video (16 channel Relay Raspi)really useful. Got it all working with a Pi Zero. I noticed that the 5v back feeds from the relay board and powers the Zero, so I am wondering if 5v really needed by the relay board as it appears to provide this via the 12v connection. Going to use this to provide an automated control for my wifes doll house light with a LDR and PIR so lights will change when PIR triggers. Got a bit of programming to first!
In order for the relay board to work for a Raspberry Pi 4 you must ensure the inputs are active HIGH. Most boards out there are active or trigger LOW. If you have a active LOW board you will need to place a Darlington sink drive ahead of the relay board inputs. Use something like a ULN2803. You will need two of them, cost about $1.25 each.
Hi Sir pete I found your Channel it's so great,I hope I can learn your program and how use the raspberry board.God bless. I am also a new subscribers of yours . Thanks
Hey @skiwithpete, great video and great focus on the camera, thanks. One question please, as i have a similar module and struggling to figure out what's wrong. If you connect the 12v power to the module and then the 5v+GND from the module to the 5v_GND of the rPi, does it power the rPi on? I connected the 12v power to the module, used a multimeter on the 5v and gnd pins and it gives me 5v. Is that normal? Could you check on yours?
Check the amperage on the 5+v, it should be somewhere between 1.5+ amps to 3.0 amps to power the rpi. Connect the positive of you amp meter to positive post on the board and negative to negative post on the board. Depending on which pi you are using (check what voltage and amperage is required for that pi), you ought to be able to power your pi from that board.
I retrofited an old washing machine with this board. It came with a broken mechanical programmer. The only issue was when runing the motor at full speed the relay burned after a few uses because it was arcing (the motor turns into a generator when speeding down). I needed to add an anti arcing circuit to avoid that so it was not a big issue since I had a few spare relays to use.
I like how they used optocouplers on-board it makes it less worrisome about buffering the GPIO's. I did unfortunately have a death in my Raspberry Pi family. This is the cost of not checking your GPIO wiring.
Alright, I have no idea what I'm doing and I've been at it for the last 3 hours. When I run the first program you have all the relays turn on but when it runs through each one individually nothing happens. I've done some testing out found if I set the pin on the board to output the relay activates but when set to input the relay deactivates. I can't control the relay by setting the pin high or low just by changing the mode of the pin to in vs out. Why is it doing this? and how can I fix it?
Okay I got it to work with the raspberry pi. My particular relay board and probably yours too works on 5v logic and the pi is 3.3v logic. All you need is a logic level converter can be bought for dirt cheap. (Relays requires the 5v to signal off position so you can turn it on but not off)
im having some issues, with just the connections. I'm using a RPI 4 with a 16channel 5V relay board. what I'm having trouble with is that when i do a GPIO.setup all the relays with be switch on and i am unable to switch it off or control it, unless i do a cleanup. send help
This video series is great. My question is. How can you turn on more than one relay at a time? Then turn them off at different times? That way they're not so patterned. They could be more random, or sync to music? Thanks for any help that you can provide.
I am planning out a project and I think this video is going to be pretty useful. Thank you so much for making it. My plan is to power some 12v 2amp devices, only, one at a time. My question. If the board uses 12v, what power supply would I need to power: the pi, relay board, and 1 relay output 12v 2 amp? Or do I need to split a separate 12v 2amp power supply into 12 outputs and wire each relay separately? (p.s. just starting out, sorry if its a noob question.)
The pi and the relay need separate power since it operates on 5V. There is a way to step down - but I don't do it. The question you asked though is can 12V power the relay, and power something on the other side too? Yeah, it can. Take a look at my "outdoor light setup" video, you'll see how I split the power.
Hi skiwithpete, I'm trying to connect the relay to control my home light. I use the relay to turn off/on the light from my Pi with no problems. But how can get the input from the physical switch light buttons and update the status of relay in Pi? In addition, what is the best way to add more gpio to Pi for example, I need to control 32 relays (outputs) , which means I need 60 gpios ( input + output) , Can I use a chip like this - mcp23017 ?
Anan My thoughts exactly! It will make the wiring, easy enough here, even more easier. What do we rate I2C or SPI? SPI Bus has great range and extendability in space. uk.farnell.com/microchip/mcp23017-e-sp/ic-io-expander-16bit-i2c-28dip/dp/1332088?CAWELAID=120173390001317605&CMP=KNC-GUK-GEN-KWL&mckv=PpFlXUmR_dc|pcrid|186409721995|&gclid=Cj0KCQiA8_PfBRC3ARIsAOzJ2up7DjZxOCZL_Cen37JrHBbdhxoFt6XbTe6iTy3dBNfTw0NxUHGfOmAaAjgKEALw_wcB
Greetings all I have the Sainsmart 16 channel board. I have watched the video which is very good. I have hooked my pi up the same way. But I can't seem to get it working right. When I power the pi and run the script, some of the relays come on and stay on. I have loaded your script and it still does the same thing. I wish someone could come up with the answer. I have read the comments from other folks and not really seeing the right answer to get it working. I have a 12V 3 A power supply hooked to the relay board. I have disconnected the ground wires and tried it. Still not working. I have disconnected the 5v wires and even moved them over to the 3 V side. Still not working right. I do see that your running the raspberry pi 2. Could that be the whole problem? I have seen that a few folks have got it running with the raspberry pi 3. I could use some help. Thanks everyone.
Learn a lot from this video. I do have one question. If I was going to wire in some water pumps to this relay. Does the positive wire from my pump go into the center of the relay? The ground for my pump does it go into the relay or should it go back to the power supply?
Yeah this only interrupts one wire in the circuit. Positive or neutral it doesn't really matter. But in your example, yes interrupt the positive and the neutral goes straight back to power.
For christmas lights you wouldn't want all that clicking, you'd use a MOSFET OR SSR (solid state relay)... They use less power, are silent in operation of and can switch at significantly faster rates. Plus a bank if them would take up significantly less space...
I have a trouble when I turn off the relay. The code I used is the same as you but I debugged it, when it run to "GPIO.setup([PIN_NUMBER], GPIO.OUT]", the relay of this PIN_NUMBER is turned on. Can anybody help me for it? THANKS
I followed your video that I must say was very easy to follow. Only thing I am not sure on is the power from the pins on the pi to the relay board. The relay board says it's an output of power not a in put. Does it do both or am I reading wrong. I'm running 12 v 1 amp power to the relay board and the 5v pin is powering my pi with no transformer. Please help me understand a little better
Your python programming is absolutely wonderful. I learned so much. Thank you. In the first script, I learned how you designated the pins as output pins using a "for" loop. I wonder why you couldn't do the same thing for the long section where you used "try:" I'm a beginner with python and was just wondering.
Nice intro to this 16channel board. One thing I question is why you would set the GPIOs to outputs before setting their state to high. Is this just a limitation of the RPi.GPIO library i.e. it won't let you set the state before it is set to an output? I've not done any gpio work with the RPI yet but I've always set the state first then enable the output that way there is no quick spike on the output.
I don't remember why I did this. I think it's because I had two types of relay. One that started high one that started low, so this set them all to same state... But I'm not 100%
Hi, love your video, Im totally new at this, I have set this up and have a question, I connected led lights to it, but all the lights turn n at the same time, is that whats supposed to happen or should they light up in a sequence, thanks,
I notice when the GPIO is set to "output" doesn't matter if it's true/high or false/low, there is some voltage coming out of that GPIO pin. Very low .179volts, this is why I think the relay stays on, and doesn't turn off for me.
Those are NOT 5V input pins on the relay board. This is the second video I have seen where this is stated. Those are 5V OUTPUT pins used for things like Arduino if the user wanted to piggy back their Arduino off the back of the relay board. There is even a chip that regulates that 5V output supply from the 12V supply you add under those screw sockets. I dunno if the Pi has separate 5V input pins though. The Arduino does. It is a poorish design placing those 5V and GND pins alongside the low level inputs. It is confusing. Those 5V and GND pins should be separated elsewhere on the board.
Hi great vid! How would I go on about if I wanted an input from the relay to the board? Case scenario being -- when a light in a room has been switched on, I'd like the relay to send a signal to the board that the light has been switched on? -- Would this be possible? How would I go on about tackling on this matter? Thanks!!!
The only way it could sense that a light has been turned on is to have light sensor at the source of the light, otherwise all it could tell you is if the relay is working or not. It could not even tell you if there is a short in the wiring to the light.
After connecting 5v to relay throu the pie and latter you programmed the pie. After programming tte pie did you connect 12 v to relay when the 5v was connected. While programming. I would like to know
I got my setup in the mail. Tried to reproduce your setup. Seems to work partially. At relay 11 all red leds dim, 12 does switches but does not click and after that the board resets or the pi reboots. I have a 2amp 12v power adapter connected, possible thats not enough? (pi is also powered by the relay board.)
I went ahead and weirded everything the way you have but when I go to run the script all the relay will kick on same time they will turn off when the run time is over. I also try your other script and same thing. All the relay will power on. Any idea on what I may have done wrong.
Hey Mate!! Do you have any project, an idea to make it or even indicate a project including a simple wall light switch that can change the relay status. This way I could monitor, in real time and save into a database, the way I on or off lights and I also could show the real status on a webPage. Cheers
Great tutorial!! Very clear. I have a few questions though. I'm doing this on a pi zero so I don't know if that makes a difference. Whether I have only a few GPIO pins connected to the relay channels or all 16, when it steps through the loop to turn on the first relay, All of the relays that are wired to the Pi turn on for some reason. Also I was wondering what is the reason to have both 5v and both grounds hooked up? I tried several combinations and the only one that seemed to work as expected (partially) was when I didn't have any power or ground hooked up to the Pi. However when I try to turn on more than two relays in this configuration, the board makes a buzzing noise as if it's being underpowered. But- the relays come on one at a time as I expected them to. Any ideas?
+Eric Steed No, that's some unusual behavior. Are there shorts between your GPIOs? Are you sure you have an optocoupler relay? Are you supplying enough power to the Pi Zero (you should still use at least 1A)?
I am trying to write a script that would turn on one relay and it stays on while using ur script how would add or mod ur script to leave on one while the others are off if u could help you could give me would welcome
I am trying to write a script that would turn on one relay and it stays on while using ur script how would add or mod ur script to leave on one while the others are off if u could help you could give me would welcome
After switching from 5V to 3.3V from the raspberry pi 3 it worked!!! Thanks for the info. Now a question... is anyone having trouble with gpio 11 &16 switching relay #1 on and off? This is driving me crazy!
yes, grasshopper, after your toil in the garden of Herculean Code Edit and clean the Augean Stables of Rewire then you will eventually discover that 3.3v is correct and 5V will make you head spin for an interminable time. Only then can you pass the test and walk gently across the rice paper to brand your arms with the Rasperian logo.
Hi skiwithpete, I followed all steps with all attention, but when I tried to execute wich one code, all relay was activated. Do you know how can I solve it? Thank you and congrats for the great video.
i've tryed with my PI3B with a 12v 2.5A power adapter and pins connected to 3.3 v on the PI side and...surprise surprise, the PI turns on without his power adapter. In some way electricity from the relay board flows to the PI and keeps it running. is this ok? should i still power the PI with its adapter?
I am using a raspberry pi 3b+ and the same 16 relay module, When I try to run the first script16_1.py it lights all the relays up and turn off when its done counting to 16. If I try to run the script16_2.py it lights up all the relays until I hit CTRL C.
Having a problem, following your great video. Every script i ran turns all the relays on at once and the only way to turn them off is by exiting the script with Ctrl-X Any ideas ?
Hi, First of all thank you for the very interesting video. Then, just a newbie question. The 12V power supply you're linking is 12V and 6A. On the other hand, the 16 channel relay states "12V 16-Channel Relay interface board, and each one needs 15-20mA Driver Current". So I was wondering if this big current discrepancy (6A vs 15-20mA) wasn't a problem or if I'm missing something?
Hi Pete, Great tutorial, especially for beginners like me! I must be doing something wrong, though. I used a rp3 and python 3.5 so I added parentheses to your script. I tried to run 16_1 and 16_2 and in both of them at start all relay diodes light up and only switch off when I ctrl+C the process. Any idea what I could be doing wrong? Thanks so much, I love the way you explain things! :)
Not sure what I did wrong. I connected ground and the sixteen GPIO's to the raspberry pi, attached 12v to the relais board. The Pi was not powered, no connection between the +5V pins, still the relais pulled, the 470µF capacitor got hot, and this was the last sign of life from the relay board.
According to Sainsmart the 5v pins are powered by the connected 12v power supply (courtesy 5v power according to them). According to RPi docs the USB power supply also delivers 5v on the RPi 5v pins. Can you explain why you've connected these all together?
On the 8-channel relays there is a VCC and JD-VCC jumper connection which links pins for the 5V power to the board, to the 5V power for the optocouplers. On the 16 channel, there is no connection linking them. And when powered only 5V there is not sufficient power to run all 16 relays (as you'll find through experimentation). When running on 12V alone, the optocouplers do not trip (as you'll find through experimentation). So it is my assumption that the 12V runs the power for the relays, while the 5V is the power for the optocouplers - though I don't have any documentation to back up this finding.
@@petergosselin1180 Actually the voltage regulator on the board (LM2576) can supply up to 3A on the 5V rail, which is more than enough to drive the 16 optocouplers and other ICs on the board, and even has power left over to power a small pi (Zero W takes max 370ma). The 12V rail drives the relay coils, and when they're all on it draws a little under 500ma according to my experimentation. You cannot run this board on a 5V supply alone, as it won't drive the relay coils reliably. Furthermore connecting the 5V or 3.3V rail from the Raspberry Pi to the 5V rail on the Sainsmart board as shown in this video (with the USB power attached to the PI) is a bad idea and will likely end up killing the PI, and even if it doesn't it's bad practice. I found a really easy solution to this in the amazon reviews for this board of all places, which I posted in another comment.
==Credit to AJ in Amazon reviews for this method... it works great and gives you the ability to have led indicators for the relays external to the board. Scripts provided here will work as is== ====DO NOT CONNECT THE POWER PINS TOGETHER ON THE PI AND RELAY BOARD (Unless you are not using a USB to power the PI and want to use the 5v rail on the board to power a low power Pi-- I wouldn't do anything larger than a Zero W as other PIs draw a lot more power)==== For those that need help this is the easiest way to connect them to the Raspberry PI: The relays are triggered on when the pin of the relay is pulled LOW (0) volts. the pins are made for an Arduino but will work with the PI if you connect a 3V LED between the relay board and the PI GND pin on relay board ----------> GND pin on Raspberry PI Relay Board Pin------> LED Anode (Long Wire) / LED Cathode (Short Wire) -------> GPIO of Raspberry PI you will have to do this 16 times. This has the added benefits of; Indicator if relay is supposed to be on to mount in project box side/top (Unused just leave inside) Relays do not trigger ON when rebooting the PI Relays do not trigger ON when PI is off all parts are cheap and comparable with using resistors. How this works: When the LED is used this way it is essentially a device that drops the voltage by 3V. converting any excess power to light. The PI requires 3.3v maximum to its pins. This method reduces the 5v to 2v for the PI. (You can check with a multi-meter) When the PI GPIO is HIGH (ON) there is 3.3v at the PI and 5v at the relay board. Because the LED requires 3v to operate and there is only 1.7v the led does not conduct power and the opto-coupler in the relay board stays deactivated. When the PI GPIO is LOW (off) there is 0v at the PI and 2v at the relay board. Because the PI is forcing the pin low the LED begins to conduct, turning on, The current limiting resistors in the relay board keep the LED from conducting too much power (and burning out) and still provides enough to activate the opto-coupler causing the relay to activate.
HELP I have a problem... I have all the same things as him except when I try to run the code, instead of turning relay 1 on then relay 2, ect, all relays turn on. The code is still saying that it is turning on the relays but they are all on. They are wired the same as his i have checked many times. I need help!!
I want to make a home automation and i bought a 16 channel relay like that for switcking a few things like the gate opening and so on. Everything should be controlled by a server application which i am doing installed and hosted on a raspberry pi. Here's the question: how can I get inputs like checking if the doorway is open?
Your description links to the 12v version of the relay board. I have the exact same board and these scripts do not work. Can you confirm you have the same board as you linked to because somethings wrong on my end.
I just went and looked, and I can confirm that I have the 12V version of this board, exactly as linked, and that I'm powering with a 12V power supply and driving the relays with with the Raspberry Pi.
@@skiwithpete ok thanks for the confirmation. clearly there's an issue with my relay board or difference in raspberry pi's, maybe the rpi a has more driving current than the 3? Either way none of your scripts work for me. I mainly write all my code in javascript and it works fine with my 2 channel 5v relay boards when i have a handful of them connected. Gotta find my multimeter to debug the problem =( Figured i'd just follow someone elses known working code to rule out any issue with my software side.
super nice video, i got the same relay board but it's either damaged or there is something I cant't get right. I am using an esp32 as controller, but the relays are activated as soon as i connect the board to my esp, no matter if i set the IO high or low. Now the esp32 outputs 3.3 for high ... i suppose the PI outputs 5v. Also i have noticed on your video you are setting the I/O to LOW for the relay to actuate ? ... should it be a HIGH to actuate? Also I noticed on my board that even without the 12v (only 5 v from the esp board) the leds still light up ... the LED should be ipto-isolated from 5v (they are on the 12v circuit) ... is my board broken or there is a flaw in the design of these boards ?
@@skiwithpete Found the issue, first of all the board works at 5v so for esp you need a 3v to 5v convertor (there are logical convertors for this). The relays requires a LOW state to activate and a high state to be off. The 3.3v from esp is not enough to be considered HIGH this is why the relay see 3.3v as LOW .. you need 5v to shut them off. Hope this helps other in this situation. After this implementation the integration works perfect
+Darren Weatherall without the grounds, the 3v3 of the GPIOs wouldn't flow. The 5V is a different question. I never thought to disconnect that, might be worth a try...
+skiwithpete Thanks for the quick reply. I took another look at my relay (I have the sainsmart ssr 8 channel board), and it's a 5v board with only one power source. I followed your video and everything works great. Thanks, you've helped me get on my way to building my xmas light project.
Hi. I had my raspberry pi 2 connected to a 2 channel relay for a while and yesterday I upgraded to 16 following your tutorial. My raspberry pi shut itself off today and was much warmer than usual. I wasn't sure why so I unplugged the raspberry pi. To my surprise the still had power which made me confused. I googled and I found out its possible to power the raspberry pi through the pins. I used a volt meter to test the two 5 volt pins on the board relay board. With my raspberry pi unplugged and the Relay plugged it, it shows there's 5 volts outputted to the 2 pins. I unplugged the 3.3 volt from the raspberry pi to the board and it works fine for now. If someone else has the time, can they confirm this.
The sainsmart 16 channel relay board produces its own 5 volt through a transformer. If you hook up 3.3 volt from the Pi, you risk ruining your Pi. Some say it will work without the Pi 3.3 or 5 volt from the Pi. I believe this relay board has been modified since this video was produced.
3 years later nobody answered your question, how sad. yea you could but you would need a way to control 64 pins. think multiplexers. shift registers, etc. it is possible to control hundreds of gpio pins with only a few.
(yes this is 3 years later but 3 years ago i was not into tech) it is possible using MCP23017 chips with IC2 controlling them, you're in for a long ride if you want 16 individual relays working though its a steep learning curve but there are several tutorials on this chipset
I am disabled and have 8 switch and raspberry pi 3b+. I need it to read a capacitive moisture sensor.....if dry start water pump until sensor says “wet” then turn off small pump. Continuous moisture monitoring . 4 plants = 4 sensors and 4 pumps. I think 8 switch. Wiring. I need very long wires for sensors and pumps. PI will be in garage with switch on wall. Wires for sensors and water pumps ran outside to each plant. Can you help with detail video? And is there code written already? I can have vegetables then. I cannot care for them by myself due to disability. Please help or direct me to a source. You can leave message here. We go from there. Most Humble Appreciation! Alton
Hi skiwithpete! I have a project to start automating the lights of my house. I have this board of 16 channels, and bought a plate with network interface RJ45 style the SaintSmart. I'm just doubt with the module supply to the relay because of the 16 relays will use at least initially 14 and do not know what the correct amperage to use this module with all this capacity?
When I run the script16_1.py on a Raspberry Pi 2 all of the relays turn on simultaneously like some of the others have posted here. I have tested from one of the grounds on the relay to any of the 16 channels while the script is not running on the PI and the voltage shows about 4.6V. When the script is running the same test shows about .13V. When the script is finished looping and prints goodbye, all of the relays go off simultaneously as expected. The same thing happens when pressing CTRL + C as expected. I have checked all of the wiring multiple times, have both 5V connectors and two of the grounds from the PI to the 5V connectors and both grounds on the relay. I have not tried connecting the 3.3V connectors on the PI to the 5V connectors on the relay out of fear of frying the PI. I also tried changing HIGH to LOW and LOW to HIGH in the script with no change either. Any help would be greatly appreciated. Thanks in advance. Another observation that I made is that if I just hookup both 5V and ground connections along with just a few channels, but do not power on the PI with its 5V adapter, when I plug in the power for the relay, 5V flows back into the PI and powers it on too. Not sure if that is supposed to happen or not.
I am having something similar to this problem and removing the connection from ground to the relay did NOT fix the problem. I have tried this on both RPi 2 model B and a RPi 3 model B with the 16 channel relay that requires 12V power supply, and my issue is when I set the pin to be an output pin it goes HIGH, but then when trying to set the pin LOW the relay will not switch open. This happens no matter what I'm using i.e. python, wiringPi, or BCM2835. example from terminal (wiringPi): gpio -g mode 17 output (sets the pin to output and is instantly HIGH) gpio -g write 17 0 (pulls the pin LOW and is suppose to turn off the relay, but does not work) #even using gpio readall says the pin is set to 0, but the relay is still stuck in the closed position. example from python script: import RPi.GPIO as INOUT, time INOUT.setmode(INOUT.BCM) pin = 17 INOUT.setup(pin, INOUT.OUT) try: while True: INOUT.output(pin, INOUT.HIGH) time.sleep(0.2) INOUT.output(pin, INOUT.LOW) time.sleep(0.2) except KeyboardInterrupt: print ("Program Interrupted") INOUT.cleanup() If anyone knows what I'm doing wrong I'd love to hear back as I'm out of ideas to try.
I am thinking that he just got lucky. I have it working fine with an Arduino that puts out 5v on the gpio instead of the 3.3v on the gpio for the PI and am thinking that a transistor is needed for each gpio to increase the voltage to 5volt to trigger each relay. I would be interested to know what voltage Pete is getting from his PI gpio pins to see if perhaps his is putting out more voltage.
Got lucky? No. Try to watch my other 8channel videos. You should be able to set it up the same way then add the 12V power. The problem Ryan is facing, is likely to do with the GND power returning to the Pi.
Thanks for putting this video together. I am using a Raspberry Pi 3 b+ and copied your script and wiring to the letter. When I run the script all of the relays turn on at once, stay on and then all turn off at the end of the script. I have tried it with all the GPIO wires connected and with removing the GND GPIO wires and get the same results. Any suggestions? Thanks
I ended up disconnecting the ground wires from the PI to the controller and then connecting the 3.3 V pins on PI to the 5V pins on the relay board. Seems to be working perfectly now.
Douglas Light excellent! Glad it worked. I found this solution somewhere online and tried it. I think the problem was that the 5V in was backfeeding to the PI. Removing the ground wires and switching to the 3.3 v solved the problem for me. Glad it worked for you as well!!
This worked for me finally with a SainSmart 16-Way Level Conversion Module for Raspberry Pi. I made a template for a php menu system that has on/off menu and a status red/green light to see which one is on atm. If you are interested msg me. Very simple to install just unzip and run a sudo cp command to get the files in the right directory.
I just bought a Sainsmart 16 way Level converter after reading the comments here. Could u guide me how to connect the pins between Pi, 16-way level converter and 12v 16-Ch Relay?
Hi mate, really nice video! I almost have the same setup at home (I am waiting for my powersupply, I run with 12V 0.6A atm and a RPi B+) the problem that I struggle with is that all the 16 channels turn on at once as soon as I change the GPIO state from IN to OUT. It doesnt matter how much I change from LOW to HIGH the relays stay turned on forever. the relayboard that I have is an ebay kina version could it be that the relayboard is faulty and how can I test this out? what do you think is the problem? if anyone here have any ideas that might help that would be great.
i have also the same problem, 2 channel relay works perfectly,when i connect 16 channel, the relays stay turned on forever.i am using 12v 2 amp power-supply for relay.
any way to have some sort of graphical interface that could be renamed through the graphics? Im trying for something like this for my vehicle to control lights and have a gauge display from the OBD. Id like the lights to be dimmable and color changing, then I might incorporate GPS as well
what wire gauge did you use to connect the channel relay to the power source? For my own project I used 14 awg and was really hard to put in since it was too big
+skiwithpete I received these relay shield from amazon and tested it but something weird, when I connect the relays to the raspberry pi 3and run the program all leds automatically turn on. I'm using the same python code you use it, please any one advise what I should I do Link for the relay I have it www.amazon.com/SainSmart-101-70-103-16-Channel-Relay-Module/dp/B0057OC66U?ie=UTF8&psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s00
Just fried my Pi. dont ever connect the 5V on the relay board to your Pi. I now use the 5V and GND pin on the relay board to power my arduino, which is receiving serial commands from another Pi I have laying around. The downside is you gotta code twice - use AI to generate that 😅 It was my own fault, I should've tested the power pins on the relay board.
Sorry, disregard, I figured it out, , now can you tell me how to run all the scripts one after another or how do I make one script out of all of tuem? Thanks,Milton
Is there something like this with a silent alternative. I'm noticing in the video they each make a click when turning on. My goal is to add lighting to a Lego city i am making and would like to have software turn on and off lights at random intervals. I would prefer there isn't a constant clicking sound being emitting from under the table.
I received these relay shield from amazon and tested it but something weird, when I connect the relays to the raspberry pi 3and run the program all leds and relays automatically turn on. I'm using the same python code you use it, please any one advise what I should I do???
if you're using relays with external power to trigger the relays you should be fine since the 5v is simply there to trigger the optocoupler to send the external power to energize the relay
Thanks for the Video. I have the question.I want to turn ON and Turn OFF in 24 Hours (Means scheduler for every day for 30 days). I need some help with the code. I want to include the Time stamp and also which relay are Turn ON.
Thanks for the answer. I check the code and it is working for me. I got the following code. it is working fine for me. github.com/skiwithpete/relaypi/blob/master/16port/script16_5.py But i also want to include the time stamps every hour and also the pin numbers which were active? What i have to include in the code.
Hi I want to that but with a NFC controller my idea is when I leave to the home 🏡 put the card #1in the NFC and the home loss all the energy. And close the door and.. when arrived to the home open the door with other card #2 and put the card #1 in the NFC and the home have energy again and when put the card #3.. six lights in the home turn on ,,, so you know how to do a remote control for the smartphone
Pete - thanks for this comprehensive guide - it's really been helpful. Having said that and having wired everything up as you said, I too have suffered some of the same issues that others have been reporting here and I believe I have found a work-around that requires no additional components and is very straightforward. I'm using a RPi 3, GrovePi sensor board and a 16 channel relay board very similar to yours except mine is a 5V input rather than 12V. What I eventually established is that you only need one 3V3 connection from the RPi to the relay 5V pin. Leave the other 5V pin unconnected. Then only connect 1 ground wire from the RPi to the GND pin on the relay board - making sure you connect the GND on the same row as the 5V pin you have connected to the RPi. So instead of having 20 wires connecting the RPi to the relay board I only have 18. I have had no problems whatsoever since doing this and all of your scripts have worked as they should. Hope this helps everyone else.
Tried that, it blew my Pi unfortunately :(
Spent an hour researching why the relays would turn on, but not turn off. Then I saw Eric Steed's post below. Changing the VCC connection from Pin 2 (5V) to Pin 1 (3.3v) and everything worked as expected.
OMFG! I wish I would have read this earlier. Spent most of the day thinking I missed a step!
Connecting the 5v pins on the relay to the 3.3 v pins on the pi fixed the problem of them all turning on at once thanks!
Hi. Wonderful job! Many thanks for that huge work.
I was searching for "how to connect a SainSmart 16 channel board in the most simpliest way" and I founded it! Thanks!
In my project, I want to use the 16 channels board directly on a RspiB mounted with Domoticz and an Arduino in USB mounted with "MySensors" and several sensors in a hydroponic project 100% automatized.
You helped me to leave the first stone. Respect to all people sharings skills and passions over Internet.
Following you now.
I have hooked up my 16 port relay and Raspberry 3 per your video. The problem is when the script runs, the relays lock on and won't go off. Not really sure what is going on? Can you help?
Thanks
I have the same relay switch except that it runs on 5v instead of 12v (I'm powering it from a 5v 2A dc adapter). Your scripts worked like a charm. Thanks man :-)
When I get my man cave built, thinking of creating a smart garden with lights and auto plant watering. Thanks for the videos, really clear and understandable.
Is it a real cave or just a basement?
Thank you for replying , I' ll try to post a video, I have a 4 channel relay running some of your scripts, I have connected 1 LED light strip on each relay, running your script2 I thought the lights would turn on/off in the order the relay is switching (wave like), instead all the 4 led strips light up at the same time, what I wanted to accomplish was to have a sequence in the order the relay is switching like a light show, I know I may be confusing you with this question, so will try to post a video as soon as I can , i ordered all the same parts listed on your 4 channel relay video. Thank you so much!
Check your wiring, some wires may be out of sequence?
Great video, i too can't get it to work how you have it shown. Some of the comments have had people connect the 5V rail on the relay to the 3.3v on the PI. While this appears to work, several people said it fried the PI. I think I will have to just use two 8 channel relays for what I want to control. I wasn't too happy about needed a 12v external power source anyway.
Check the amperage of the 5+v on the board, if it is higher than what your pi requires it will fry your pi, if it it is too much under the amperage then your pi will not work.
I know this video is 5 years old but I wanted to put it out there that I have a raspberry pi 4 B and I was getting all relays on at the same time when GND and 5V were supplied to both or just one. I switched that to a single row of GND and 3V3. I also had to not use GPIO4 and GPIO22, not sure why but they were supplying power in LOW and HIGH states. I changes the code for GPIO4 and 22 to GPIO23 and GPIO24 and that solved my power leak issue.
Summary: use 3V3(only one row) and if any voltage leak change GPIO to another one.
I figured out what my problem was. I was using the 5 V connection from my pi zero to the board. When I switched it over to 3.3 V, everything worked like a chanp. I'm using the same exact really is you, the same smart 16 channel really with Opto couplers.
thanks for the tip! helped in my case as well!
Thanks man.............You Saved me..............!...........Such a Big Help .......(y)
rasp 2b worked for me 2 ! thanks
The problems that various people describe here that all the relays immediately turn on all together isquite explainable when you know the anatomy of this board: It isnt really made for 3v3.
The input consists of an optocoupler that has its anode tied to +5Volt via a 1k resistor.
The GPIO of the Raspberry then connects to the cathode of the optocoupler.
On the secundary side of the optocoupler the collector is tied to 5Volt and the emitter is pulled to earth via a 10k resistor. The emitter then drives an ULN2803 which is an open collector, so it has the relay between the output and the 12 Volt.
So here is what happens with the signal:
Raspberry LOW -> optocoupler +serieresistor get 3V3 ->optocoupler opens ->emitter goes HIGH -> INPUT ULN2803 goes HIGH ->OUTPUT ULN2803 goes LOW -> Relay activated.
So, as you can see from this, and which is clear from the script, you need a LOW to activate the relays and a HIGH to deactivate the relays.
Now that is where the problem is. The 3V3 RASPI has no problems creating a LOW to activate the relay, but what happens if you send a HIGH.
For arguments sake lets say that a HIGH on the raspi is 3Volt. That means that the optocoupler + serieresistor will still see 2 Volt.Not much, but it might be enough to open up the optocoupler, which will activate the relay, just as a LOW signal did.
So why did not everybody have that problem, why did it work for Pete and not for others? Simply because of variation in components.
So, what to do? Well, the easiest is to add 16 transistor leveladapters that have their collectors connected to the input of the board. added bonus is that they also invert the signal so you get an active HIGH contraption
another solution is to bypass the LM2576 and feed the primary optocoupler with 3V3.
Though adding the 16 resistors is a good solution, it is kinda ironic that those 16 resistors by itself already are capable of driving 16 relays
Do you have a model/part number that would be good for testing?
@@matthewdornfeld2126 it is about the one in the link in the discription. Further discussed here: arduinodiy.wordpress.com/2018/09/04/the-16-relay-module-and-the-raspberry-pi-not-an-ideal-marriage/
Thanks for the video (16 channel Relay Raspi)really useful. Got it all working with a Pi Zero. I noticed that the 5v back feeds from the relay board and powers the Zero, so I am wondering if 5v really needed by the relay board as it appears to provide this via the 12v connection.
Going to use this to provide an automated control for my wifes doll house light with a LDR and PIR so lights will change when PIR triggers.
Got a bit of programming to first!
In order for the relay board to work for a Raspberry Pi 4 you must ensure the inputs are active HIGH. Most boards out there are active or trigger LOW. If you have a active LOW board you will need to place a Darlington sink drive ahead of the relay board inputs. Use something like a ULN2803. You will need two of them, cost about $1.25 each.
Hi Sir pete I found your Channel it's so great,I hope I can learn your program and how use the raspberry board.God bless. I am also a new subscribers of yours . Thanks
Hey @skiwithpete, great video and great focus on the camera, thanks.
One question please, as i have a similar module and struggling to figure out what's wrong.
If you connect the 12v power to the module and then the 5v+GND from the module to the 5v_GND of the rPi, does it power the rPi on?
I connected the 12v power to the module, used a multimeter on the 5v and gnd pins and it gives me 5v. Is that normal?
Could you check on yours?
Check the amperage on the 5+v, it should be somewhere between 1.5+ amps to 3.0 amps to power the rpi. Connect the positive of you amp meter to positive post on the board and negative to negative post on the board. Depending on which pi you are using (check what voltage and amperage is required for that pi), you ought to be able to power your pi from that board.
I retrofited an old washing machine with this board. It came with a broken mechanical programmer. The only issue was when runing the motor at full speed the relay burned after a few uses because it was arcing (the motor turns into a generator when speeding down). I needed to add an anti arcing circuit to avoid that so it was not a big issue since I had a few spare relays to use.
This video is incredible! Thank you for all your precision and detail!!
thanks for your comment, please share and spread!
I like how they used optocouplers on-board it makes it less worrisome about buffering the GPIO's. I did unfortunately have a death in my Raspberry Pi family. This is the cost of not checking your GPIO wiring.
Alright, I have no idea what I'm doing and I've been at it for the last 3 hours. When I run the first program you have all the relays turn on but when it runs through each one individually nothing happens. I've done some testing out found if I set the pin on the board to output the relay activates but when set to input the relay deactivates. I can't control the relay by setting the pin high or low just by changing the mode of the pin to in vs out. Why is it doing this? and how can I fix it?
I know your comment is already three years old, but did you fix this issue? And if yes... how?
Lukas Weishaupt this is the issue I’m working on now let me know if you have a solution
@@turke6756 same issue here
Okay I got it to work with the raspberry pi. My particular relay board and probably yours too works on 5v logic and the pi is 3.3v logic. All you need is a logic level converter can be bought for dirt cheap. (Relays requires the 5v to signal off position so you can turn it on but not off)
Tim Neeley I think I figured it out check my comment below
im having some issues, with just the connections.
I'm using a RPI 4 with a 16channel 5V relay board. what I'm having trouble with is that when i do a GPIO.setup all the relays with be switch on and i am unable to switch it off or control it, unless i do a cleanup.
send help
This video series is great. My question is. How can you turn on more than one relay at a time? Then turn them off at different times? That way they're not so patterned. They could be more random, or sync to music? Thanks for any help that you can provide.
I am planning out a project and I think this video is going to be pretty useful. Thank you so much for making it. My plan is to power some 12v 2amp devices, only, one at a time. My question. If the board uses 12v, what power supply would I need to power: the pi, relay board, and 1 relay output 12v 2 amp? Or do I need to split a separate 12v 2amp power supply into 12 outputs and wire each relay separately? (p.s. just starting out, sorry if its a noob question.)
The pi and the relay need separate power since it operates on 5V. There is a way to step down - but I don't do it. The question you asked though is can 12V power the relay, and power something on the other side too? Yeah, it can. Take a look at my "outdoor light setup" video, you'll see how I split the power.
Hi skiwithpete, I'm trying to connect the relay to control my home light.
I use the relay to turn off/on the light from my Pi with no problems.
But how can get the input from the physical switch light buttons and update the status of relay in Pi?
In addition, what is the best way to add more gpio to Pi for example, I need to control 32 relays (outputs) , which means I need 60 gpios ( input + output) , Can I use a chip like this - mcp23017 ?
Anan My thoughts exactly!
It will make the wiring, easy enough here, even more easier.
What do we rate I2C or SPI? SPI Bus has great range and extendability in space.
uk.farnell.com/microchip/mcp23017-e-sp/ic-io-expander-16bit-i2c-28dip/dp/1332088?CAWELAID=120173390001317605&CMP=KNC-GUK-GEN-KWL&mckv=PpFlXUmR_dc|pcrid|186409721995|&gclid=Cj0KCQiA8_PfBRC3ARIsAOzJ2up7DjZxOCZL_Cen37JrHBbdhxoFt6XbTe6iTy3dBNfTw0NxUHGfOmAaAjgKEALw_wcB
Greetings all
I have the Sainsmart 16 channel board. I have watched the video which is very good. I have hooked my pi up the same way. But I can't seem to get it working right. When I power the pi and run the script, some of the relays come on and stay on. I have loaded your script and it still does the same thing. I wish someone could come up with the answer. I have read the comments from other folks and not really seeing the right answer to get it working. I have a 12V 3 A power supply hooked to the relay board. I have disconnected the ground wires and tried it. Still not working. I have disconnected the 5v wires and even moved them over to the 3 V side. Still not working right. I do see that your running the raspberry pi 2. Could that be the whole problem? I have seen that a few folks have got it running with the raspberry pi 3. I could use some help. Thanks everyone.
Learn a lot from this video. I do have one question. If I was going to wire in some water pumps to this relay. Does the positive wire from my pump go into the center of the relay? The ground for my pump does it go into the relay or should it go back to the power supply?
Yeah this only interrupts one wire in the circuit. Positive or neutral it doesn't really matter. But in your example, yes interrupt the positive and the neutral goes straight back to power.
But I can ground back to relay also right?
@@dennischang5296 No, it's like a light switch. You only interupt one side of the circuit. Both sides don't terminate back.
For christmas lights you wouldn't want all that clicking, you'd use a MOSFET OR SSR (solid state relay)... They use less power, are silent in operation of and can switch at significantly faster rates. Plus a bank if them would take up significantly less space...
I have a trouble when I turn off the relay.
The code I used is the same as you but I debugged it, when it run to "GPIO.setup([PIN_NUMBER], GPIO.OUT]", the relay of this PIN_NUMBER is turned on.
Can anybody help me for it?
THANKS
turning off that pin, will turn it off. You will find that in the code as well.
good project, but its good to stick to color codes especially on the power side
good teacher and this good video for whom need detail instruction ... keep educate
I followed your video that I must say was very easy to follow. Only thing I am not sure on is the power from the pins on the pi to the relay board. The relay board says it's an output of power not a in put. Does it do both or am I reading wrong.
I'm running 12 v 1 amp power to the relay board and the 5v pin is powering my pi with no transformer. Please help me understand a little better
Your python programming is absolutely wonderful. I learned so much. Thank you. In the first script, I learned how you designated the pins as output pins using a "for" loop. I wonder why you couldn't do the same thing for the long section where you used "try:" I'm a beginner with python and was just wondering.
John Layman just wanted to show different ways.
Nice intro to this 16channel board. One thing I question is why you would set the GPIOs to outputs before setting their state to high. Is this just a limitation of the RPi.GPIO library i.e. it won't let you set the state before it is set to an output? I've not done any gpio work with the RPI yet but I've always set the state first then enable the output that way there is no quick spike on the output.
I don't remember why I did this. I think it's because I had two types of relay. One that started high one that started low, so this set them all to same state... But I'm not 100%
Hi, love your video, Im totally new at this, I have set this up and have a question, I connected led lights to it, but all the lights turn n at the same time, is that whats supposed to happen or should they light up in a sequence, thanks,
impossible to tell what you're asking - can you take a video and post it here?
Test your relay board, it may be defective?
This was very informing. keep it up, these are great!
I notice when the GPIO is set to "output" doesn't matter if it's true/high or false/low, there is some voltage coming out of that GPIO pin. Very low .179volts, this is why I think the relay stays on, and doesn't turn off for me.
Exacly what i'm searching for, thank you very much!
thank you so much you make the best pi projects always work thank you so much
thanks.
Those are NOT 5V input pins on the relay board. This is the second video I have seen where this is stated. Those are 5V OUTPUT pins used for things like Arduino if the user wanted to piggy back their Arduino off the back of the relay board. There is even a chip that regulates that 5V output supply from the 12V supply you add under those screw sockets. I dunno if the Pi has separate 5V input pins though. The Arduino does. It is a poorish design placing those 5V and GND pins alongside the low level inputs. It is confusing. Those 5V and GND pins should be separated elsewhere on the board.
Hi great vid! How would I go on about if I wanted an input from the relay to the board?
Case scenario being -- when a light in a room has been switched on, I'd like the relay to send a signal to the board that the light has been switched on? -- Would this be possible? How would I go on about tackling on this matter?
Thanks!!!
The only way it could sense that a light has been turned on is to have light sensor at the source of the light, otherwise all it could tell you is if the relay is working or not. It could not even tell you if there is a short in the wiring to the light.
After connecting 5v to relay throu the pie and latter you programmed the pie. After programming tte pie did you connect 12 v to relay when the 5v was connected. While programming. I would like to know
Any tutorials on what to do with the relay afterwards ?
I got my setup in the mail. Tried to reproduce your setup. Seems to work partially. At relay 11 all red leds dim, 12 does switches but does not click and after that the board resets or the pi reboots.
I have a 2amp 12v power adapter connected, possible thats not enough? (pi is also powered by the relay board.)
I went ahead and weirded everything the way you have but when I go to run the script all the relay will kick on same time they will turn off when the run time is over. I also try your other script and same thing. All the relay will power on. Any idea on what I may have done wrong.
so are those inputs on the board pulled up to 5v?
Hey Mate!! Do you have any project, an idea to make it or even indicate a project including a simple wall light switch that can change the relay status. This way I could monitor, in real time and save into a database, the way I on or off lights and I also could show the real status on a webPage. Cheers
Great tutorial!! Very clear. I have a few questions though. I'm doing this on a pi zero so I don't know if that makes a difference. Whether I have only a few GPIO pins connected to the relay channels or all 16, when it steps through the loop to turn on the first relay, All of the relays that are wired to the Pi turn on for some reason. Also I was wondering what is the reason to have both 5v and both grounds hooked up? I tried several combinations and the only one that seemed to work as expected (partially) was when I didn't have any power or ground hooked up to the Pi. However when I try to turn on more than two relays in this configuration, the board makes a buzzing noise as if it's being underpowered. But- the relays come on one at a time as I expected them to. Any ideas?
+Eric Steed No, that's some unusual behavior. Are there shorts between your GPIOs? Are you sure you have an optocoupler relay? Are you supplying enough power to the Pi Zero (you should still use at least 1A)?
Is the common wire connected only to the outlets and the relay, also how did you ground the outlets?
Great project. Useful videos for beginners. Can you explain how safely i work with 110 volts?
Take some electrician courses. They're typically offered at local community colleges and you can do the basics in just a couple of hours.
Thank you. I have other question: it´s necessary to use a resistor in each relay?
I am trying to write a script that would turn on one relay and it stays on while using ur script how would add or mod ur script to leave on one while the others are off if u could help you could give me would welcome
I am trying to write a script that would turn on one relay and it stays on while using ur script how would add or mod ur script to leave on one while the others are off if u could help you could give me would welcome
After switching from 5V to 3.3V from the raspberry pi 3 it worked!!! Thanks for the info. Now a question... is anyone having trouble with gpio 11 &16 switching relay #1 on and off? This is driving me crazy!
I tried using the 3.3v and it destroyed my Pi :(
You can be a good teacher 👨🏫
yes, grasshopper, after your toil in the garden of Herculean Code Edit and clean the Augean Stables of Rewire then you will eventually discover that 3.3v is correct and 5V will make you head spin for an interminable time. Only then can you pass the test and walk gently across the rice paper to brand your arms with the Rasperian logo.
When I plug my relay all the channels light up, even with out our attached. Can someone help?
Hi skiwithpete, I followed all steps with all attention, but when I tried to execute wich one code, all relay was activated.
Do you know how can I solve it?
Thank you and congrats for the great video.
Thiago Fabri this is likely caused by a non-optocoupler relay.
thank you
i learnt very much from u r videos
i've tryed with my PI3B with a 12v 2.5A power adapter and pins connected to 3.3 v on the PI side and...surprise surprise, the PI turns on without his power adapter.
In some way electricity from the relay board flows to the PI and keeps it running.
is this ok? should i still power the PI with its adapter?
I am using a raspberry pi 3b+ and the same 16 relay module, When I try to run the first script16_1.py it lights all the relays up and turn off when its done counting to 16. If I try to run the script16_2.py it lights up all the relays until I hit CTRL C.
Having a problem, following your great video. Every script i ran turns all the relays on at once and the only way to turn them off is by exiting the script with Ctrl-X Any ideas ?
BTW I am using a raspberry pi 3
Also, my 12V supply is 2A is that a problem ?
I am having this same issue. Did you find a solution?
same for me :(
raspberry pi 3
I figured out a solution to this issue. Connect the 5v Constant pins on the Relay to the 3.3v pins on the Raspberry Pi.
Hi, First of all thank you for the very interesting video. Then, just a newbie question. The 12V power supply you're linking is 12V and 6A. On the other hand, the 16 channel relay states "12V 16-Channel Relay interface board, and each one needs 15-20mA Driver Current". So I was wondering if this big current discrepancy (6A vs 15-20mA) wasn't a problem or if I'm missing something?
I couldn't find a cheaper power supply that offered less.
SSH. Look it up, it will help you connect.
Hi Pete,
Great tutorial, especially for beginners like me! I must be doing something wrong, though. I used a rp3 and python 3.5 so I added parentheses to your script. I tried to run 16_1 and 16_2 and in both of them at start all relay diodes light up and only switch off when I ctrl+C the process. Any idea what I could be doing wrong? Thanks so much, I love the way you explain things! :)
They're activating on the low setting
Awesome thanks for the very helpful video
Not sure what I did wrong. I connected ground and the sixteen GPIO's to the raspberry pi, attached 12v to the relais board. The Pi was not powered, no connection between the +5V pins, still the relais pulled, the 470µF capacitor got hot, and this was the last sign of life from the relay board.
According to Sainsmart the 5v pins are powered by the connected 12v power supply (courtesy 5v power according to them). According to RPi docs the USB power supply also delivers 5v on the RPi 5v pins. Can you explain why you've connected these all together?
On the 8-channel relays there is a VCC and JD-VCC jumper connection which links pins for the 5V power to the board, to the 5V power for the optocouplers. On the 16 channel, there is no connection linking them. And when powered only 5V there is not sufficient power to run all 16 relays (as you'll find through experimentation). When running on 12V alone, the optocouplers do not trip (as you'll find through experimentation). So it is my assumption that the 12V runs the power for the relays, while the 5V is the power for the optocouplers - though I don't have any documentation to back up this finding.
@@petergosselin1180 Actually the voltage regulator on the board (LM2576) can supply up to 3A on the 5V rail, which is more than enough to drive the 16 optocouplers and other ICs on the board, and even has power left over to power a small pi (Zero W takes max 370ma). The 12V rail drives the relay coils, and when they're all on it draws a little under 500ma according to my experimentation. You cannot run this board on a 5V supply alone, as it won't drive the relay coils reliably. Furthermore connecting the 5V or 3.3V rail from the Raspberry Pi to the 5V rail on the Sainsmart board as shown in this video (with the USB power attached to the PI) is a bad idea and will likely end up killing the PI, and even if it doesn't it's bad practice. I found a really easy solution to this in the amazon reviews for this board of all places, which I posted in another comment.
==Credit to AJ in Amazon reviews for this method... it works great and gives you the ability to have led indicators for the relays external to the board. Scripts provided here will work as is==
====DO NOT CONNECT THE POWER PINS TOGETHER ON THE PI AND RELAY BOARD (Unless you are not using a USB to power the PI and want to use the 5v rail on the board to power a low power Pi-- I wouldn't do anything larger than a Zero W as other PIs draw a lot more power)====
For those that need help this is the easiest way to connect them to the Raspberry PI:
The relays are triggered on when the pin of the relay is pulled LOW (0) volts. the pins are made for an Arduino but will work with the PI if you connect a 3V LED between the relay board and the PI
GND pin on relay board ----------> GND pin on Raspberry PI
Relay Board Pin------> LED Anode (Long Wire) / LED Cathode (Short Wire) -------> GPIO of Raspberry PI
you will have to do this 16 times.
This has the added benefits of;
Indicator if relay is supposed to be on to mount in project box side/top (Unused just leave inside)
Relays do not trigger ON when rebooting the PI
Relays do not trigger ON when PI is off
all parts are cheap and comparable with using resistors.
How this works:
When the LED is used this way it is essentially a device that drops the voltage by 3V. converting any excess power to light. The PI requires 3.3v maximum to its pins. This method reduces the 5v to 2v for the PI. (You can check with a multi-meter)
When the PI GPIO is HIGH (ON) there is 3.3v at the PI and 5v at the relay board. Because the LED requires 3v to operate and there is only 1.7v the led does not conduct power and the opto-coupler in the relay board stays deactivated.
When the PI GPIO is LOW (off) there is 0v at the PI and 2v at the relay board. Because the PI is forcing the pin low the LED begins to conduct, turning on, The current limiting resistors in the relay board keep the LED from conducting too much power (and burning out) and still provides enough to activate the opto-coupler causing the relay to activate.
Why did you need to plug in the 5v if you are taking 12v from the power supply?
HELP
I have a problem...
I have all the same things as him except when I try to run the code, instead of turning relay 1 on then relay 2, ect, all relays turn on. The code is still saying that it is turning on the relays but they are all on. They are wired the same as his i have checked many times. I need help!!
i have same issue. any solution?
I want to make a home automation and i bought a 16 channel relay like that for switcking a few things like the gate opening and so on. Everything should be controlled by a server application which i am doing installed and hosted on a raspberry pi. Here's the question: how can I get inputs like checking if the doorway is open?
+Balgruuf The Greater I'd use this: amzn.to/1Jrihjt and poll it for status every 2 seconds or something.
Thanks
Please add a video on how to control a DC motor using Raspberry Pi
Have you done anything with mqtt with any of your relays?
Your description links to the 12v version of the relay board. I have the exact same board and these scripts do not work. Can you confirm you have the same board as you linked to because somethings wrong on my end.
I just went and looked, and I can confirm that I have the 12V version of this board, exactly as linked, and that I'm powering with a 12V power supply and driving the relays with with the Raspberry Pi.
@@skiwithpete ok thanks for the confirmation. clearly there's an issue with my relay board or difference in raspberry pi's, maybe the rpi a has more driving current than the 3? Either way none of your scripts work for me. I mainly write all my code in javascript and it works fine with my 2 channel 5v relay boards when i have a handful of them connected. Gotta find my multimeter to debug the problem =( Figured i'd just follow someone elses known working code to rule out any issue with my software side.
super nice video, i got the same relay board but it's either damaged or there is something I cant't get right. I am using an esp32 as controller, but the relays are activated as soon as i connect the board to my esp, no matter if i set the IO high or low. Now the esp32 outputs 3.3 for high ... i suppose the PI outputs 5v. Also i have noticed on your video you are setting the I/O to LOW for the relay to actuate ? ... should it be a HIGH to actuate? Also I noticed on my board that even without the 12v (only 5 v from the esp board) the leds still light up ... the LED should be ipto-isolated from 5v (they are on the 12v circuit) ... is my board broken or there is a flaw in the design of these boards ?
I just had someone else say the same thing on another video. Take a look to see if you can find a recent comment here that mentions the same
@@skiwithpete Found the issue, first of all the board works at 5v so for esp you need a 3v to 5v convertor (there are logical convertors for this). The relays requires a LOW state to activate and a high state to be off. The 3.3v from esp is not enough to be considered HIGH this is why the relay see 3.3v as LOW .. you need 5v to shut them off. Hope this helps other in this situation. After this implementation the integration works perfect
I get that the relay board needs 12v on it's own, but why did you connect the 5v wires and grounds from the pi?
+Darren Weatherall without the grounds, the 3v3 of the GPIOs wouldn't flow. The 5V is a different question. I never thought to disconnect that, might be worth a try...
+skiwithpete Thanks for the quick reply. I took another look at my relay (I have the sainsmart ssr 8 channel board), and it's a 5v board with only one power source. I followed your video and everything works great. Thanks, you've helped me get on my way to building my xmas light project.
Hi. I had my raspberry pi 2 connected to a 2 channel relay for a while and yesterday I upgraded to 16 following your tutorial. My raspberry pi shut itself off today and was much warmer than usual. I wasn't sure why so I unplugged the raspberry pi. To my surprise the still had power which made me confused. I googled and I found out its possible to power the raspberry pi through the pins.
I used a volt meter to test the two 5 volt pins on the board relay board. With my raspberry pi unplugged and the Relay plugged it, it shows there's 5 volts outputted to the 2 pins.
I unplugged the 3.3 volt from the raspberry pi to the board and it works fine for now.
If someone else has the time, can they confirm this.
The sainsmart 16 channel relay board produces its own 5 volt through a transformer. If you hook up 3.3 volt from the Pi, you risk ruining your Pi. Some say it will work without the Pi 3.3 or 5 volt from the Pi. I believe this relay board has been modified since this video was produced.
This may have happened to me. Pi no longer boots and shows a red LED after switching to the 3.3 pins. Maybe a good warning for others
Do you know if I can use a computer power supply (12v cable) to give energy to the relays
Love the videos, keep up the great work man :)
+Angealies Thanks. Really happy with this one. My most complete relay video yet!
Great video!! If I wanted to connect (4) 16 channel SainSmart relays, could a single raspberry pi run all four relays? Thank you!
3 years later nobody answered your question, how sad. yea you could but you would need a way to control 64 pins. think multiplexers. shift registers, etc. it is possible to control hundreds of gpio pins with only a few.
(yes this is 3 years later but 3 years ago i was not into tech) it is possible using MCP23017 chips with IC2 controlling them, you're in for a long ride if you want 16 individual relays working though its a steep learning curve but there are several tutorials on this chipset
Awesome- really clear and complete, thank you
I am disabled and have 8 switch and raspberry pi 3b+. I need it to read a capacitive moisture sensor.....if dry start water pump until sensor says “wet” then turn off small pump. Continuous moisture monitoring . 4 plants = 4 sensors and 4 pumps. I think 8 switch. Wiring. I need very long wires for sensors and pumps. PI will be in garage with switch on wall. Wires for sensors and water pumps ran outside to each plant. Can you help with detail video? And is there code written already?
I can have vegetables then. I cannot care for them by myself due to disability.
Please help or direct me to a source. You can leave message here. We go from there.
Most Humble Appreciation! Alton
I´m curios. Why 12V supply if the realy partnumber says 5vdc? is there a regulator on this board
Can the raspberry take inputs and translate them into a specific sequence of outputs?
Hi skiwithpete! I have a project to start automating the lights of my house. I have this board of 16 channels, and bought a plate with network interface RJ45 style the SaintSmart. I'm just doubt with the module supply to the relay because of the 16 relays will use at least initially 14 and do not know what the correct amperage to use this module with all this capacity?
do not play with mains electricity. wiring lights is dangerous! and must be left to professionals!
Exactly. Was I who made all the electrical network from my home.
Thank you so much for your video. very help helpful.
When I run the script16_1.py on a Raspberry Pi 2 all of the relays turn on simultaneously like some of the others have posted here. I have tested from one of the grounds on the relay to any of the 16 channels while the script is not running on the PI and the voltage shows about 4.6V. When the script is running the same test shows about .13V. When the script is finished looping and prints goodbye, all of the relays go off simultaneously as expected. The same thing happens when pressing CTRL + C as expected. I have checked all of the wiring multiple times, have both 5V connectors and two of the grounds from the PI to the 5V connectors and both grounds on the relay. I have not tried connecting the 3.3V connectors on the PI to the 5V connectors on the relay out of fear of frying the PI. I also tried changing HIGH to LOW and LOW to HIGH in the script with no change either. Any help would be greatly appreciated. Thanks in advance.
Another observation that I made is that if I just hookup both 5V and ground connections along with just a few channels, but do not power on the PI with its 5V adapter, when I plug in the power for the relay, 5V flows back into the PI and powers it on too. Not sure if that is supposed to happen or not.
I am having the exact same problem as you, have you found a solution?
I found a solution. Remove the connection from ground to the relay. this will fix the problem.
I am having something similar to this problem and removing the connection from ground to the relay did NOT fix the problem. I have tried this on both RPi 2 model B and a RPi 3 model B with the 16 channel relay that requires 12V power supply, and my issue is when I set the pin to be an output pin it goes HIGH, but then when trying to set the pin LOW the relay will not switch open. This happens no matter what I'm using i.e. python, wiringPi, or BCM2835.
example from terminal (wiringPi):
gpio -g mode 17 output (sets the pin to output and is instantly HIGH)
gpio -g write 17 0 (pulls the pin LOW and is suppose to turn off the relay, but does not work)
#even using gpio readall says the pin is set to 0, but the relay is still stuck in the closed position.
example from python script:
import RPi.GPIO as INOUT, time
INOUT.setmode(INOUT.BCM)
pin = 17
INOUT.setup(pin, INOUT.OUT)
try:
while True:
INOUT.output(pin, INOUT.HIGH)
time.sleep(0.2)
INOUT.output(pin, INOUT.LOW)
time.sleep(0.2)
except KeyboardInterrupt:
print ("Program Interrupted")
INOUT.cleanup()
If anyone knows what I'm doing wrong I'd love to hear back as I'm out of ideas to try.
I am thinking that he just got lucky. I have it working fine with an Arduino that puts out 5v on the gpio instead of the 3.3v on the gpio for the PI and am thinking that a transistor is needed for each gpio to increase the voltage to 5volt to trigger each relay. I would be interested to know what voltage Pete is getting from his PI gpio pins to see if perhaps his is putting out more voltage.
Got lucky? No. Try to watch my other 8channel videos. You should be able to set it up the same way then add the 12V power. The problem Ryan is facing, is likely to do with the GND power returning to the Pi.
Could i wire up 2 16-channel relays to the Pi's 40 pins?
Thanks for putting this video together. I am using a Raspberry Pi 3 b+ and copied your script and wiring to the letter. When I run the script all of the relays turn on at once, stay on and then all turn off at the end of the script. I have tried it with all the GPIO wires connected and with removing the GND GPIO wires and get the same results. Any suggestions?
Thanks
Howard I have the same problem and the same setup as you. Did you ever get it resolved?
I ended up disconnecting the ground wires from the PI to the controller and then connecting the 3.3 V pins on PI to the 5V pins on the relay board. Seems to be working perfectly now.
Thanks. will give it a try.
Well Mr. Pinsky. It works!!! Thank You Sir...
Douglas Light excellent! Glad it worked. I found this solution somewhere online and tried it. I think the problem was that the 5V in was backfeeding to the PI. Removing the ground wires and switching to the 3.3 v solved the problem for me. Glad it worked for you as well!!
This worked for me finally with a SainSmart 16-Way Level Conversion Module for Raspberry Pi.
I made a template for a php menu system that has on/off menu and a status red/green light to see which one is on atm.
If you are interested msg me. Very simple to install just unzip and run a sudo cp command to get the files in the right directory.
I just bought a Sainsmart 16 way Level converter after reading the comments here. Could u guide me how to connect the pins between Pi, 16-way level converter and 12v 16-Ch Relay?
Hi mate,
really nice video!
I almost have the same setup at home (I am waiting for my powersupply, I run with 12V 0.6A atm and a RPi B+)
the problem that I struggle with is that all the 16 channels turn on at once as soon as I change the GPIO state from IN to OUT.
It doesnt matter how much I change from LOW to HIGH the relays stay turned on forever.
the relayboard that I have is an ebay kina version could it be that the relayboard is faulty and how can I test this out? what do you think is the problem? if anyone here have any ideas that might help that would be great.
i have also the same problem, 2 channel relay works perfectly,when i connect 16 channel, the relays stay turned on forever.i am using 12v 2 amp power-supply for relay.
any way to have some sort of graphical interface that could be renamed through the graphics? Im trying for something like this for my vehicle to control lights and have a gauge display from the OBD. Id like the lights to be dimmable and color changing, then I might incorporate GPS as well
+forklift385 I'd use HTML/PHP because I'm most familiar with that as a language, but I'm sure you could just use Python if you wanted.
hi.. it possible to add 8 channel relay again to single raspi board?
what wire gauge did you use to connect the channel relay to the power source? For my own project I used 14 awg and was really hard to put in since it was too big
+ProDesignHd I'm using just 24AWG for the 12V.
thanks for specifying :)
+skiwithpete
I received these relay shield from amazon and tested it but something
weird, when I connect the relays to the raspberry pi 3and run the program all leds automatically turn on. I'm using the
same python code you use it, please any one advise what I should I do
Link for the relay I have it
www.amazon.com/SainSmart-101-70-103-16-Channel-Relay-Module/dp/B0057OC66U?ie=UTF8&psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s00
Just fried my Pi. dont ever connect the 5V on the relay board to your Pi.
I now use the 5V and GND pin on the relay board to power my arduino, which is receiving serial commands from another Pi I have laying around. The downside is you gotta code twice - use AI to generate that 😅
It was my own fault, I should've tested the power pins on the relay board.
I learned a lot from you.
you are awesome :)
+asim mohammed Thanks, that's very kind. Let me know if you get up to any of the projects on my channel.
Sorry, disregard, I figured it out, , now can you tell me how to run all the scripts one after another or how do I make one script out of all of tuem?
Thanks,Milton
:) Don't want you to rely on me. You can do it!
Lol. I'm trying. Thanks
Is there something like this with a silent alternative. I'm noticing in the video they each make a click when turning on. My goal is to add lighting to a Lego city i am making and would like to have software turn on and off lights at random intervals. I would prefer there isn't a constant clicking sound being emitting from under the table.
Solid state relays might be a possibility, but they require higher voltages passing through them in order to operate.
This guy is good, Thank you for the video :)
I received these relay shield from amazon and tested it but something
weird, when I connect the relays to the raspberry pi 3and run the program all leds and relays automatically turn on. I'm using the
same python code you use it, please any one advise what I should I do???
Hi, is it necessary to use both 5V pins?
Have you made an updated video using the pi 4?
I have not updated the video. But the code works.
will the Pi have enough 5V power to control two 8-channels relays to make a 16-relays solution?
if you're using relays with external power to trigger the relays you should be fine since the 5v is simply there to trigger the optocoupler to send the external power to energize the relay
Thanks for the Video. I have the question.I want to turn ON and Turn OFF in 24 Hours (Means scheduler for every day for 30 days). I need some help with the code. I want to include the Time stamp and also which relay are Turn ON.
please look in the About Section for the example code.
Thanks for the Answer. But where to find? can you send me link. Please
The video description. The code is on this page.
Thanks for the answer. I check the code and it is working for me. I got the following code. it is working fine for me.
github.com/skiwithpete/relaypi/blob/master/16port/script16_5.py
But i also want to include the time stamps every hour and also the pin numbers which were active? What i have to include in the code.
how do you add a lot more channels to the raspberry?
Hi do you know if one Can run RGB lights from this relay
Hi I want to that but with a NFC controller my idea is when I leave to the home 🏡 put the card #1in the NFC and the home loss all the energy. And close the door and.. when arrived to the home open the door with other card #2 and put the card #1 in the NFC and the home have energy again and when put the card #3.. six lights in the home turn on ,,, so you know how to do a remote control for the smartphone