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

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 335

  • @bgable7707
    @bgable7707 Год назад +5

    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!

  • @acadman4322
    @acadman4322 5 лет назад +27

    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 лет назад +2

      Glad you liked the video ACADMan, thanks for posting.

  • @garycrockett4477
    @garycrockett4477 4 года назад +1

    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  4 года назад

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

  • @LenzJimmy
    @LenzJimmy Год назад

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

  • @mickcoomer9714
    @mickcoomer9714 5 лет назад

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

    • @RalphBacon
      @RalphBacon  5 лет назад +1

      No problemo, Mick, glad it cleared that up.

  • @jayobrine8475
    @jayobrine8475 3 года назад

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

  • @iandawkins2182
    @iandawkins2182 5 лет назад +4

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

    • @RalphBacon
      @RalphBacon  5 лет назад +1

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

    • @iandawkins2182
      @iandawkins2182 5 лет назад +1

      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.

  • @jimbrownza
    @jimbrownza 5 лет назад +1

    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.

  • @allbeit582
    @allbeit582 5 лет назад

    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  5 лет назад

      Glad it helped you, thanks for posting.

  • @raygud5653
    @raygud5653 3 года назад +1

    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  3 года назад +1

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

  • @andreatanzi3191
    @andreatanzi3191 3 года назад +5

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

  • @inspiredtiny
    @inspiredtiny 4 года назад

    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) !!!

  • @steveedwards90
    @steveedwards90 5 лет назад +1

    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.

  • @MikeHoover1
    @MikeHoover1 3 года назад

    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 года назад +1

      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.

  • @oncledan282
    @oncledan282 5 лет назад +3

    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  5 лет назад +1

      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 5 лет назад

      @@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 !

  • @markowens9950
    @markowens9950 5 лет назад +1

    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.

  • @nicholasbarber5905
    @nicholasbarber5905 Год назад

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

  • @MyBigThing2010
    @MyBigThing2010 5 лет назад

    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 лет назад +1

      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.

  • @webslinger2011
    @webslinger2011 6 лет назад +1

    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.

  • @laidman2007
    @laidman2007 5 лет назад +2

    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.

  • @glentyan2505
    @glentyan2505 2 года назад

    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  2 года назад

      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. 👁️😜

  • @Risingnshouting
    @Risingnshouting 7 лет назад

    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...

  • @RalphBacon
    @RalphBacon  8 лет назад +1

    The code I used to demonstrate switching the relays alternately can be found here: db.tt/HlkvoTbM
    Let me know if you have any issues downloading the code (or understanding 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!

  • @CurmudgeonExtraordinaire
    @CurmudgeonExtraordinaire 6 лет назад

    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.

  • @KAVIAN_HZ
    @KAVIAN_HZ 9 месяцев назад

    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  9 месяцев назад

      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.

  • @Ahlg1990
    @Ahlg1990 3 года назад

    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  3 года назад +1

      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?

  • @shaunr9950
    @shaunr9950 5 лет назад

    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
    @russellmccallum3606 5 лет назад +1

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

    • @RalphBacon
      @RalphBacon  5 лет назад

      Glad you liked it, Russel, thanks for posting.

  • @Paulilmys
    @Paulilmys 2 года назад

    Best explanation yet! Thank you for the video.

  • @stefaneberle8969
    @stefaneberle8969 4 года назад

    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  4 года назад

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

  • @hedbergmicke
    @hedbergmicke 5 лет назад

    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.

  • @KaylebGarmon
    @KaylebGarmon 5 лет назад +1

    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 лет назад +2

      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!

  • @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

  • @yurkshirelad
    @yurkshirelad 3 года назад

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

    • @RalphBacon
      @RalphBacon  3 года назад +1

      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.

  • @yusufcali793
    @yusufcali793 7 лет назад

    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  7 лет назад

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

  • @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.

  • @Risingnshouting
    @Risingnshouting 7 лет назад +1

    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 лет назад +2

      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 лет назад +1

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

  • @vedaprakash2707
    @vedaprakash2707 2 года назад

    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.

  • @PavolFilek
    @PavolFilek Год назад

    Hi Ralph., do U have a video, where U send signal to ESP32/8266 , to which is connected relay, and another ESP32 has a microphone, and listen to voice commands ? I need to program something like this, to get rid of DC cables from battery to switch.. Cables will be only from battery to LED.

    • @RalphBacon
      @RalphBacon  Год назад

      Voice commands requires a lot more processing than what the ESP32 can ever give you. You would need, I would think, at the very least, a link to a cloud service (such as Amazon's Alexa service, which is long winded by easy enough to do) for this all to work.

    • @PavolFilek
      @PavolFilek Год назад

      @@RalphBacon Thanks, bud I have to do it myself I do not want cloud, a lot of work ahead for me to do it.

  • @mikesfarmmikesfarm3977
    @mikesfarmmikesfarm3977 Год назад

    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  Год назад

      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

  • @cyabd8515
    @cyabd8515 3 года назад

    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  3 года назад

      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 3 года назад

      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 3 года назад

      @@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  3 года назад +1

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

  • @saadet4
    @saadet4 5 лет назад

    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  5 лет назад

      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.

  • @pjay3028
    @pjay3028 2 года назад

    If the pin is set Low at the point of being set as Output, and you want to avoid this, shouldn't the pins be set High AFTER the Output command (lines 10&11) in the code, rather than before (lines 7&8)?

    • @RalphBacon
      @RalphBacon  2 года назад

      It doesn't really matter whether you set the pin's state (LOW, HIGH) either before or after the "pinMode" command.
      But if you set it _after_ the pinMode you may get a tiny (1μS) pulse which you might not want. The guru Nick Gammon once told me that setting it _before_ was in fact a bit safer.

    • @pjay3028
      @pjay3028 2 года назад

      @@RalphBacon excellent, thanks for your reply.

  • @wouladjecabrelwen1006
    @wouladjecabrelwen1006 3 года назад

    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 года назад +1

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

  • @djs134
    @djs134 11 месяцев назад

    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  11 месяцев назад

      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.

  • @bigpickles
    @bigpickles 4 года назад

    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

  • @drelectronics13
    @drelectronics13 4 года назад

    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  4 года назад +1

      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).

  • @markwatson7636
    @markwatson7636 4 года назад

    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.

  • @FOATE
    @FOATE 5 лет назад

    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  5 лет назад +1

      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 5 лет назад +1

      @@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 :)

  • @JeanDAVID
    @JeanDAVID 5 лет назад

    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.

  • @steverose2405
    @steverose2405 5 лет назад

    It was both useful and interesting. However, you didn't cover how to connect the relays to an output. I need to independently control four 24 Vdc solenoid air control valves. Two wires and three contacts on the relay output. The silkscreen on the board is a bit cryptic regarding what is NO, NC, and common.

    • @RalphBacon
      @RalphBacon  5 лет назад +1

      You need a four-way relay board first. It's the same as I showed but contains 4 identical circuits (with a common ground). Or four singles. Or two doubles. But there will be more wires that way.
      The relay outputs are zero voltage (that is, nothing is connected to them on this board) so you can see them as "switches" for the 24v and the valves. Use a COMM and NO relay connection. Your multimeter will show you that these two relay connections are normally open and only when the relay is energised to they connect.

    • @steverose2405
      @steverose2405 5 лет назад

      I am thinking that center contact is common and the ohmeter will tell me NO and NC.

    • @steverose2405
      @steverose2405 5 лет назад +1

      @@RalphBacon Indeed, Thanks!

  • @steverose2405
    @steverose2405 5 лет назад

    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 лет назад +1

      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 лет назад +1

      @@RalphBacon Good idea; thanks for your support!

  • @sadayghosh5894
    @sadayghosh5894 3 года назад

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

  • @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.

  • @mikhailkh8560
    @mikhailkh8560 2 года назад

    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  2 года назад

      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?

  • @sushildamle3449
    @sushildamle3449 3 года назад

    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  3 года назад

      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 3 года назад

      @@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  3 года назад

      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.

  • @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.

  • @m0gga
    @m0gga 7 лет назад

    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 лет назад +1

      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.

  • @Reptiledge
    @Reptiledge 8 лет назад

    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.

  • @MrIonutz2008
    @MrIonutz2008 4 года назад

    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 года назад +1

      @@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.

  • @marius86ar
    @marius86ar 6 лет назад

    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.

  • @rabiulislam3406
    @rabiulislam3406 3 года назад

    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.

  • @JohnBaxterWalker
    @JohnBaxterWalker 4 года назад

    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!

  • @GaryMcKinnonUFO
    @GaryMcKinnonUFO 5 лет назад +1

    Thanks for the detail, good stuff!

    • @RalphBacon
      @RalphBacon  5 лет назад +1

      Glad you liked it Gary, thanks for posting.

  • @jeff3741
    @jeff3741 5 лет назад

    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 лет назад +1

      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.

  • @ryanavery7980
    @ryanavery7980 4 года назад +1

    I think its an output pin because you are writing to it, not reading from it.
    edit: I'm talking about at 3:36

    • @RalphBacon
      @RalphBacon  4 года назад

      Can you just put this into context, please, Ryan? At which point in the video does this come up? From what you say if you are writing to a pin it will probably be an output pin - but if you write to an input pin it just turns on the pull-up resistor!

    • @ryanavery7980
      @ryanavery7980 4 года назад

      @@RalphBacon 3:36

    • @RalphBacon
      @RalphBacon  4 года назад

      Right, the point I was making at that point in the video was that although the current flow was coming IN to the Arduino (from VCC and the diode), the pinMode was still an OUTPUT - something that confuses beginners.

  • @steveedwards90
    @steveedwards90 5 лет назад +1

    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 лет назад +1

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

  • @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?

  • @bloodswarms
    @bloodswarms 7 лет назад

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

    • @RalphBacon
      @RalphBacon  7 лет назад

      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)

  • @mayurchauhan4219
    @mayurchauhan4219 4 года назад

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

    • @RalphBacon
      @RalphBacon  4 года назад +1

      Glad it helped, Mayur!

  • @clems6989
    @clems6989 2 года назад

    So, why not drive the output HIGH to activate the optocoupler.. [Reverse the polarity's]

    • @RalphBacon
      @RalphBacon  2 года назад

      Because the datasheet suggests that the LED inside the optocoupler is connected to +5v and the current sunk (sinked?) via the μController.
      However, as the terminals are totally isolated I suppose you could drive the LED from the μController (instead of +5v) and connect the other end to GND, that should work too. But do check what the manufacturer of the board has done, they might have made assumptions on how you're supposed to connect it up.

  • @FOATE
    @FOATE 5 лет назад +1

    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.

  • @chrism3790
    @chrism3790 4 года назад

    Why do you connect VCC and then set the pin to HIGH to keep it closed, instead of connecting the ground and setting the pin to HIGH only when you want it opened? I read some comments saying you can only switch on relay at a time like that, but I'm not sure I understand why... Is there something I'm missing? I have my relays coming in tomorrow and don't want to blow up my ESP8266 hahaha

    • @RalphBacon
      @RalphBacon  4 года назад

      I don't fully understand the question, or what you think I'm doing, but I can tell you the Esp8266 will SINK the current for the LED on the relay board's optoisolator when set LOW (HIGH is off). So the other side of the LED is connected to VCC. Take a close look at the circuit diagram in the video. Still confused? Let me know!

    • @chrism3790
      @chrism3790 4 года назад

      @@RalphBacon Thank you! My parts just arrived. I'll be trying to figure it out this weekend :) will definitely revisit your video then.

    • @chrism3790
      @chrism3790 4 года назад

      @@RalphBacon Ahhhhh now I understand!!! Took me a bit of tinkering, but your video makes total sense now! Thanks!

    • @RalphBacon
      @RalphBacon  4 года назад

      Great stuff! don't let the magic smoke escape!

  • @karamchris
    @karamchris 7 лет назад

    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!

  • @dannyrodman5075
    @dannyrodman5075 6 лет назад

    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

  • @RD-ni7qe
    @RD-ni7qe 4 года назад

    Such a clear explanation, thanks!

  • @ryanjoshuaverano1382
    @ryanjoshuaverano1382 3 года назад

    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 года назад +1

      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 ruclips.net/video/OAmXypXwkeg/видео.html

    • @ryanjoshuaverano1382
      @ryanjoshuaverano1382 3 года назад

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

  • @jeremylambright1658
    @jeremylambright1658 3 года назад

    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/RUclipsVideoList-RalphBacon

  • @dekipet
    @dekipet 6 лет назад

    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!

  • @dasboseimbusch7079
    @dasboseimbusch7079 Год назад

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

    • @RalphBacon
      @RalphBacon  Год назад +1

      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 Год назад +1

      @@RalphBacon Alles klar, danke ;-)

  • @alexus9915
    @alexus9915 7 лет назад +1

    why is there a shortcut between JD-VCC and Q1?

    • @RalphBacon
      @RalphBacon  7 лет назад

      Now, Alexus, when you say "shortcut" between JD-VCC and Q1 I'm assuming you mean the VCC to JD-VCC jumper? Remember that the JD-VCC is the power to the "other side" of the circuit - that is, the transistor (Q1), half of the opto-isolator and the relay itself. By shorting JD-VCC to VCC we power the entire board with power from VCC. Not truly opto-isolated, which is why the option is there to power the "other side" independently". The video shows the schematic at 02:07 which makes this clearer. This is then covered in some detail in the video when I power the circuit from two sources. Perhaps I have misunderstood your question so do let me know whether I have wrong end of the proverbial stick!

    • @alexus9915
      @alexus9915 7 лет назад

      Sorry i mean "short circuit" not shortcut...
      At 2:07 between the wire JD-VCC and the collctor of Q1 is a wire-bridge, wich is parallel to the free-wheeling diode and the relais.
      What does this wire do? A Short circuit? :D

    • @RalphBacon
      @RalphBacon  7 лет назад +1

      How strange. Not your post, Alexus, that was very observant indeed. The circuit diagram for this device is basically WRONG. And only you spotted this! Obviously there should be no link between the collector of Q1 and JD-VCC (not unless you want the power to be shorted to ground as soon as Q1 was switched on). So basically the collector of Q1 should go to one side of the relay coil and the anode of the diode, which are shown correctly. No connections between the collector of Q1 and JD-VCC. I just cannot believe that (a) I did not spot this when I did the video, and (b) that in all that intervening time no-one else has mentioned it (and the Arduinites on this channel are a pretty observant lot). So thanks for posting, I shall make a small comment in the video description about this (and credit you, obviously). Thanks for posting.

    • @grundell2930
      @grundell2930 7 лет назад

      Thank you for this post. I was thinking the same thing. Good pick up Alexus

  • @JeremydePrisco
    @JeremydePrisco 6 лет назад

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

    • @RalphBacon
      @RalphBacon  6 лет назад

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

  • @oLePi100
    @oLePi100 8 лет назад

    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  8 лет назад

      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!

  • @kennmossman8701
    @kennmossman8701 5 лет назад

    a somewhat common mistake is using a mechanical relay when a solid state relay or device is a better choice;
    1) fast switching speeds (on/off/on)
    20 longevity
    3) fast turn-on
    4) High voltage or current loads
    5) need to have minimum current drain

    • @RalphBacon
      @RalphBacon  5 лет назад

      But you did miss one thing, Kenn, that is not so good: HUGE size (compared to a mechanical relay) especially if we factor in the ridiculous heatsink for higher currents. I have...
      I have resisted doing a video on my SSR precisely for that reason. It certainly would not fit in the original consumer unit (fuse box) so it would have to be mounted externally, suitably insulated in a box which then requires drilling etc.
      Some relays are fakes, of course. Rated at 20A and can barely conduct 5A without melting (as other videos I've done have shown). But I've sourced (from a respected UK company) two very nice, high current mechanical relays, with all the correct CE certification that would do the job. But, I'm still thinking of that SSR... What do do!?!

    • @kennmossman8701
      @kennmossman8701 5 лет назад

      @@RalphBacon :) to be sure relays have their advantages......including zero loss to the load, multiple poles, isolation .....

    • @kennmossman8701
      @kennmossman8701 5 лет назад

      @@RalphBacon personally I'd go with the SRS!

  • @frankalvarez7387
    @frankalvarez7387 6 лет назад +4

    Too late, RIP my ESP32 will be missed i ended up shorting VCC and GND :(

    • @RalphBacon
      @RalphBacon  6 лет назад +5

      Maybe not. Shorting out those two pins would overload the AMS1117 voltage regulator but your ESP32 should survive (the power doesn't flow through the ESP32). If you can find the AMS1117 (might be an NCP1117) you could replace it if your SMD soldering is any good, or just attach 3.3 volts to the VDD pin. If it springs back into life you must somehow replace the voltage regulator as that also receives 5v via the USB plug to generate the required 3.3v (or just keep the 3.3 v supply going). Worth playing about with.

  • @khulileasherembizela3283
    @khulileasherembizela3283 4 года назад

    hey Mr Ralph can you please help me with my project here about 2 sensors , LCD, RELAY MODULE AND ARDUINO ITS my first time using them.

    • @RalphBacon
      @RalphBacon  4 года назад

      You need to start with some simple things first, Khulile. Try getting an LED to flash (and know why it's doing it that way). Then move onto the relay module and get that working. Then do the sensor... the only way to succeed in a project is to break it down into small, manageable chunks. That way you learn how to do each part and can build upon your knowledge. There are plenty of videos on this channel for beginners like you, but you must walk before you can run.

  • @juliusferrer2071
    @juliusferrer2071 10 месяцев назад

    i tried to remove the ground pin among vcc and IN pins to one of my 4 relay module and now the led wont work...i think i broke it :< just like what you did on 8:07

    • @RalphBacon
      @RalphBacon  10 месяцев назад

      I don't think you can break a relay module just by removing the ground pin but you can check it's operation in two stages; the opto part first, followed by the actual relay power.
      If the LED lights up then it will all work. Remember you need to have the GND connected in all cases.

    • @juliusferrer2071
      @juliusferrer2071 10 месяцев назад

      ​@@RalphBaconIve absorb many infformations(including yours) in my head, still cant reach solve my main problem..

  • @billbobby461
    @billbobby461 10 месяцев назад

    can i use high trigger or are all relays low trigger? lazy and dont want to rewrite code ha

    • @RalphBacon
      @RalphBacon  9 месяцев назад +1

      Many require the GPIO pin to go LOW (to _sink_ ) the current, but I have a couple that have a jumper and allow high OR low usage. I bought them from Amazon as I was in a rush but, frankly, the prices are sometimes equivalent to the Far East markets, once they have added on VAT and postage. Here's a link: amzn.to/49rzrL5

    • @billbobby461
      @billbobby461 9 месяцев назад

      @RalphBacon I had done a little more research since writing the comment and found ones that can do both.
      Your videos are great BTW, used one to learn to code an arduino to work a solenoid hydraulic valve block for a piece of farm equipment.
      Now to go from code and simulation on the breadboard(which was useful, damn button bouncing!) to a prototype pcb for a controller. Any advice for a total novice?

  • @johnskii
    @johnskii 6 лет назад +1

    Great video - very informative, thanks!

    • @RalphBacon
      @RalphBacon  6 лет назад

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

  • @hullmanhunter
    @hullmanhunter 7 лет назад

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

    • @RalphBacon
      @RalphBacon  7 лет назад +1

      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 7 лет назад +1

      hullmanhunter Amazon sells them too

  • @johanoberg149
    @johanoberg149 3 года назад

    I can't get this setup to work. If I use the hopper on and power JD-VCC with VCC from Arduino it works fine.
    But if I remove the hopper and connect an external 5V source into JD-VCC the clicking stops. The LEDs is still blinking but there is no power going to the coils. What can be the problem here? I've checked the voltage and it is indeed 5V going in to the JD-VCC.

    • @RalphBacon
      @RalphBacon  3 года назад

      Hmm. Let's check:
      1. You have removed the jumper.
      2. VCC from the Arduino goes to (one of the) VCC pins on the module.
      3. The IN1 (incorrectly named) on the module goes to a GPIO pin on your Arduino and lights the LED when you make that pin LOW.
      4. An independent +5v goes to JD-VCC.
      5. The GND from the independent +5v goes to GND on the module.
      So there are only TWO wires from the Arduino running to the module.
      There are only TWO wires (+5v and GND) connected to the module from the independent power supply.
      Is this your setup, Johan?
      As a further test, you can also connect +5v and GND from the Arduino UNO board to the module (INSTEAD of the independent power supply, do not connect both) and it should also work.
      Let me know!

    • @johanoberg149
      @johanoberg149 3 года назад

      ​@@RalphBacon Thanks for the quick respons Ralph!
      Yes this is the exact setup that I've been using, but nothing happens except that the LED is blinking.
      How do you mean in the last note? That I connect the arduino +5V to VCC and JD-VCC and the Arduino GND to GND on module?
      That should be the same setup as if Im using the hopper right?
      However I want to use a setup that uses an independant power supply. Perhaps something is broken in my Relay, I'm going to make a try on another relay later today.
      Thank you!

    • @johanoberg149
      @johanoberg149 3 года назад

      @@RalphBacon I couldnt wait to try it out on a new relay, so I did it during my lunch break. However it still doesnt want to work with an independent power supply.
      I recorded a quick video of the setup with and without hopper, hopefully you can see something - the video is shaking a bit unfortunatly.
      ruclips.net/video/OA9JGQ1QUNg/видео.html
      In the end of the video I reconnected the GND from the arduino that made the coil activate, but it doesnt switch back and forth.
      But yeah, I'm clueless about what the issue could be.

    • @RalphBacon
      @RalphBacon  3 года назад

      You bring a whole new meaning to the words "Shaky Video", Johan 🤣
      Now that relay board is not the same as in my video; it's a Velleman quad relay board, possibly a VMA400, can you confirm the exact model you are using?

    • @johanoberg149
      @johanoberg149 3 года назад

      @@RalphBacon that is a WPM400. But I have also been trying to use a Sunfounder 2 relay module.

  • @ahk501
    @ahk501 2 года назад

    I can't find 30a relay modules with with seprate power pins
    Can anyone suggest one?

    • @RalphBacon
      @RalphBacon  2 года назад

      Depends where you are in the world, Alex. In the UK try RS or Farnell. In the US I'm sure Mouser or DigiKey must have something?

  • @Dralsoft
    @Dralsoft 2 года назад

    Is it possible to power the arduino from the relay?

    • @RalphBacon
      @RalphBacon  2 года назад

      It can't power the Arduino that controls the relay (a bit like pulling yourself up by your own boot laces). It could power another Arduino though.

    • @Dralsoft
      @Dralsoft 2 года назад

      @@RalphBacon I see. What about from the main grid?

    • @RalphBacon
      @RalphBacon  2 года назад

      The relay can switch mains voltages, if that's what you're asking.

  • @jakel1977
    @jakel1977 4 года назад

    Thank you. Very good explanation

  • @prashantsakre6577
    @prashantsakre6577 4 года назад

    This is good exactly I needed...thanks

  • @ernestosaboia
    @ernestosaboia 5 лет назад

    Great information, and well done! Thanks mate

    • @RalphBacon
      @RalphBacon  5 лет назад

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

  • @Defconstructivism
    @Defconstructivism 4 года назад

    can you connect to arduino mini?

    • @RalphBacon
      @RalphBacon  4 года назад +1

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

  • @berliandro
    @berliandro Год назад

    You saved my life

    • @RalphBacon
      @RalphBacon  Год назад

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

  • @eraslanaslan9059
    @eraslanaslan9059 Год назад

    This video is very helpfull thank you sir:)