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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well welcome back now today we're going to talk about a very innocuous looking object and it is this two channel relay module now you wouldn't think something's is simple and it's fairly straightforward and frankly somewhat unexcited could cause such a stir but let's talk about this and see exactly where the problems that I've found on the Arduino forum stem from basically this is a dual relay controlled by the Arduino and the great thing about it is that these little tiny chips on here or in fact opto-isolator z' which means that the Arduino when it's running through here has absolutely no knowledge at all of anything that's happening up here it's treating it effectively like an LED so your Arduino is effectively protected with anything happening at this end the sharp end where you might be connecting mains electronics even and all it knows about is an ethyl LED buried inside these plastic modules those plastic modules are in fact el8 one-seventh and I don't think we're gonna get close enough to see them but you never know you might but it just make them out there in fact they're probably also download most things on this camera anyway there's some look at the the computer screen here now you'll see the yelling one service I've only got four four pins on them which basically means one half is connected to an LED and the other half is an open-ended transistor in fact I have a circuit diagram we can have a look at which is this one here and it's this element here we're interested in as you can see pin 1 and pin 2 are a simple LED and pin 4 and 3 it's an open base op so transistor really so from the aspect of the yard we know all it knows is it's driving or at least not driving it's sinking the current through the LED if you notice here it says BCC so you supply your 5 volts here the module that's that's this module here already has a limiting resistor on it here and it has an LED to display which challenges is that's on now although there's two on here you really can treat these as two identical hearts in fact this whole picture look it's two of the same though identical so what this means for the Arduino is that if you want to drive for some some noisy electronics or some other types that you couldn't possibly run off an arduino mains for example or just some heavy-duty stuff even motors this isn't absolutely ideal way of doing it because where Arduino is protected to the nth degree however the way this module here is set up by default means you're not quite as protected as you might think you are and we'll have a look at that in a second first of all though let's just connect some four lines of code or thereabouts to switch this on and see how it all hangs together so if we go to our card window this one here male this is simplicity itself all we're using are two digital output pins in this case three and four I've chosen these arbitrarily but it could be any two you choose we're setting them up as output which confuses some people because you think hang on them and he'll fool you said we were sinking current or supplying it but you have to set the output pin as an output pin whether it's supplying or sinking it's the most certainly not input mode you might be thinking that the current flows into the Arduino and should therefore be an input pin no input is means a digital input not not current type input so we define them as output and then because of the way the circuit is defined we're supplying current on VCC so that's just a five volt supply flow from your Arduino board it comes on air flows through the LED back through this other LED that you can see rather than being buried inside this black plastic package and then where it says in one that goes to the pin on your Arduino namely either pin 1 or pin 2 and as we've got two channels will define two so initially we're going to define one of these as high which effectively switches that one often prevents current running through it and one we're going to define as low which allows the current to run through it now just as in the case of when you're supplying current now do we know a 40 milliamp total is the absolute maximum per pin and as you can't supply all the digital pins at 40 milliamps and loading it away with it either there's a maximum which I can't remember off the top of my head but we're not going to be doing very much here we're probably talking 10 milliamps maybe 20 tops because I've thought it is going through two LEDs then we're going to delay for a second and then we're going to flip the relay output or at least the digital pin output which will in turn flip the relays so what was high on pin 1 is now low and what was low is now high so current will flow into relay pin 1 but will be prevented from glowing integrally pin 2 and then we're gonna have another little delay but slightly long one so let's see how this all hangs together when we connect it up to the board and I have preloaded it because on that's very frustrating watching code download right so there it goes it's loading now and the first one is on and off and on and off and basically these two relays just toggling now so this one's on to begin with then he goes to this one then it comes back here and the delay is short one this one one second and three seconds on here just like the code showed now you might think well that doesn't seem very difficult actually is what I expected true however if we look at the circuit diagram again and what's happening here now this circuit diagram shows or expects their to be a supply here on VCC for the LED in the opto coupler and you notice there's a supply here JD VCC it doesn't actually show where that supply is coming from but on the board show the board quickly as a little tight jumper here there's there's JD VCC and that is connected by default to the VCC pin that we have supplied here on this board which is coming from our Arduino now to hammer Arduino to supply the LED is absolutely fine having our Arduino supplied effectively the other side of the circuit he's not a good idea because it means your Arduino is no longer electrically isolated from this circuit apart from being connected on the positive side we've also had to make a return journey on the ground side as well and that's not really what we want just have another look at that circuit again and you'll see that what we really want is two pins we want power coming in and then the Arduino to sync it here so really we don't want the power supply on here to be on at all and we don't want the ground be on here at all what we want is just that pinning source out will allow the power to be connected to this side of the circuit and only this side of the circuit but what we're going to do is disconnect this other side so that no longer has any power at all this side is now electrically dead and separate from our Arduino power comes in here through the optimum Isolators and this sunk are the two pins on the Arduino alternatively now as you can see the lights are still already flashing or still flashing because there is a circuit here that is being rained what's not happening is that the relays are being switched on them because they've got no power to switch on what we really want is a separate isolated power supply to supply this half of the circuit if we look back at our two circuit diagram we're talking about this part here and it is totally and utterly separate from anything at this end even though this little I see this opto isolator is one package internally there's no connection between the LED and the opto transistor the other side so let's connect up an external power supply and see what happens now I'm gonna connect this up and then hopefully I'll be able to speed up the video because it must be very frustrating watching somebody connects up was here goes and there we are now I'm running this little tiny breadboard power supply here and it's only going in to the other half of this circuit so this half the Arduino side knows nothing about what's going on the other side all the Arduino thinks is it's lighting up an LED and in fact it is lighting up real LED as you can see plus the one you can't see inside these optocouplers now so all the Arduino knows about them there's no need to have the ground control line connected at all you just have power in and then being sunk by the Arduino pins brilliant so now we have the power supply that's totally separate supplying the other half of this circuit remember by the other half we mean all this here so the opto transistor the power transistor here the relay coil and the protection diode all this is fired up by JD VCC and that's what we're supplying now though this alternative power supply so what are the things then on the Arduino forum have been mentioned that even I sort of was unaware of to be quite honest but apparently there is a an issue with this board that has caused several people to raise queries about what was going on well for that we need to look at our code again and think about what's happening so back in that kind of window here we define our pings as has output pins fine unfortunately instant that we've defined them as output pins they can either sink or source current now initially the pin mode is going to be sent to output but the way current can flow is they are both set low instantly so once this command has been executed and once it's starting writing doing this command here pin 1 is already low because we've not told it otherwise and apparently in the time it takes for this command to be executed current is starting to flow through relay pin 1 because we haven't said it high until here and that can cause problems for some circuits just in those few microseconds that occur between this statement on pin on line 7 and this statement here on line 12 obviously the longer the delay between setting the output and setting the relay pin high the worse the problems going to get so the advice given on the Arduino forum is to set the relay pin 1 and 2 to high first so if we look at the code window yourself added these two lines here to set them high initially then we set them as per as we always did to output and then high and low respectively now and you can see it from the circuit the board down here nothing really has changed if I reset it off it goes nothing must just happened except that the relay that turns on first is now not trying to turn on before we actually allow it it's prevented by these two statements here I would suggest that you look at the digital ride home the hardware now forum because it does contain more information about this but it's just a point to be aware of that if you said something as output it will allow current to be sunk immediately until you set it high which may affect so it's especially timing critical ones so let's just have a quick look at what you might be able to buy for these relays now as you can see here on the screen this is the same smart one probably at a price most people will look elsewhere to be kiwanis now as you can see this is a dual one though and I think some of the clowns are already based on this same small one now you can city down here in this little picture here you can see there's a quotient one quad with the network controller I've even seen them up to 16 relays on the board so if you've got enough pins you might be pushing out an Arduino Uno but you can get quite a few relays connected now if we go over to ebay or it quickly now this is the sort of thing I've got a simple Joule relay module 99 pence which is about what one dollar 40 these days even listen about that one dollar 40 now that's from the best I'm not endorsing the seller by any means it just happens to be one that came up on eBay when I search for and as I say you can get single relays dual quad 8 16 probably a whole ton more but they're all based on very much the same thing we have these little opto couplers built in good stuff ok so there it is that's where you can get back to the main video now there's one final point that I'm going to talk to you about on this board and for that I'm gonna have to disconnect it all so this is how the board is supplied with a jumper on here which says JD VCC and it's automation to put a jumper on to VCC which is the same pin as this one here underneath they're connected which means your Arduino supply will also supply the other side of the circuit and for testing this is absolutely fine and indeed for some circuits this is absolutely fine as long as you're aware the Aurora ad we know is not actually up to isolated from this I'd always recommend using a separate supply however that's not the downside this jumper looks like it should be moved either from here or to here I mean after all that's what jumpers do wherever you do do not do this all you're going to do here is short out VCC and ground or through Arduino supply the one that's coming in here so do not move this jumper this is a very poor design I don't know why they've got that second ground pin in there like that unless it's for convenience in connecting your alternative supply but frankly it's just asking I believe for trouble with people experimenting but they think what happens when I move that to that well they could be a puff of smoke and the revolted regulator on your Arduino board could be very very upset with you so just bear that in mind so there we are who would have thought that a simple relay board like this can contain so many gotchas as well as the advantages of protecting your Arduino from all the nasty bits on the relays and because remember there are built-in protection diodes on it so you didn't have to worry about any of that all you need to do is connect rods we know in here it will light up the LED end of easy you bet it was quite time thanks for watching I hope you're finding these videos useful and interesting remember you can leave comments down below and also click that little button that says subscribe ok thanks for watching and see you in the next video
Info
Channel: Ralph S Bacon
Views: 97,109
Rating: undefined out of 5
Keywords: Arduino, electronics, C++, microcontrollers, programming, gadgets, Relay, Relay Module, EL817, Dual channel relay, opto isolator, photocoupler, Hints, Tips, Traps
Id: d9evR-K6FAY
Channel Id: undefined
Length: 16min 51sec (1011 seconds)
Published: Sat Feb 27 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.