Very well explained. Clear, concise and straightforward without losing the detail of the topic. To explain things like this takes real skill, great work.
Holy CRAP!! This is an AMAZING tutorial. I just spent the past 6 hours learning everything you explained in 10 minutes. Wish I had found this tutorial first, but I guess the past 6 hours weren't completely lost since I did end up learning something. But man....I mean really, this is just incredibly well done. Thanks! you rock!
I know you haven't uploaded in quite a few years, but your tutorials really helped me a lot when I was getting started with the Raspberry Pi controlling electronics
9:55 - THANK YOU. This is in fact the most important part of your video. Because how can any RPi or other project enrich your life, if it … well, _ends_ it? Safety first. Always.
Thank you for this super video! This helped me to get my 8-Relais Optocoppler running and I got the knowledge from your video how it is working and has to be connected. My 8 Kanal Channel 5V Relais Relay Converter Modul worked fine with VCC and JDVCC connected via the jumper! I'm looking forward for new videos as they are very interesting and good produced! Thanks for your time you spend here!
effin awesome.. covered alot of material but i appreciate the calculations and circuit explanations such as using beta value to calculate the necessary current limiting resistance
I've managed to get the board working this way: - using the jumper for JD-VCC and VCC - connecting the VCC pin of the input pin group to one of the 5V pin of GPIO - connecting the GND pin of the input pin group to one of the GND pin of GPIO - connecting the IN1 and IN2 pins to GPIO pins set as OUTPUT and initially set as HIGH
Awesome explanation of what going on here, saved me a lot of reasearch effort. I wouldn't normally sub to such a channel, electronics is more like an 'video on demand' sort of thing for me, but your videos are top shelf.
You certainly can do that, and in both cases you will need 1 GPIO pin. Either a GPIO pin on Vcc, with the control pin connected to ground, or Vcc attached to 3.3V and a GPIO pin connect to the control pin (like in the video). The only time an issue would arise would be when using more than one relay on the board. Because the two relay modules share Vcc, a GPIO pin on Vcc would affect both modules. Of course, if you're not using the board, your suggestion would work perfectly fine.
Yeah, a single transistor and a relay will do the job just fine. The optocoupler is there only for protection, and I made a point of discussing it as a large number of relay boards use it. Unless you're going to use a separate power supply to connect across the relay coil, you might as well not use the optocoupler as your bypassing the electrical isolation by connecting anything on the right side of the optocoupler to your Raspberry Pi.
You might be able to control the relay coil with 3.3 V (a gpio pin). On my board, one relay worked this way, and the other didn't. So it's definitely something you can test out with your own relay board, as relay modules are not all created equal. A transistor is also an excellent solution, and it's what I tend to connect my GPIO pins to. The only reason I didn't suggest them with the board is because I wanted to avoid using additional components.
Thanks, (8:34) Had problems with mine running at the 3.3v from the raspberry and switching 230VAC 2A. Changing the R1 (1kΩ) Resistor to a 510Ω one worked for me perfect!
An old video for sure, but rather than a current limiting resistor on the opto-isolator, one could simply use a current regulator. These are available with a fixed mA limit (with 2-pins in an SMT package), and can have a VMax of 220Volts (like a CL220K4: www.digikey.com/product-detail/en/microchip-technology/CL220K4-G/CL220K4-GCT-ND/4918704). This way it basically doesn't matter what voltage you put on the opto-LED circuit or the relay control side of the isolator (within common voltage ranges of course). Using a current regulator means your current is capped at the design current and you never have to go back in an recalculate/rework a constructed circuit once built. To drive the relay coil a MOSFET and a current regulator would again be more flexible. 60mA can be current regulated with monolithic current regulator parts (two 25mA and a 10mA in parallel gives you 60mA, so does three 20mA regulators in parallel). Using those regulators would then ensure that the coil only ever see the POWER it was designed for, and the relay would work with a supply of 5VDC up to the power rating of the current regulator. To protect the MOSFET, a zener would need to clamp the gate to under its maximum voltage, and a current regulator would need to limit both the current conducted by the opto-trans-out, and the zener. Since a MOSFET gate only needs to be charged with a voltage/current and not driven by a continuous current, this value can be very low (sub-milliamps) - which reduces the total circuit power draw. Remember, ten 6mA LEDs draws as much power as one 60mA relay coil.
Great video! I believe I'm using the same relay board as you, and only one of the relays would turn of if I connected Vcc to 3.3v. I'd measured the voltage across the coil and it was 2.7, so I guess that wasn't quite enough. All works well if I use Vcc = 5v. I assume that slight differences in the transistor or relays would affect this. Now the coil voltage is about 4.6, which works great.
good advice can you make another video showing best safe way to run ac through the relay as best you can as i dont mind danger but want things to stay working, maybe by using different relays and an inline fuse etc for example many thanks
This helped me a lot using the pre-built board, but for some reason did not quite work. I found that I had to send +5 to VCC and VCC-DJ, and that I did not need a ground. With +3.3 at VCC, the relay never got more than 3V across the magnet
Matt Brennan Hi, for me it didn´t work either, i have the model b rev2 rpbi and i guess the 3.3v gpio data is not giving much current. I see the led blink at the relay control and the relay is not giving output voltages when it should, also i´m not hearing the relay sound switching. Did you use the jumper to provide 5v to JD-Vcc and Vcc, and what do you mean by not needing ground. thanks
If I wanted to make this into an "active high" relay, could I feed the 3.3V GPIO output to Vcc, 5V to JD-Vcc, and then tie GND to the GPIO input of the board? That way the optocoupler has 3.3V across it (and the resistor) when GPIO is HIGH and 0V when GPIO is LOW?
Wait I'm a bit confused. In the first circuit, the current goes from 5V -> GND and that makes sense to me. In the version with the board however, it goes from 3.3VDC -> GPIO pin. It seems to me like the current comes out from VCC and it comes out of the GPIO at the same time that it would be a problem. Does that not reverse the way that things work?
The last part of the video. Telling to connect 5V Rpi to JD-VCC Pin6 Rpi to GND pin7 Rpi to IN1 pin1 Rpi to VCC Does this circuit will not damage anything? especially the raspberry? I'm confused because you introduced to us the using of Resistors,Diode,transistor and Optocoupler. So is it fine not to use those? just the direct connection from Rpi to Relay then? Need ASAP reply . This is for our thesis project
Gaven, im doing a project for a course in my college and i want to create a wireless door lock, what i had in mind is a relay, electromagnetic door lock and the raspberry pi connect all those together and i could build it, so am i missing anything or should i be using something much simpler design ?
In the video you used a GPIO pin of the Raspberry Pi to control an optocoupler which in turn controlled a transistor which in turn powered the relay. Was the optocoupler really necessary? Couldn't you have just used a transistor and a relay? I didn't need an optocoupler to control a small relay with my arduino, just a transistor. Or is the optocoupler there because you don't want the GPIO pin to be destroyed by some kind of voltage spike?
i am fixing to purchase a rasberry pi, relay board, and touch screen. i want to make a 12v switch box with a touch screen. have any of yall already written a program for the interface? im in the process of trying to figure out python and figured if someone already wrote a program, it would save me a LOT of time
I could only get this to work by connecting Vcc to the 5v pin on the RPi and connecting Vcc to JD-Vcc using the jumper. When I connected Vcc to 3.3v rail, the red LED would light but the switch would not activate (there was no audible "click")
Why is the optocoupler connected to the 5v power supply?? Couldn't it be connected to the GPIO out directly? The 3.3v generated by the GPIO pin can power the the optocoupler.
Hi. Could you explain more about the extra power requirements? Just to clarify, you need 2 power supplies, a USB powering the pi which sends some of the required power to the relay for the LED, and a second power supply connected directly to the relays outward face and the ground for the LED, right?
Also, is the point of using the relay to isolate the 9v power source so it doesn't interfere with the 5v arduino board and blow it up while maintaining control of the external object with the board?
A voltage source represents a "potential difference" in electric terms. So, the GND rail for each source is NOT an absolute 0 value, and also the independent GNDs will not be on the same level as each other. Instead of thinking of the + and - terminals as 5V and 0V, you can also think of them as +2.5V and -2.5V (i.e. the potential difference is still a 5V supply), or even +4V and -1V (it is still a 5V supply). There is no such thing as absolute 0V GND (the GND on different supplies will be different and hence represent a voltage potential difference even between independent GNDs). The power from the positive terminal from one voltage supply must return to the negative terminal of it's own supply, so this is why you need circuit isolation. If instead the entire circuit could be solely powered from the micro-controllers own power rails then there would be less need for isolation since you could instead limit current through the use of resistors, but in this case if you are controlling actuators and motors then the arduino cannot possibly supply the needed current (or voltage) required for those actuators to power the motors, and some components in a circuit just need more than 5V to work. You need voltage-source isolation in this situation.
mains are some scary things to mess with 12 volt dc systems are as well but I been messing around with it and havent burned zaped or blew anything up with whats your thoughts on a 12 volt set up at around 220 ah drawing .750 ma @ 5 volts 24/7? its just a common led think its a bad ideah for light
Very well explained. Sadly so stones there is a module designer who thought "JD-VCC?, Jumper?, Wait let's just hardwire that" arduinodiy.wordpress.com/2018/09/04/the-16-relay-module-and-the-raspberry-pi-not-an-ideal-marriage/ Just a remark, you suggest that one option is to desolxer the resistor and replace it with a seeker one. I am not sure that is the right choice: the voltage drop will remain the same, but now there will be a higher current owing. If any you should replace it with a higher value. In that case desoldering isn't necessary, just add one at the input lines. Having said that, I think with the 1k, the optocoupler and LED in series the 1.7 volt drop the current flowing will be practically zero
Couldn't you have just powered the relay coil from the GPIO pin of the raspberry pi or connect a gpio pin to a transistor which controls the relay coil?
i use module relay when no load connected to the relay every thing well when it connected to 220ac it take a time and then the lcd display strange symbols the power of the relay and the lcd from arduino
Oh man, you fucking helped me :D I love you :) I didn't know that the GPIOs provide 3.3V and i also didn't know that the inputs need 5V to get triggered^^ So i have a few questions and i hope you could answer me some of them ;) 1. Why is a octocoupler used to trigger the transistor? I could just power the Transistor with a GPIO pin directly? 2. What are the cons of providing the Optocoupler with 3.3V if you just have GPIO with 3.3V outputs?
PaYtrIxHD The optocoupler acts like a switch, such that it is used to isolate the circuit so that it will prevent any damage to the Raspberry Pi when working with higher current and voltages. Therefore, it only activates at certain states. Since the Raspberry Pi has a low current output, it would be wise to use an optocoupler to keep things separated so as to not fry the Pi when messing with higher voltages/currents. Check out his optocoupler video where he goes more in-depth. Good stuff.
1:30 How do you know that the required current is about 60ma? I looked at the datasheet here: www.ghielectronics.com/downloads/man/20084141716341001RelayX1.pdf It seemed to be different than what you mentioned.
I am trying to use a Keyes 4 ch solid state relay It's a red circuit board with blue terminal. there are tons for sale on ebay. I can get the leds on the inputs tp go on and off with the Raspberrypi, but the relays themselves do not change state. I have connect them up using a 5 volts, a 22o ohm resistor and an led. The led will sometimes light up as it should, but then it stays on. Anyone know what I am doing wrong? Any help is appreciated.
hi could anyone help i would like to control a 4 channel relay with raspberry pi to turn on -off in sequence sometimes all together sometimes two at a time -one at a time and be able to alter time between them thanks
☠☠☠ Just remember folks the relays on that panel are NOT safe to use to switch MAINS VOLTAGES directly - the air-gap is not good enough (needs to be around at least 7 or 8 mm for 220-250V type voltages) i.e. the space between the bits of metal that would be connected to the Mains are not far enough from the bits of metal that are connected to the RPi and which you might touch... ☠☠☠
I don't agree with it. It's the only video, i found on youtube, where the function of an optokoppler-relais is explained! I think it's worth knowing, what you connect here instead of frying your pi!