So, you want to control things with your Particle Photon and/or Electron do you? Well, a relay is a perfect way to do that.

Transcript

Hey Guys, How’re you doing? My name’s Sam and I’m from Core Electronics and today we’re going to be taking a look at how we can use relays with our Particle board. Now this tutorial applies to both the Photon and Electron, so what ever you have, you’re covered.

Now, if you don’t know what Particle is check out some of our other Particle tutorials including Getting Set Up with the Particle Photon or the Particle Electron and some of the other cloud functionality.

But today we’re going to be looking at using relays and controlling different things around the house with the Particle Relay Shield. Now this is awesome, I cannot speak highly enough of the engineering and design that went into this piece of equipment.

00:38 I have my Photon in there, now the Particle Relay Shield is a 4 channel relay board. It includes headers for the photon and you can see when you put it in you’ve also got extra breakout headers so you can attach more things to the pins that aren’t being used. It’s got a prototyping area and it’s also got an input to power your Photon from, you can power it by USB still or you can connect a DC supply from 7V - 20V and it regulates that down to 5V speeds to the Photon and powers all of the relay circuitry. It’s a very well thought out piece of gear, there’s pads under here that you can cut with a knife and by default the relays go through to pins D3-D6, yeah, D3-D6. You’ve got those relays but you can cut those and solder those jumpers to any pins that you like. It’s a really, really versatile bit of gear.

1:31 And these are 220V 10A rated relays so they will handle mains voltages, but before we go into this tutorial a very heavy disclaimer: That you should not mess around with mains voltages unless you are certified to do so, and just because you can wire something up physically doesn’t mean you should. We take no responsibility for anything that catches fire while using this device. You need to be careful with mains voltages guys, very, very dangerous stuff.

1:59 But of course, just because they’re rated for that doesn’t mean that you can’t use voltages and currents lower than that, of course you can. You can use anything beyond, sorry before the rated voltage and current but you just can’t exceed that. So, before we dive in to actually using it, lets take a look at what relays actually are because it’s an important thing to know. Now, a relay is an electromechanical switch, simply put. It has a solenoid in it and it has metal contacts which form the switching mechanisms. So if you don’t know what a solenoid is we’ve put a bit of a working description into the tutorial here and it uses whats called the “motor effect” which explains that when there’s a current travelling through a wire it is going to experience a force if it is in a magnetic field. Now, of course, now when a current travels through a wire, when there’s a change in that current it’s also going to create an electromagnetic field around the wire proportional to the change in current so, or relative to the change of current I should say. So, a relay uses that principle and you can see a bit of a working description here on the tutorial where the coil is energised and it has an armature which is attracted or pushed away from the coil depending on how its set up. When its energised it will make a switch and when its de-energised it will break that switch and could make contact with another switch. And if you’re not really sure about switches we’ve got a tutorial just for you, it’s called “All About Switches” and it covers what a single pole, a single throw switch is, through to double pole, double throw switches and a lot of relays are going to be using that terminology so it’s a good idea to get versed in that.

03:38 But yeah, so a relay uses that solenoid principle to mechanically make or break a switch. Now why this is useful is, sure there’s transistors and opto isolators, LED LDR converse and things like that that you can use to control the flow of electrons from a device from a control signal but the big advantage that relays have is they make a mechanical connection between the signal whereas transistors it’s travelling through the silicone layers on the transistor and the transistor is acting like a switch to another supply rail. The relay is a physical mechanical conductor touching another conductor which means that there’s nothing you have to worry about, you know, polarity issues. They handle current in both directions and the rating is purely based upon the size and the integrity of the mechanical connections in there.

So, there’s a couple of important specs to keep in mind with relays. As we’ve talked about, you’ve got the rated voltage and current on the switching side so the loads that you’re switching, that is the voltage and the maximum current that you can switch and it’s important to note that those specifications are a function of power. So if you’re, even though it’s rated up to 220V, if you’re only switching 10V then it’s going to be able to carry a lot more current than just the 10A because power is equal to voltage multiplied by current so the total power consumption is still far less even if you’re carrying, say, 20A at 10V through - the total power is still less which is where that heat comes from because it could melt the contacts or the plastic housing.

