#18 Add a Relay Module to your Arduino project - Hints, Tips & Traps

Ғылым және технология

Wow! Who knew that adding a typical 5-volt relay module to your Arduino could be so easy yet at the same time harbour some gotchas that will make you wonder what's going on?
If you need to drive some external circuitry from your Arduino module then a relay module is a fantastic item to use - but there are some gotchas to be aware of, and having some knowledge in how they work will help you refine your project.
I give you the low down on what makes these tick and how to avoid some potential traps that could leave you scratching your head!
PLEASE NOTE: In July 2017, an observant Arduinite (#Alexus) has spotted that the circuit diagram for this device is wrong - there should be no direct connection between the collector of Q1 and JD-VCC as that would be a short circuit whenever Q1 was switched on! Luckily the actual device is fine, just the circuit diagram that is wrong.
As always, Thanks For Watching.
And my channel is here:
/ ralphbacon
How can I remember this? Memory tip: "See" Ralph Bacon, geddit?

Пікірлер: 339

  • @bgable7707
    @bgable7707 Жыл бұрын

    I don't know how many times over the years I've watch this video to "remind" myself how the JD-VCC works, again thanks for the detailed explanation!!!

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Ha, ha! Yes, it can get confusing. I've just implemented a 4-channel relay for my pond controller. And yes, I used the JDD-VCC pin too!

  • @garycrockett4477
    @garycrockett44773 жыл бұрын

    Thanks for taking the time to describe what the JD-VCC/VCC pins are for, and how they work. I was having a hard time finding out, searching the Internet.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it helped, Gary. Just don't short anything out using that dangerously placed jumper!

  • @acadman4322
    @acadman43225 жыл бұрын

    Ralph, you have pointed out some important nuances with this little relay board others have ignored. Thanks quite a bit for your kind video. Well done!

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Glad you liked the video ACADMan, thanks for posting.

  • @jayobrine8475
    @jayobrine84753 жыл бұрын

    Thanks for describing what the JD-VCC/VCC pins are for, and how they work. Watched many other KZread videos on the subject on relay modules and this was overlooked. Nice job.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it was helpful!

  • @markowens9950
    @markowens99505 жыл бұрын

    Thanks for a great video. I was having trouble understanding my relays because because a single relay module I have actually turns on with the "HIGH" command but all the other relay modules turn off with this command. After watching your video I was able to understand how this one works.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Glad it helped you, Mark, thanks for posting.

  • @andreatanzi3191
    @andreatanzi31913 жыл бұрын

    This the best explanation I found about the subject. Thank you very much, everything clear!

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it was helpful!

  • @iandawkins2182
    @iandawkins21825 жыл бұрын

    Brilliant down to earth understandable for someone like me new to trying to control external devices with an Arduino. Thanks.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    I'm glad it helped, Ian, thanks for posting.

  • @iandawkins2182

    @iandawkins2182

    5 жыл бұрын

    Thank you so much, just subscribed as I think this is such a great learning channel as you have the ability to explain and inform. A rare skill please keep them coming and looking forward to what's to cum. Respect.

  • @hedbergmicke
    @hedbergmicke5 жыл бұрын

    Love your videos Ralph. Always that that bit of extra information that makes you go: "I've learned something new" :)

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Thanks for that, Michael Hedberg, glad you learning! Nice to hear from you.

  • @allbeit582
    @allbeit5824 жыл бұрын

    I looked for quite a while to find info explaining the 3pins with jumper on this board, then I found your video .... Perfect, thank you.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad it helped you, thanks for posting.

  • @mickcoomer9714
    @mickcoomer97144 жыл бұрын

    Finally a vid that explains why you are sinking the supplied voltage to the onto-coupling. Thank you.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    No problemo, Mick, glad it cleared that up.

  • @laidman2007
    @laidman20075 жыл бұрын

    Thanks for this video on relays. It clarified a lot of things for me.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    You are most welcome Roberta Laidman, I'm glad you like the video. Nice to hear from you.

  • @MikeHoover1
    @MikeHoover13 жыл бұрын

    Thanks for a great video! You are right about the jumper at around 15:30 and newbie assumptions. One might assume the jumper is to be in one of the two possible positions. I removed mine and turned it 90 degrees and placed it on the VCC pin as a reminder.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Yes, I do that with jumpers too! But they do have a habit of then jumping off, never to be seen again! That's why I bought a pack of 50 some time ago. Glad you found it useful, Mike, good to hear from you.

  • @raygud5653
    @raygud56532 жыл бұрын

    This video may be 5 years old but still very educational and usefull, help me alot. Thanks! I had some issues running the code you used but i got it working with afew modifications 🙏🏻

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    Great to hear, Ray! It would be interesting to know what the changes were?

  • @Risingnshouting
    @Risingnshouting7 жыл бұрын

    Thanks for the details. I am clearly not as skilled at reading circuit diagrams, and had no idea what was happening with my 16 channel relay. However, now I suspect I am inadvertently shorting out my GPIO IC with the connections from my Arduino to the GND, along with the 16 Pins. Again, your expertise is much appreciated!

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    I read from your other post that things are now working. I'll comment on your other post...

  • @steveedwards90
    @steveedwards905 жыл бұрын

    Thanks ralph your coding skills are far superior to my novice attempts but I cant find any one local to help so self taught .

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Self-taught is fine, Steve, but do try and follow Best Practice as you do so. Avoid monolithic programs (the first self-taught issue) and lay it out nicely. If it looks nicely written, logically, with comments, then it means the programmer has taken time with the code too. As a professional web coder for the best part of 3 decades, I can tell you I am STILL learning. But look at the demo sketch in my NEXT video (#133 about a workshop heater repair) to give you some ideas. Oops. Spoiler alert. Too late.

  • @inspiredtiny
    @inspiredtiny4 жыл бұрын

    I have just received my relay module which is exactly the same as modules shown in this video. Great thing I came across this video as I am just about to start my project.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I knew you had ordered one Robert (Benny is my spy) so it is not a coincidence that you have found this video! Have Fun but do NOT short out those header pins (JCC-VCC-GND) !!!

  • @user-qh2ed4xe5x
    @user-qh2ed4xe5x9 ай бұрын

    this was so helpful ..was stuck on a project for days ..so enlightening ..may the Heavens richly bless you thank you

  • @RalphBacon

    @RalphBacon

    8 ай бұрын

    Glad it helped!

  • @webslinger2011
    @webslinger20116 жыл бұрын

    Thanks for explaining that light flickering issue. Didn't know it was due to setting pins as an output.

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Thanks for that, webslinger2011, glad it was clear, nice to hear from you.

  • @shaunr9950
    @shaunr99505 жыл бұрын

    Great video - well explained. This has given me a much better understanding of this relay module and how to use it correctly with an Arduino board. Thank you.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    You are most welcome Shaun R, I'm glad you like the video. Nice to hear from you.

  • @russellmccallum3606
    @russellmccallum36064 жыл бұрын

    Wow I learned a lot about these relay modules with this video - Thank You so much-!!!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad you liked it, Russel, thanks for posting.

  • @FOATE
    @FOATE5 жыл бұрын

    This is great info, just what I needed to know, thank you!

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    You are most welcome dikke j, I'm glad you like the video. Nice to hear from you.

  • @jimbrownza
    @jimbrownza5 жыл бұрын

    That's a really good video; kudos for that. All I would add, when you're talking about why not to use it with the jumper attached (ie, powering the coils from the Arduino and compromising the opto protection) is the current aspect. Those Songles draw about 70mA each, so if you have an 8-relay version of the board and energise all of them at once you're up in the 1/2Amp realms and you don't want to subject the Arduino 5V pin to that.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Excellent point you make there, Jim, I'll make a note for when I next mention relays.

  • @GaryMcKinnonUFO
    @GaryMcKinnonUFO4 жыл бұрын

    Thanks for the detail, good stuff!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad you liked it Gary, thanks for posting.

  • @johnskii
    @johnskii6 жыл бұрын

    Great video - very informative, thanks!

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Thanks for your post, Broken Barrel Productions, good to hear from you.

  • @nicholasbarber5905
    @nicholasbarber590511 ай бұрын

    Simple to follow. The circuite diagram really illustrates whats happening. Thanks.

  • @RalphBacon

    @RalphBacon

    11 ай бұрын

    Glad it helped!

  • @ernestosaboia
    @ernestosaboia5 жыл бұрын

    Great information, and well done! Thanks mate

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Thanks for that, Ernesto Melo, nice to hear from you.

  • @MyBigThing2010
    @MyBigThing20105 жыл бұрын

    Long time, no see...I hope you're well. I figured I'd drop by to vampire some more of your knowledge as I just acquired one of these funny little guys for a two channel 12V multi light vehicle project I've gotten myself into elbow deep at the moment. STILL the number ONE channel I go to to find help when I stray into dangerous...err...new waters, electrically speaking. Thanks again for sharing your knowledge and explanations that the rest of us apes can rightly understand and properly digest without falling asleep or frying our eyebrows. ;) Best wishes mate.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Good to hear from you again, it's been a while. This device would work very well in a car (low voltage) and help protect your Arduino too. Thanks for your kind words about my channel, I'm glad you like the videos. Thanks for posting.

  • @RD-ni7qe
    @RD-ni7qe4 жыл бұрын

    Such a clear explanation, thanks!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad it was helpful!

  • @woopywoopwoop
    @woopywoopwoop6 жыл бұрын

    Your video was very helpful.Thank you : )

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    It makes me happy to hear that, woopscoop! That was video #18, there are now more than 100 videos on this channel so I guess you will enjoy many, many more of them as time goes by! Thanks for posting.

  • @JeremydePrisco
    @JeremydePrisco6 жыл бұрын

    Great job! I will be referring to your site again!

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Thanks for that, Jeremy dePrisco, nice to hear from you.

  • @Paulilmys
    @Paulilmys Жыл бұрын

    Best explanation yet! Thank you for the video.

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Glad you enjoyed it!

  • @CurmudgeonExtraordinaire
    @CurmudgeonExtraordinaire6 жыл бұрын

    Thanks for the hint about setting the relay HIGH before setting the mode to OUTPUT. I had been trying to figure out that no matter what I did, it insisted on activating the relay after being powered up or reset during a compile and load. I even tried it without sending a HIGH or a LOW and it still reset during the compile and load.

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Glad the tip worked, Grumpy Old Man. Funnily enough, I learned this from Arduino guru Nick Gammon. I queried why he did it and what it was doing behind the scenes, and he explained. And here we are, some years later, with the tip being passed on! Thanks for posting.

  • @M7GBU
    @M7GBU2 жыл бұрын

    Thank You Ralph, I found your video really well explained and useful.

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    You are welcome!

  • @sadayghosh5894
    @sadayghosh58943 жыл бұрын

    Thanks, the video is very helpful. Everything's explained in detail.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it was helpful!

  • @cedomirvalcic5080
    @cedomirvalcic50805 жыл бұрын

    Great video!

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Thanks for your post, Cedomir Valcic, good to hear from you.

  • @mayurchauhan4219
    @mayurchauhan42193 жыл бұрын

    Thank you for this video it helped me alot while controling relay module through raspberry pi.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it helped, Mayur!

  • @oncledan282
    @oncledan2824 жыл бұрын

    Hi, Ralph. I think you just pinned the « problem » I have with my Laser Fan Controller project I wrote a few months back. I hear relays clicking upon initialization. NOW, I know why. Hahaha! And it makes sense. Not that it is causing any problem, but I'll keep this trick in mind next time I pin un using relays in my projects. THANKS ! and take care !

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    All good news, Daniel. I know this is late but I have to put a comment here or it will appear forever in the unanswered list!!! You should see me, I have an eye patch on and I look like a pirate!!!

  • @oncledan8509

    @oncledan8509

    4 жыл бұрын

    @@RalphBacon Aaarrr! Captain ! Hahaha! Shhhh !! Don't say that over the Net, for we just might taking you up for making your next video with this patch on ! Hahaha! Witch makes me think I must put my list to date. I made a list of all your video's titles a few months back (when we first met) and I didn't touch to since. I'm waaay back on that list, now. It's my Arduino/ESPxx's Bible and I often refer to it when I have time to play with these modules. Nowadays, I'm working that Laser like crazy .. for Xmas presents and all. Oh well ! Time will come back, I'm sure, when I'll have plenty of time to go back to the fascinating world of Arduino and ESPxx. Sooner than I expect, I guess! Hahaha! Have a nice day, my Friend .. and watch out for this eyepatch !! Take care !

  • @swedemake5571
    @swedemake55712 жыл бұрын

    Thanks for a great Video

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    Glad you enjoyed it!

  • @josip1881
    @josip18813 жыл бұрын

    Well explained, thank you.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it was helpful!

  • @prashantsakre6577
    @prashantsakre65773 жыл бұрын

    This is good exactly I needed...thanks

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it was helpful!

  • @McBurneyAndrew
    @McBurneyAndrew3 жыл бұрын

    Great work

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Thank you so much 😀

  • @syaduinotech3681
    @syaduinotech36812 жыл бұрын

    Thanks for your video sir. I have the problem with my relay, when start on, all the relay was not behave like i want. The reason, i already noted based on your explaination worth to try out. Tq sir

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    You're most welcome and good luck with your project.

  • @raillersinghirina8345
    @raillersinghirina83458 жыл бұрын

    Thanks for all tuto!

  • @RalphBacon

    @RalphBacon

    8 жыл бұрын

    +raillersing Hirina You are most welcome! I hope it's helping you get your Arduino project(s) further forward. Remember to spread the word and, if you haven't already done so, please subscribe so you don't miss future videos.

  • @raillersinghirina8345

    @raillersinghirina8345

    8 жыл бұрын

    Hi!!Can you explain the variable type boolean...I dont understand it and I have not found tuto about it. I saw it in the book: Exploring Arduino. My problem is: I have never seen this in language C. I can give you the book if you give your email.

  • @RalphBacon

    @RalphBacon

    8 жыл бұрын

    Sure. A boolean variable (bool) can be either TRUE or FALSE. For more details see here: www.arduino.cc/en/Reference/BooleanVariables

  • @raillersinghirina8345

    @raillersinghirina8345

    8 жыл бұрын

    thanks

  • @jakel1977
    @jakel19773 жыл бұрын

    Thank you. Very good explanation

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad it was helpful!

  • @amoshuxley2924
    @amoshuxley29242 жыл бұрын

    Great video! Thanks 👍

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    Glad you liked it!

  • @berliandro
    @berliandro Жыл бұрын

    I spent weeks and days trying to figure out why my servo spins when i turn the "isolated" relay on. And it takes 13 minutes to solve it with this video ❤❤

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    I'm so glad it helped, Patrick!

  • @Reptiledge
    @Reptiledge8 жыл бұрын

    do you have a tutorial where the relays could be triggered through a humidity sensor depending on its readings?

  • @RalphBacon

    @RalphBacon

    8 жыл бұрын

    +Reptile_Edge I've no specific video on that, but if you're using something like a DHT11 humidity sensor then it's as simple as reading the data via its one-wire system and triggering the relay at a certain humidity point. No different to using a DS18B20 temperature device in its implementation really. In fact, the DHT11 returns both humidity and temperature together. It just uses a different library. If you look at the Arduino playground website (playground.arduino.cc/Main/DHT11Lib) there an example of how to read that device. All you then need to do is turn ON or OFF or relay at certain humidity/temperature points.

  • @JohnBaxterWalker
    @JohnBaxterWalker4 жыл бұрын

    Excellent video - thank you. I notice on some coding for relays there is a line in Setup - Serial.begin (115200); . Can anyone tell me if it's important when operating these relays please?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    That line has no bearing on the relay part of the sketch, John. What it is telling Arduino is that the speed of data transmission from the Arduino back to the PC/Mac (in the Serial Monitor, aka debugging window) is at that speed. So you can then send information back like this: Serial.println("Relay ON"); I tend to use 9600 which is a bit slow but very stable!

  • @oceanzrobotics
    @oceanzrobotics Жыл бұрын

    Thanks immensely!

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Glad you found it useful!

  • @jeffbluejets2626
    @jeffbluejets26265 жыл бұрын

    Well done.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    Thanks for your post, Jeff Bluejets, good to hear from you.

  • @rob3125
    @rob31253 жыл бұрын

    Very useful thanks 👍

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad to hear that.

  • @steveedwards90
    @steveedwards905 жыл бұрын

    Thank you this has been a problem for my self I want to switch 2 relays on when I push a button but they must not switch when powered up those code lines will save me a large headache lol regards

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    You are most welcome Steve Edwards, I'm glad the video helped you. Nice to hear from you.

  • @cyabd8515
    @cyabd85152 жыл бұрын

    Thanks Ralph for a very helpful video. It seems when using a 5v relay things are pretty straight forward and easy but, the problem starts going beyond 5v even 12v could still be all right since can use the VIN on Arduino but as far as I understand it and for the benefit of others you cannot use Arduino to trigger a 24v Relay. Although 12 is still ok feeding the Vin with an external 12v. Generally it seems triggers can only be done within 10% of the Relays Voltage rating as in min. 9v required for a 12v one and 21v to trigger a 24v relay!

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    Glad you found it helpful, Cy. You can always trigger a higher voltage relay if you supply the necessary voltage independently, usually controlled via a N-MOSFET. So the Gate of the MOSFET is switched on via the Arduino (via a 100Ω resistor), the Source of the MOSFET is connected to GND and the Drain of the MOSFET is connected to one side of the coil with the 12/24v connected to the other side. All Grounds are connected together (common ground). A simple TO-92 outline 2N7000 MOSFET works well, usually.

  • @cyabd8515

    @cyabd8515

    2 жыл бұрын

    Also now-a-days Relays mostly come with the bi-directional Optos meaning no JD-Vcc! A bad Idea since JD-Vcc and the external power option not only creates total Isolation but also much less current draw on the Arduino since it only needs to light an Led and has nothing to do with the relay coil which gets powered by the external source.

  • @cyabd8515

    @cyabd8515

    2 жыл бұрын

    @@RalphBacon Yes quite so, but then you'd be making a relay of your own to get the ready made one going. It's just best for everyone to know, if they want to get an MU like Arduino to trigger the relay, to NEVER buy a relay with more than 12v nominal rating. That is a 5v one can be run with no other changes necessary and the 12v one only with connecting a 12v supply to vin and then, only the MU/Arduino input signal line connected to Arduino and everything else on both sides input/output must be connected directly to the external supply which should not be leass than 9v also feeding the VIN. The relays with J-D VCC more versetile/safer draing much less current from thr Arduino Vs. the ones without it(my 2 cents after suffering 2 days of searching and trial error to get a 12v relay without JD-VCC going). I often wonder, why the Cinese don't invest a few bucks to write a proper tutorial on their product, I hope it is NOT intentional?

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    Perhaps in Chinese, the phrase "invest a few bucks" is often misunderstood as "keep the costs down"?

  • @bigpickles
    @bigpickles4 жыл бұрын

    Thanks very much, very helpful. One silly question I have though, is seeing as I'd like to keep my 12V source (deep cycle agm battery) fully charged, if I were to keep the trickle chargers (12V 1A from 240 mains adapter) cables attached to the battery, and activate a 12V 5A draw via the relay, will the charger/adapter pop, or will the battery deal with the draw? Please excuse my ignorance!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    If you are _directly_ charging the battery from a charger the the current for any circuit will come from both battery and charger, depending on which has the higher voltage. If the charger can only supply 1A (at which point the voltage will drop) all the "missing" current will come from the battery. It would be better to use a dedicateds battery charger circuit (like the ones for LiPOs) that allow charging and powering a circuit without anything getting stressed. Check out solar panel charging modules.

  • @bigpickles

    @bigpickles

    4 жыл бұрын

    @@RalphBacon ah like an MPPT controller? Thank you kindly for the reply too. Best wishes

  • @berliandro
    @berliandro Жыл бұрын

    You saved my life

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Well, not literally, I hope but I get the gist!

  • @jeff3741
    @jeff37415 жыл бұрын

    I had been using an LED on my breadboard to represent the optocoupler and set the ledState to HIGH for 'on' and took the other pin to ground. Would that not work as well?

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    To turn the relay on, you need to SINK the current. So the pin needs to go low. The current flows from VCC thought the diode into the Arduino and then (internally) to ground. Is this what you're asking? If so, you can model this on your breadboard the same.

  • @bloodswarms
    @bloodswarms6 жыл бұрын

    Subscribed because of this video. Side note: Ebay relays terrify me.

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Thank you indeed, Bloodswarms! If you liked this video you will like a future one too but no spoilers at this early stage. Let's just say we explore different approaches to relays. Side note: anything to do with mains electricity from the Far East gives me the willies (side note to my side note: I hope that translates well, it's a UK, family-friendly expression)

  • @m0gga
    @m0gga7 жыл бұрын

    Hi Ralph, thanks for sharing this informative video. I am currently working on a project for the control of various 240v devices used in my fish keeping hobby and have recently purchased a couple of similar relay modules with solid state relays, so as to eliminate the noise of the relay contacts. Do your recommendations in this video apply to solid state devices and are there any other pitfalls associated with using them, other than the obvious current limitations of the relays? Thanks.

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    Hi Fred, and welcome to my channel! A solid state relay is, mainly, an opto-coupled triac so it behaves very similar to the opto-coupled part of the relay that I described (without the actual relay!). You still have to protect the circuit from spikes and back-EMF from any motors you might be driving (or anything else with a coil, such as a fan) but apart from that it should all work as you would expect. The Arduino will drive the 'input' (usually an IR LED) which is received by an photo-sensitive diode/triac connected to a mains voltage triac (a bi-direction thyristor) - usually with a zero-crossing component in the middle to ensure the off and on states only occur as the AC mains voltage crosses the zero voltage line - thus eliminating (or minimising) any RF interference generated. As you say, they are silent and work pretty much as you might expect. Just be aware that the IR LED driven from your Arduino must include a limiting resistor (usually) and the breakdown voltage of that diode is probably not much more than the 5v Arduino output level so don't connect it in reverse by mistake! Ideally you should reverse connect a standard diode in parallel with the input IR LED to protect it from just such a mishap. Additionally the forward voltage of that LED is pretty low, about 1.2 volts rather than the 2.0+ volts of standard LEDs. Refer to the maker's datasheet to find out the exact figures or you might overdrive the LED. From a 5v Arduino output the limiting resistor would be 5v - 1.2v = 3.8v drop at 20mA = 190R or the nearest (higher) preferred value. Finally, if I recall correctly, you should incorporate a snubber circuit in parallel with (and close to) the output pins that consists of a capacitor (suitably rated for mains use) and a resistor - a 0.022uF capacitor and a 47R resistor is a good starting point. This absorbs surges created by the load which may turn the relay back on again.You may not need this depending on what you are switching, but at least you know about it. I hope this helps and may your fish continue to thrive!

  • @m0gga

    @m0gga

    7 жыл бұрын

    Thanks for such an in-depth reply! Please take a look at this module which is the one I have www.ebay.co.uk/itm/132067724356? , is this not a plug-and-play solution not requiring any additional circuitry? Thanks.

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    Squinting sideways at the photos on the eBay page it shows that the Omron relay model is a G3MP-202P, which if you look at the datasheet for that relay (www.mouser.com/ds/2/307/g3mb_0609-298620.pdf) it states on page 1 under Ordering Information that that model does contain both Built In snubber circuit AND input resistor. Woo Hoo! You have got the jackpot and therefore don't need to consider either (probably why the manufacturer of the board used them for Arduinos et al, as they save components). Phew! (More by luck than judgement, but hey, who cares how?!) Plug and play it is, indeed. Just watch the current on the (presumably) mains side of things, 2A max if you're using heaters for the water etc. 230V x 2A = 460W, sounds a bit high for a fish tank heater, you could boil a cup of water with that so I guess fish tank heaters are more in the 25W range? Your fish will love you.

  • @m0gga

    @m0gga

    7 жыл бұрын

    What a result! My fish and the relays will indeed be happy, especially since the highest rated heater I use is only 100W. Generally speaking most common fish tank heaters are between 25W-150W. Thanks for all your assistance.

  • @manuelacuna9958
    @manuelacuna9958 Жыл бұрын

    omg!, thank you so much! I had this issue with powering up an Arduino. The relay would activate within the first few microseconds, turning on the contactor of an AC motor,and of course, that shouldn't happen, It was driving me nuts

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Glad it helped you Manuel!

  • @eraslanaslan9059
    @eraslanaslan905911 ай бұрын

    This video is very helpfull thank you sir:)

  • @RalphBacon

    @RalphBacon

    11 ай бұрын

    Glad it was helpful!

  • @ZunairParviez
    @ZunairParviez Жыл бұрын

    Thanks sir you explained very well. The same module you using is available in my country at the price of less then dollar 😀

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Glad it helped! I'm using the 4-relay module in my most recent project and that was pretty inexpensive too.

  • @JeanDAVID
    @JeanDAVID5 жыл бұрын

    Do we need separate ground too ? On a 4 relay modul there is no ground pin next to vcc ! Then we have external vcc on jd-vcc pin and ground on to the gnd pin on the input header.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    If the relay board is controlled by optocouplers, Jean, then you do *NOT* need to connect the grounds together. Why? Because the Arduino (or whatever) is effectively just lighting up an LED between a GPIO pin and it's own ground (via that optocoupler). End of. The relay board now does whatever it needs to, by using its own, entirely separate power supply. Fantastic isolation between the two parts. I hope this is clear, if not let me know. Thanks for asking a great question.

  • @Risingnshouting
    @Risingnshouting7 жыл бұрын

    On my 16 channel relay, I removed the ground connection from the Arduino to the relay, so the ONLY connections between the Arduino and the relay board are the IO Pins. Everything works fine now, and no more shorting out :-). I obviously have a separate power supply to control the relays, and it has a ground connection. I wonder where the current flows from the IO pins, when they are set to HIGH? Does the current flow from one pin set to HIGH to another pin set to LOW? If that's the case, am I always required to have at least one pin set to LOW?

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    OK, let's figure this out. The ONLY two connections you need to get this to work are the VCC (+5v) from the Arduino and a GPIO pin configured as OUTPUT. So the current flows from the (Arduino's) VCC through the opto-isolator LED pin (IN1) and back from GND to the Arduino's GPIO pin set to LOW (to let the current flow - set it to HIGH to stop it). But... But if you are also powering the relay from the Arduino's 5v supply, then you need that jumper in place (to join VCC to JD-VCC) and that GND (ground) connection (back to the Arduino) too. This is good for testing it all hangs together. If you are powering the relay side of things independently then you need to remove the jumper, and connect the independent power supply to JDC-VCC and ground. The ground does NOT need to go back to the Arduino. This is the best option as you're then totally isolated. Not sure if this clarifies things or not, Mr RisingNShouting? Let me know!

  • @Risingnshouting

    @Risingnshouting

    7 жыл бұрын

    Ralph S Bacon Yup, that helps a lot! Thanks Ralph, you're the best!

  • @supremeleader5516
    @supremeleader5516 Жыл бұрын

    Thanks

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    No problem!

  • @yusufcali793
    @yusufcali7936 жыл бұрын

    Amazing video, very pedagogical, beginner friendly and focused on the point. Thank you for your time sir. Your friendly and humble cyber-student. :-) Much love from Sweden

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Nice to hear from you Josef, glad you're liking the videos!

  • @Ahlg1990
    @Ahlg19902 жыл бұрын

    Thanks for the video, But I am a bit confused by the closing comments, you mention the protection diodes and that all you need to do is connect the Arduino to those inputs (easy), But a bulk of the video was discussing the issue of jumper pin and the two circuits not being isolated. So is it ok to use the Relay with jumper between VCC/JD-VCC and the Arduino powering the whole thing? Do the protection diodes protect the Arduino?

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    I'm sorry to have confused you; it was because I was trying to cover two points here. You can connect the jumper between VCC and JD-VCC to power everything, then connect up to the Arduino as described in the video. Because the relay module is isolated as far as the GPIO pin of the Arduino is concerned (that opto-isolator) there is no need for any further protection. Note that the relay energises when the GPIO pin goes LOW (not HIGH as you might expect) because the current flows from VCC into the LED then into the GPIO pin then to GND. If the Arduino were to ever power a bare relay (coil) it would need the protection of a diode connected across the coil contacts so that when the relay was de-energised, the back-EMF (potentially hundreds or thousands of volts) caused by the collapsing magnetic field of coil did not find its way back to the GPIO pin. Regarding that VCC/JD-VCC jumper, if you were to power the relay module with an independent power source (and removing the jumper) it would improve the isolation as all the Arduino environment now sees is the LED within the opto-coupler. But it's not necessary to do this. Have I confused you even more now, Andrew?

  • @saadet4
    @saadet44 жыл бұрын

    Can the alternate power source be something other than a breadboard power supply? Maybe something a little more friendly for a portable application?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    The power for the relay (if you are using a dedicated, separate power source for the relay) can be anything you want - but it will need to supply power for as long as the relay remains energised. For portable, battery powered devices you really need a _latching_ relay that switches to the open (or closed) position and stays like that even if you remove the power. You can then switch it back again (via a different coil pin) the same way and remove the power. I hope this helps. Portable devices don't really need an isolated relay anyway, so you can power it from the same supply as the µController.

  • @FOATE
    @FOATE4 жыл бұрын

    So this might be a stupid question but when using the external power input on the relay module, can you use the same power supply, like the breadboard power supply you're showing, to power the Arduino as well or does this defeat the purpose? It would be nice to have one psu powering both devices because it saves some space!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Not a stupid question at all, dikke j. You can indeed use the same 5v source to power both Arduino and the bare relay (coil). Either drive the relay coil _directly_ via a transistor from a GPIO pin (using a protection diode across the coil), or use an opto-isolated relay as I showed here, which protects the Arduino (and you) better - and arguably is easier to use!

  • @FOATE

    @FOATE

    4 жыл бұрын

    @@RalphBacon Awesome, I thought it would be possible but I just wanted to make sure since this is all new to me. Thank you very much for being so helpful :)

  • @drelectronics13
    @drelectronics133 жыл бұрын

    If i use same connection in esp 8266 with 8 channel relay board on which pin of esp 8266 i hv to i hv to connect vcc

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    You must be careful with the ESP8266 as it is a 3v3 device. The module you have will probably have a 5v pin which can be used for the JD-VCC relay supply (if you are not using a separate power for that side of things). For the opto-coupler LED you can use any pins (choose ones that aren't PWM-capable or that is used for I2C or SPI) connected to the IN1 - IN8 pin. If the current limiting resistor (R1 in my video) is not already on-board choose the wisely. If you are using a 5v supply as VCC then limit the current to 10mA so your resistor will be about 200 ohms (you have two LEDs in series on that board, one embedded in the optocoupler and the visible one). If you use 3v3 your resistor will be about 150 ohms but there is a possibility it won't work at all at 3v3 due to the LEDs voltage drops. Try it and see! Remember that the relay switches ON when the digital pin connected to the INx pins is LOW (your µC will SINK the current from VCC via the current limiting resistor).

  • @KaylebGarmon
    @KaylebGarmon5 жыл бұрын

    Can you just add a flyback diode at the JD part instead of removing the jumper? I don't have a separate 5v power supply.

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    If you don't have (or don't want) a separate power supply for the JD-VCC part of the circuit, Kayleb, just keep the jumper connected on the board, JD->JD-VCC. Replacing the jumper with a rectifier diode (eg IN4004) might give a modicum of extra protection should things go awry in the "other side" of the board, but don't rely on it. That's assuming the voltage drop across the diode doesn't affect the operation of the relay (which I don't think it will). Adding a flyback diode _instead_ of removing the jumper doesn't come into it here, I'm not sure how you see that helping you. Let me know!

  • @steverose2405
    @steverose24055 жыл бұрын

    I have a similar board, but is a bit different. It does not have the troublesome ground next to JD-Vcc and Vcc, just the latter two pins with a jumper, which I have removed. When connecting my independent 5 Vdc power supply, do I use JD-Vcc and the ground pin that is next to the relay inputs? Thanks

  • @RalphBacon

    @RalphBacon

    5 жыл бұрын

    That's right, Steve. The independent power supply (for the relay) goes to JD-VCC and the ground is common so must go to the GND pin on the board. If you have a multimeter you can prove that JD-VCC is not connected to the Arduino board at all.

  • @steverose2405

    @steverose2405

    5 жыл бұрын

    @@RalphBacon Good idea; thanks for your support!

  • @markwatson7636
    @markwatson76364 жыл бұрын

    Great demo. Can you help me? I have a MT3608 step up converter. I want to increase my output power from the arduino uno to ignite an electric match for my rocket parachute deployment. 9v battery is my power source . Can I power the MT directly from the battery and use arduino as a switch only? I used a blink program to send power to MT3608 thus increasing voltage, but not amps. ??? Any diagram help would be great.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    If the 9v can ignite the match, Mark, then the Arduino can connect the 9v into a totally separate electrical circuit via the relay. Rough circuit here: www.dropbox.com/s/h1bvuntfivrmw5d/9v%20match%20circuit.png?dl=0 Do watch the demo explanation in conjunction with that circuit.

  • @jcdock
    @jcdock4 жыл бұрын

    Great info! Might save me killing on of my boards.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Oh no! Don't kill your board. I can't condone any cruelty to any board. Be kind. It will then work again because it loves you.

  • @jcdock

    @jcdock

    4 жыл бұрын

    @@RalphBacon I won't! I'm always careful !

  • @glentyan2505
    @glentyan2505 Жыл бұрын

    I don't know if it's already been pointed out but the back emf diode and relay coil are short circuited. {Q1 collector to JD-VCC line.}

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Ha! I never noticed that before! Not my circuit diagram, but from the seller. The boards works at least, so we can safely assume that the replay coil is not shorted like that. Well spotted, Glen, you get the Eagle Eyed award for... well, for the last 6 years. 👁️😜

  • @marius86ar
    @marius86ar6 жыл бұрын

    And what do you do when you have only one 5v power supply? Then it means no isolation is possible, right? Maybe a DC to DC isolator will do the trick? What is happening if I take out the jumper and I split the power supply so that 5v -> jdvcc, gnd of the power supply -> relay module optocouplers gnd and on the other pins, VCC from 5v+ Arduino pin, inputs from Arduino outputs and gnd remains unconnected. Arduino also is powered by power supply

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Well, it's not so bad, Marius, if the relay board is powered by the same 5v as your Arduino, it's just that the level of isolation is reduced. At least this board gives you that choice. And, don't forget that the actual signal path is always isolated. Basically, it's risk vs convenience that we just all weigh up. Good point, thanks for posting.

  • @yurkshirelad
    @yurkshirelad3 жыл бұрын

    If you wanted both relays to be off at bootup, would you set the pins to low before using pinMode?

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Yes; Nick Gammon, Arduino guru, once told me to set the pins LOW before changing the pinMode to avoid the tiny pulse that will otherwise appear on the relay pin, which might cause the relay to chatter.

  • @dekipet
    @dekipet6 жыл бұрын

    If i understood correctly with external power supply on gnd and jd-vcc, module need vcc from a board for in pins to make a circle. And if board works on 3,3v than vcc MUST be connected with 3,3V and not 5V external (say)? Otherwise 3,3V board could be damaged?

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Just to be sure we both agree on what is required, Dejan, let's summarise: 1. The power from your Arduino goes to VCC 2. The "IN" pin goes to the Arduino output pin that SINKS the current when LOW (it should be labelled OUT pin, really) 3. If you choose to supply 5v to JD-VCC and do NOT use the jumper then it will work as expected 4. If you DO use the jumper so that VCC and JD-VCC are joined then you must ensure that the voltage to your Arduino is the expected voltage of 5v. 5. If you DO use the jumper and are using a 3v3 board then you must reduce the voltage (from VCC) down to 3v3 before it reaches the Arduino. Just remember that the Arduino (or whatever board you use) is SINKING the current from the IN pin. This image is very clear: electronics.stackexchange.com/questions/196139/why-is-designed-active-low I hope this helps. Good question, thanks for posting.

  • @dekipet

    @dekipet

    6 жыл бұрын

    4-CH relay module don't have separate GND for external power so with 3,3V board connections should goes like this: 1. GND should be connected with GND on board and external power supply GND (all three) 2. IN pins on board digital pins 3. VCC on 3,3V board pin 4. JD-VCC on 5V VCC of external power This way board should be safe from and IO pins will work on 3,3V, and relay on 5V. ?

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    No, don't connect the GND of the external 5v to the Arduino, it doesn't need it (not unless you are powering the Arduino by using the jumper). All the Arduino needs is the VCC pin connected, so current flows FROM the Arduino, through the LED and back in via the IN pin GPIO (where it will flow internally to the Arduino's GND). By keeping the GND pin purely for the external power supply you have totally separated the two supplies (unless you use the jumper). Make sense?

  • @dekipet

    @dekipet

    6 жыл бұрын

    Just tried. Yes. Thank you.

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Glad it all worked out for you, Dejan, makes it all worthwhile!

  • @DougHanchard
    @DougHanchard6 жыл бұрын

    After watching this video, I'm more confused about relays than I was before. Muckery...

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Oh dear, Doug, that wasn't the intention at all. If you can specify the areas which confuse you I'll do my best to untangle confusion and provide a clear path forward...

  • @hullmanhunter
    @hullmanhunter6 жыл бұрын

    Can you please tell me where to buy relays like this. I can't find any with separate VCC and JCC

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Any of the Far Eastern warehouses have these (Banggood, Aliexpress, Gearbest), HullmanHunter; they are available in single, double, quad, eight-way, twelve and sixteen relays on a single board! BUT do make sure you buy the optically isolated ones (the ones you're having problems finding). Here's an example for you: www.aliexpress.com/item/10-pcs-Optoisolated-Relay-Module-5V/1950115306.html Oops, that for 10 pieces but see if that seller does them singly too.

  • @jonathanmurray2186

    @jonathanmurray2186

    6 жыл бұрын

    hullmanhunter Amazon sells them too

  • @stefaneberle8969
    @stefaneberle89693 жыл бұрын

    Hi.. I have a 12V power supply for the Arduino. The 5V from the Arduino I use for the output pins/ opto coupler diodes...for the Relais I use Vin from the Arduino Board... which is the 12V before the Arduino Voltage regulator.... This is not a full galvanic isolation but I think the Arduino is well protected this way...Do you think so too?

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Yes, correct, Stefan. The Arduino is not totally protected but pretty good. Good enough, anyway!

  • @karamchris
    @karamchris7 жыл бұрын

    Hello Ralph, I am super new to this hobby. Do you know how to sketch a potentiometer into the mix to control the speed of the switching? Thanks, Chris

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    Hey Chris, welcome! This channel is designed for noob Arduinites like yourself, so I hope you have fun watching the videos and learning along the way. Back to your question: can you just elaborate what you mean by "speed of switching"? Do you mean you want to switch the relay on, then off, then on... and so on? Or do you want a delay before the relay switches on once it has been triggered? Let me know and I'll see if I can answer! Always good to hear from a newcomer to the Arduino world.

  • @karamchris

    @karamchris

    7 жыл бұрын

    Thanks for the quick reply and the help! Yes, I would like to control the on/off/on/off of a relay. I need it to power a solenoid valve for a water sprayer. I need it to spray in short quick bursts, and then long slow bursts. It would be good to control both either with a pot or with an on screen GUI. Any help would be greatly appreciated.

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    Understood, Chris, thanks for clarifying. You might want to look at the "Blink" example sketch first (just so you understand the flashing LED principle), then look at one of my sketches that uses a pot to control the analog value (eg my Neopixel display demo) and see if you can figure out how you might connect that up to the "Blink" sketch instead of using a fixed delay value. If... If after looking at that you're thinking "Huh?" let me know and I'll knock up a quick demo sketch. It's quite straightforward but being super new to Arduinos it would be in your best interests if you understood what you were doing rather than just copying code - that way you'll learn loads of stuff along the way. Let me know, either way.

  • @karamchris

    @karamchris

    7 жыл бұрын

    Gotcha! I have a sketch going with the basic blink function. I am still getting errors when I compile the code. I think if you wouldn't mind sending me that basic sketch I'd be able to better figure out what I'm doing wrong. I greatly appreciate the help!

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    Out of the goodness of Benny's heart, he has agreed to look at your code. Upload it to this DropBox folder (just drag and drop) and I'll let you know where you have gone wrong. This way you will get your own code to compile. Link: www.dropbox.com/sh/1u198yq6tbcfesa/AADmsqAxJQZ0fiUPQvEawOW6a?dl=0 Let me know when you've done it and I'll get Benny on the case!

  • @MrIonutz2008
    @MrIonutz20084 жыл бұрын

    Hi, i would like to know if the 24v rated relay modules could be triggered by a 24v signal or the 5v signal is a must . Thank you.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    There are *two voltage ratings* for a relay, Ionut. The first is the COIL voltage, and determines how much voltage you need to trigger (switch) the relay on and off. The second voltage/current is how much current the relay can carry. So a 5v relay with a rating of 24V/5A means that it requires 5V (no more) to trigger it, and can carry up to 24V at 5A maximum. Don't forget the protection diode across the coil, which will be present on a module board like I used, but you will have to add one if you use a bare relay. Is this clear?

  • @MrIonutz2008

    @MrIonutz2008

    4 жыл бұрын

    @@RalphBacon Thank you for response although i'm not sure i did put the question the right way in order to get the right answer. For example the relay module is this www.ebay.co.uk/itm/1-channel-24v-relay-module-board-shield-for-arduino-with-optocoupler-ZT/362992628401?_trkparms=aid%3D1110001%26algo%3DSPLICE.SIM%26ao%3D1%26asc%3D20190920091355%26meid%3D0afe53015d8d4b729b7d7ba4cf4e6a36%26pid%3D100036%26rk%3D2%26rkt%3D7%26sd%3D402261796421%26itm%3D362992628401%26pmt%3D1%26noa%3D1%26pg%3D2047675&_trksid=p2047675.c100036.m2109 . Not talking about load rating. So, all i need to know is what voltage will require the input pin to trigger the relay on/off via optocoupler. Are the 24v coil modules built to be managed by 24v inpun signal, the 12v coil modules by 12v input signal, the 5v coil modules by 5v input signal or all the relay modules no matter the coil voltage is, are built to be triggered by an input signal in range within let's say 3.3v - 5v ? I'm talking strictly about the way they come from factory, about what range of signal voltage they can handle safely. I want to know if to this 24v coil relay module i can apply 24v as signal input without frying the input zone of module. I hope i made myself understood and i apologize for giving you such a headache. It's all because my bad english. Thank you again.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    It's not your English that's a fault here, Ionut, just the rubbish documentation on these products! I can't even see the optical isolator, on the board you link to. I suspect the 24v refers to the JD-VCC that goes to the optoisolator (see my video at about 01:58). All the optoisolators require you to SINK the current from VCC (NOT JD-VCC) to ground. I would carefully wire this up to 5v first and test this out as per my demo. Then you can ramp up JD-VCC to your 24V and hope it works. this site has better pictures: www.ebay.co.uk/itm/5V-12V-or-24V-1-2-4-8-16-Channel-Relay-Module-Arduino-PI-ARM-AVR-DSP-PIC-PLC-UK/362951292175 The 24v relay switching voltage and the VCC for the optoisolator are separate - you don't want 24v anywhere near your Arduino!

  • @MrIonutz2008

    @MrIonutz2008

    4 жыл бұрын

    @@RalphBacon Thank you for response,. i'm sorry i sent you the wrong link, in fact the relay i bought is exactly from the link you sent to me ( the 24v - 2 channel relay module). My first thought was that if the JD-VCC and VCC are bridged by jumper and board being supplied by 24v, the input pins could accept 24v as signal. I don't use arduino, this relay will control the spindle of my cnc router which controller has the output pins providing 24v signal. In other scenario i could remove the jumper to feed separately the relay coil with 24v and for inputs zone i will provide the 5v TTL from breakout board . I guess and hope this way will work. Thank you.

  • @jeremylambright1658
    @jeremylambright16583 жыл бұрын

    Awesome video! Does anyone know where i could get more info or paid online training on how to write code for arduinos and relays

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    There are doubtless many, many books on the subject, as well as videos, not least on this channel. However, the best way to learn is by doing, tweaking and understanding. You should at least be able to understand each and every line in your sketch - even if it's written by someone else. Start small, build on that. If you try and design the equivalent of NASA using an Arduino UNO you will become frustrated and eventually give up. My list of videos: bit.ly/KZreadVideoList-RalphBacon

  • @dannyrodman5075
    @dannyrodman50756 жыл бұрын

    Your video was great however, in spite of me following you my 4 channel relay (which appears ok) doesn't seem to switch. I don't hear anything happening but the led is lit. I trying to turn on a 12v pump which is prompted by a moisture sensor. I've been struggling forever with what should be a simple task (according to your video). I would be very much in your debt if you are able to advise me what I might be doing wrong and help me out.

  • @RalphBacon

    @RalphBacon

    6 жыл бұрын

    Sure Danny, let's see if we can crack this. 1. Firstly here's a good circuit diagram of what is happening: electronics.stackexchange.com/questions/196139/why-is-designed-active-low If you don't understand this, don't worry, it's not essential but it would help you if you tried to follow the circuit. 2. So when you connect your Arduino's 5v pin to the VCC (but REMOVE the jumper for now) and connect the relay board's IN pin to the Arduino's GPIO OUTPUT pin that you are using to control the relay, when you set that OUTPUT pin to LOW the light will come on. When you set it HIGH the light will go off. The relay will not click. Get this working FIRST. This is because the current is flowing from the Arduino's power supply (5v) via the relay board's optoisolator LED, out via the IN pin (this should be called OUT not IN) to your Arduino and hence, internally, to ground. 3. Now, if you ALSO want to power the relay with the same 5v from your Arduino, attach the jumper from VCC to JD-VCC, the Arduino's 5v to the other VCC pin, and the GND pin on the relay module to the Arduino's GND pin (there's more than one GND, any will do). Now when you set that GPIO pin to LOW it will light the light AND pull-in with a "click" that relay. 4. If this works all well and good but remember that you COULD isolate it better by removing the jumper, connect the JD-VCC and GND pins on the relay to a SEPARATE 5v power supply. That way, the two parts of the circuit are totally, 100%, separated. But it's your choice! Now, which bit of this works and which bit does not?

  • @dannyrodman5075

    @dannyrodman5075

    6 жыл бұрын

    Understood. Running a test program - channel connected on then off for 1 sec , relay powered from separate 5v supply, ground not connected. The leds on the relay flash 1 sec as expected but no sound from the relay. Is it DEAD!? When I first had it and ran a test there was a clicking sound - no more. I suspect I've fried it.

  • @dannyrodman5075

    @dannyrodman5075

    6 жыл бұрын

    Thanks for detailed reply - immense help. I followed you steps 1 - 4. Step 2 - worked as you said - great! Step 3 - again worked as you said. In fact a 4 channel relay I thought I had destroyed came back to life. I now have a collection of relays! Step 4 - Not so lucky here. Relay LEDs poorly lit. (4 channels). Following a test sequence HIGH/LOW on each of the 4 relays. The relay being activated becomes slightly brighter and the remaing 3 still remain lit although very dimly. The leds seem to indicate that the relay is working but it isn't if you follow me. Still no sound from the relay. I put a meter across the the voltage supply - 4.95v. Is it enough? so I increased the supply to 7.5v - no improvement I reverted to Step 3, attached some components to the circuit I'm building. The relays ceased to function... I am trying to create a control system for my greenhouse - 1. Overhead water spraying activated by moisture sensors water via 12v submersible pump. 2. Air bouyancy via 2 x 12v dc Fans. These will be initiated by a DS18B20 sensor and also PWM (hopefully) 3. LCD 20 x 4 for visual readout of all the above. 4 MCUs either UNO or Nano (preferred) Sketch developed by myseld (not very elegant I suppose). The moment I attach modules to the relay it doesn't work. It seems to drain the Uno or NAno. The fans startup but continue unabated. I susupect they are drawing power from the MCU I've been at this for a month now and am beginning to doubt myself and my capabilities. I done other diy electronics successfully but this is beginning to make me miserable. I know it's a lot to ask, but, I hope you can help me out with this nightmare. Thanks

  • @KAVIAN_HZ
    @KAVIAN_HZ4 ай бұрын

    This was a awesome complete guide for relay module❤ I want to add a arduino to one of my home appliance so Im using a relay. the power outlet voltage is 220 volt and also the machin input power is 220 volt too and as you know arduino input is 5 volt so I was wondering is it possible to use a voltage decreaser module from 220 to 5 volt for my arduino instead of using adaptor for the my arduino and adaptor for the machine and just plug the both at the same time with same power cord directly to the power?

  • @RalphBacon

    @RalphBacon

    4 ай бұрын

    If you have your mains voltage as part of the project anyway, I would use a mini PCB-mounted 5v PSU. I've used this many times and they are good if you use a good quality one. Hi-Link are OK. They might do a screw terminal version (so not designed for a PCB) if you look hard enough. Also check out "open frame 5v PSU" which I've also used with great success. These always have some sort of screw terminal but are larger than the mini PSUs I mentioned above.

  • @vedaprakash2707
    @vedaprakash27072 жыл бұрын

    i am trying to switch between 2 batteries of 12V and 80A and 12V 20A, i am confused in choosing a relay. Would you recommed me which type of relay should i use? thanks

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    It depends on how much current you will draw _in your circuit_ . If the circuit only draws 2A then a relay rated for _at least twice_ that (so 4A+) will be fine. But if you intend using anything much higher (eg 16A) then be very careful that you find a relay that can handle that much continuous current. I always *double* the rating to be safe.

  • @patrickconrad396
    @patrickconrad396 Жыл бұрын

    I'm trying to make a water pump trigger. Would I put the relay before or after the step up? Anyone know? So if water hits a certain level start a 12v pump.

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    I'm confused about the "step up" bit in your question! The Arduino GPIO will trigger the relay on and off, but the 12v for the pump is controlled by that relay (and never connects anywhere to the Arduino side of things). Can you clarify the "step up" part of your question?

  • @EnduroNerd
    @EnduroNerd Жыл бұрын

    So, what if you want to only use 1 power supply but still have the protection of isolated circuits? You can't really be creating devices with multiple power supplies. Can my external power supply be made to supply power to both the arduino and the relay module? Would I need to add in some sort of additional protection circuits to divide them?

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    If you use the _same_ PSU for both parts of the project then they are not isolated. You _could_ use the same primary transformer with separate secondary outputs (eg 2 x 5v output) to provide better isolation but, frankly, dual PSUs are the only way to give total isolation.

  • @mikesfarmmikesfarm3977
    @mikesfarmmikesfarm39777 ай бұрын

    are nano d4 and d5 not able to sink as much current as the other discrete outputs ? Those 2 outputs do not pull to 0volts, but rather 2.5vdc

  • @RalphBacon

    @RalphBacon

    7 ай бұрын

    On an Arduino Uno and Arduino Nano D4 and D5 are just normal GPIO pins and should pull low in the usual manner. Here's an official schematic: bit.ly/47YFExC

  • @nexuzinnovation-com
    @nexuzinnovation-com2 жыл бұрын

    hi Ralph, Recently I am working with relays. If the relay part number is "SRD-12VDC-SL-C", can it still be used for Arduino 5V and ESP32 3.3V as some said the "12VDC" means the relay is operating under 12V, does it means the JD-VCC have to supply 12V and VCC input is +5V DC ? Let's say, I am using ESP32 3.3V gpio pins, can the relay "SRD-12VDC-SL-C" works or I need to get "SRD-03VDC-SL-C" model of relay ?

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    I would be very careful about switching on a relay (coil) directly from _any_ GPIO pin, Ricky. They have very limited current available (40mA absolute max, but usually we limit to 20mA). I would use the ESP32's GPIO pin to switch on a MOSFET (or even a standard BJT) that then turns on the relay. You can use a simple 2N7000 MOSFET (I use this in my Workshop Heater Controller and it works well with the ESP32). This means a 5v relay will work because you have enough power from the +5v pin to run the relay. So what you really need is the relay model SRD-05VDC-SL-C, but if you limited the current through the transistor you could use a SRD-03VDC-SL-C running from the 5v supply line. Do not forget to put the protection diode across the coil otherwise your MOSFET (and even the ESP32 GPIO pin) will be damaged. If you need more information look at my Heater Controller schematic from video #225: kzread.info/dash/bejne/qn5ss5Wyo6aegZs.html The link goes to my GitHub here: github.com/RalphBacon/225-Project-Design-and-Implementation Look at the relay bit in the middle with the 2N7000 MOSFET.

  • @nexuzinnovation-com

    @nexuzinnovation-com

    2 жыл бұрын

    @@RalphBacon , thanks for the feedback, I will take note on your suggestions.

  • @mhchew1
    @mhchew1 Жыл бұрын

    Can we link those relay to our car starter motor?

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Good grief, no! Your starter motor will take many, many amps to turn the engine, far more than this relay will handle. You need a proper automotive part to do that.

  • @wouladjecabrelwen1006
    @wouladjecabrelwen10063 жыл бұрын

    Hi I think I have that problem with my ESP32 board, I have interface it with the relay after some times like 2 minutes of working nicely, it stops working at all until I have to disconnect to power supply (I supplied it from my computer) and I reuploaded the code. Tomorrow I will test your method and see. Thank you

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Be careful with the ESP32 GPIO pins, they are 3v3 and might not be enough to trigger the relay. Also, you should be monitoring the serial output of the ESP32 (at 115200 bps) as it will tell you why it's crashed (eg Panic, or Brown Out Detected).

  • @wouladjecabrelwen1006

    @wouladjecabrelwen1006

    3 жыл бұрын

    @@RalphBacon I succeeded to interface that, guess what I it works well. Thank you for the tutorial:) 😍😍😍

  • @sushildamle3449
    @sushildamle34492 жыл бұрын

    This has given me a much better understanding of the relay module and how to use it. Good stuff. Great video detailing and well explained. Thanks for the details. Can you offer any advice for me please- I want to use two numbers of ON / OFF or push switch (one each for relay) two do jobs separately. Could you please give a sketch for the same and code. Thanks in advance. Sushil Damle

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    I'm happy this has given you a better understanding of relays in general, Sushii, but I'm not able to write bespoke sketches for you! That part of the job is down to you. Break the project down into manageable chunks and think about how they might interact. Only start coding when you have the design at least "working on paper".

  • @sushildamle3449

    @sushildamle3449

    2 жыл бұрын

    @@RalphBacon Thanks for your guidance. I have tried doing the same, but I found that the turnout used to be energized where in I do not want the same as there is every possibility for the turnout getting burned out. Once I pressed the button track should change from Left to Right and when I either press the same button or have another button, when pressed track changes from Right to Left. The track should be energized only for the duration when button is pressed. Your advice please. Thanks once again.

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    When you press a button the pin will go HIGH or LOW (depending on how you have wired the button up). Whilst it is that state, the output (keep checking in the loop) keep the output HIGH. When the state changes then make the output LOW. Try this with a very small sketch and an LED to prove you can do this. Let me know how you get on.

  • @ryanjoshuaverano1382
    @ryanjoshuaverano13823 жыл бұрын

    Can someone help in my project? I used coin sensor and interrupt pin in arduino to catch the pulse that coin sensor sends. Everytime the relay clicks or goes from low to high, the arduino interprets it as the pulse of coin sensor. Any advice?

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Has the relay got a reverse voltage (aka back EMF) protection diode across the coil? You might also need a snubber across the relay contacts to prevent a pulse being generated, more details in video #131 kzread.info/dash/bejne/gXWhutupiNrRlco.html

  • @ryanjoshuaverano1382

    @ryanjoshuaverano1382

    3 жыл бұрын

    @@RalphBacon im using the same relay module you used in the video

  • @djs134
    @djs1346 ай бұрын

    Is there anyway u can tell me what’s needed to accomplish a simple task? So , I have 2 sets of 20 header pins, let’s call them source 1 and source 2. And I only have 20 pins as an output. I want to use a physical button to select between which source i want to use, either source 1 or 2 but never both at the same time. So in theory is basically a 20 pin ribbon cable switch so to speak with 2 separate sources and 1 20 pin ribbon cable out so to speak, with a switch to select which source I want. Thanks any help would be appreciated

  • @RalphBacon

    @RalphBacon

    6 ай бұрын

    I'm guessing that a mechanical switch for 20 cables is out of the question (it would be for me). I would consider using a 20-way (or 2 x 10-way) digital switch IC. These are integrated circuits that switch signals (only signals, no high power stuff) from one source or the other. Purely as an example, here's a link to a 4-way, DIL switch so can see what I mean: bit.ly/digital-switch-IC You would have to design a custom PCB to make best use of these switches with a socket for the ribbon cable connector - very do-able but worth researching (and perhaps trying out a smaller switch like the one above first). Depending on your soldering / PCB design skills, there are ICs in DIP format ( through-hole like above) or SMD QFP (square) with much higher switch counts.

  • @oLePi100
    @oLePi1007 жыл бұрын

    Thanks a bunch for the tutorial. For my current project I would like to do something similar but with 8 relays and a 24v supply. Do you think it be possible to control 8 output pins and 24 volt supply in a similar fashion? If so do you recommend any boards for the task?

  • @RalphBacon

    @RalphBacon

    7 жыл бұрын

    Hi Loren! The eight relays is not a problem; you can get the same style relay board I'm using with 8 relays. Search eBay or check out the same seller I used to see if he does the eight way variant. Now, when you say 24v supply, I'm hoping you mean that's the voltage you want to switch using the relays, not run the Arduino on? If you want to switch 24v using the relays that's fine, as the voltage on the relay pins is totally isolated from anything else. I hope this helps, if not then a more complete answer will have to wait for at least a week until I'm back from vacation - just let me know! Thanks for posting!

  • @charlesnielsen4379
    @charlesnielsen43794 жыл бұрын

    can you connect to arduino mini?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, you can, Charles. Any GPIO pin on any MCU will work because it only is driving an LED via the optocoupler.

  • @dasboseimbusch7079
    @dasboseimbusch707911 ай бұрын

    Is it possible to use a 12V external power supply?

  • @RalphBacon

    @RalphBacon

    11 ай бұрын

    Not for the independent relay power supply (JDD), if that's what you mean, because it only needs 5v. However, the relay can _switch_ 12v, no problem at all. However, if you have an external 12v power supply, that can power an Arduino, and then you can use the 5v supply from the Arduino to power the relay (VCC-JDD). The downside is that there will be no electrical separation between the Arduino power and the relay power - that might not matter to you. Alles klar?

  • @dasboseimbusch7079

    @dasboseimbusch7079

    11 ай бұрын

    @@RalphBacon Alles klar, danke ;-)

  • @mikhailkh8560
    @mikhailkh8560 Жыл бұрын

    But why HIGH - is turn it off, while it sent 5V in circuit, and LOW turn them on, while on circuit is just few mV?

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Because we are SINKING the current from VCC through the device and then through the Arduino to ground. So the output GPIO pin has to be LOW to allow the current to flow in that direction. Make sense?

  • @rabiulislam3406
    @rabiulislam34062 жыл бұрын

    my realy is good but when i connect the realy with aurdino it not working what should i do

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    Follow the example in my demo _exactly_ and it should work.

Келесі