05:11 So, you’ve got those electrical specifications and then you’ve also got the control voltage and the control current and this means the voltage that is required to energise the coil and too higher voltage and you could risk burning out the coil, because the little wires that wrap around inside to form the coil are only rated to a certain voltage and they could physically burn out and too little and you might fail to energise the coil which result in, well, it’s not going to damage your relay but it’s not going to work either. Then the current, the control current, is how much current the relay is going to pull at maximum when it’s turned on.

Now there’s different types of relays which we’ll get to in a moment. You’ve got latching and non-latching but it’s important to note that the current draw is going to be the most, it’s going to be the maximum current draw when it’s first energised and it’s going to drop off gradually. Ah, which brings us to the next point, the mechanical specs of the relay and these are really quite similar to that of the switch. As I said, you have latching, you have non-latching relays. Now a latched relay means that you apply a pulse, so say you know, you apply the appropriate voltage across the relay and it will switch on and it will latch mechanically which means that you can take power away from it and its still going to hold there and then if you provide another pulse to it and it’s going to latch back. Pretty cool, and this is good if you want to hold that relay in place without continuing to draw power from whatever the control signal is so really energy efficient applications will use those latched relays. They’re more expensive and more complex though.

So momentary relays require constant power to be held there and whenever the power is taken away they revert to their default state, 2 states and bear in mind though that the maximum current is when it’s energising and when that coil is first being turned on. The holding current is going to be quite a lot less because it just needs to hold it there, it doesn’t need to overcome all the, you know, the forces that it has to, to turn the switch on.

So, yeah, and then along with that you’ve got the type of switches which as we’ve talked about before whether it’s single pole, single throw, single pole double throw, double pole, single throw, whatever you’ve got going on, the type of switch that it is.

07:12 So, now we’ve got all of that out of the way, what is the Particle Relay Shield? Well, as we’ve said, it’s a 4 channel relay board, there’s 4 individual relays on there that are rated to 220V and 10A which gives you a power consumption of a bit over 2000 watts per relay which is huge, its very very cool! Now, these guys are single pole, double throw relays which means that you can see 3 pins and these are the output pins on each relay. You have a common pin and you have a normally open and a normally closed pin. So, if you have a look I will grab a pointing device such as this, now if you have a look that contact there is the common so whatever you connect up to there is going to depend on what the normally open and normally closed contacts are connected to so in one state the common pin is going to be connected to the normally open pin and the normally closed pin is just isolated, it’s not connected to anything. Then in the other state this switch breaks and the common pin is connected to the normally closed pin and the normally open pin is left floating, so you have these 2 states and there’s a single pole with 2 throws, which is very cool.

08:25 And as we’ve said we’ve got power in here, so i’m going to demonstrate how you can power it up using an external power source. I’ve got a 9 volt battery here with a battery connector clip, or you can use power terminal blocks or a USB’s going to work fine in and I’ll explain why that is in just a second.

So today I have got this Photon board flashed with Tinker which means like I can control the outputs from my phone and we can see what each relay is doing and as I said it also works with an Electron board because the pin mappings from there to there are the same on the electron board it simply extends those out and has an extra 2 registers of io so you can put the electron in there and it’s going to hang out a bit but its still going to work which is fine.

So, I’m going to plug this in, get started, insert it into there. I haven’t got anything on the prototyping section yet, although I would like to make a fun project out of that. Perhaps could connect it up to a pool pump or something like that provided that the power consumption is not too bad. Or you could connect it to a coffee machine, you connect a temperature sensor up or a weather station and build some extra circuitry on there like an indicator LEDs. So now, we’ll connect it up and you’ll see the blue light on the board for power and there’s a regulator circuit on here which converts the 7 to 20V and converts it into a 5V supply which goes to the Vin pin on the Photon, the Photon then has an on board regulator which regulates it down to 3.3V and then that 3.3 volt signal gets fed to the control circuitry on here. In fact we’ve got a schematic in the tutorial here from the Particle website so you can see that the control signal goes through a transistor buffer which switches a 5V supply with an indicator LED and a flyback diode to protect from EMF on the coil surges and it converts that 3.3V signal into a 5V signal to drive the relays because that is their rating for the control voltage to turn them on. Now that works just fine, now we’re going to take this out and take a look, so i’ve got my Tinker app open here with photon eric ?????? that will go there so you can see.

Now i’m going to go and turn D4 D3 D5 and D6 to digital right pins and they are all low at the moment. Now, the Tinker app is very cool, check out our “Getting Started With Photon” tutorial if you want to know more about that. It’s sending signals to the Photons to turn on or off or read the pins via the internet which is cool. I’m going to turn that on and you see that red light, blinking - now if I stop talking and do that again you’ll be able to hear the mechanical click which is the relay coil energising and making the mechanical connection with the switch. Hear that? quite a thump! Bit louder when it’s being turned off than when it’s being turned on and there’s a nice little indicator LED on here to show which relay is being turned on. Now I’ll unplug this and I’m going to connect it via USB and explain how that works because it’s actually quite cool. I think it’s cool anyway, it’s a really well designed piece of gear to allow for different situations. So how this works is the Vin pin is tied to the 5V on the USB power and there’s the diode there to protect the power, the 5V going back into the USB which is fine. But if you connect the 5V connected here isn’t going to damage your computer hopefully if your particle board is working correctly.

But now, I’ve got 5V connected to the Vin pin which goes to the regulator line and because it’s the output it actually doesn’t go into the regulator because there’s diodes to protect against that and it goes across the circuitry here on to the 5V one which means the Vin pin which is now connected to 5V is powering the relay switches. So, I can use it here 12:10 hey, very cool! It’s a really nifty design the way they’ve done that but what’s important to note is that if you are using it via USB you need to be cautious about what your USB current draw is. For example they recommend 1.2A supply if you’re powering it by an external power supply which allows for a few hundred milliamps at maximum, maximum, current draw from the coils on the relays if they’re all being energised at the same time, plus you know, plenty of amperage left for the Photon boards. So if you have even a standard computer at 500 milliwatt ah sorry, milliamps not milliwatts - a 500 milliamp device is going to power your Photon and power the relays but you’re not going to be able to draw much more power than that at all. So, if you have a beefy 1A or even a 1.5A USB power supply then that’s going to be ideal.

So that’s really all there is to it guys, this board is as simple as plugging your Photon in and these pins are simply digital right pins. The circuitry on board takes care of any logic level conversion and you just write a high to the digital pin and the relay will turn on and you write a low signal to the digital pin the relay will turn off and it makes, when it’s on, it connects the common line to one of the pins and when it’s off it breaks that and connects it to the other pin which is very cool. Now Particle have released a library for the shield but in my opinion you’re better off just using it as a digital output and using a variable to name the output pins so that you know its a relay because while the library is cool it doesn’t really include any extra functionality because it’s such a basic idea - all you need to do is turn a pin on and off so they include functionality for turning all the pins on at once or turning one pin on. But you can do all that really easily in code just as you would turning an LED on and off and you’re going to save the overheads that comes with compiling that library onto your Photon board. Just my opinion, however, feel free to experiment with using the library and that’s all for today guys, we can see that when I turn these on they all turn on and you can connect whatever you want up to there and it’s very cool and in the diagram they show connecting the light bulb up but bear in mind they’re showing that with mains power so you want to be very cautious.

I wouldn’t recommend doing this unless you are a licensed electrician or have been certified to deal with mains power but you can go and use that with LED’s so you could connect the centre pin up to 5 Volts and connect your positive lead of your LED up to there and to the negative lead of the LED through to ground via a current limiting resister and whenever that contact is made it will turn the LED on and whenever it is broken it will turn the LED off. Connect motors, connect whatever you want up to this, it’s fantastic! Grab one of these, I think they’re only $54 or something, great value. That’s all for today guys, that’s a bit about relays, a bit about solenoids, a bit about how the coils work and a lot about this fantastic relay board from Particle. See you next time guys :-)

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.