I have recently started with an Arduino starter kit. Now that I have done the experiments and played with the kit a bit, I want to make something more interesting.
I would like to make something I saw in a Make Magazine: Garduino, to measure and control an indoor garden. For that I would like to switch on and off growlights and a waterpump.
I understand what is needed and have set the thing up, but I do not konw what relays to pick to switch on and off the pump and lights. I know I have to switch on/off devices running from outlet power: 230v AC in Holland, while the arduino is able to output 5v DC, correct?
Anyone have any tips, tricks, resources for me on how to get the right relays?
The trick is to get a relay with the right rating on the contacts. You just want on / off control so a single pole, single throw or single pole change over is what you want.
This in turn will determine how much current at 5V you need to drive the relay, the bigger the contacts the more current you need to switch the relay. So the trick is not to over specify the relay contacts, but don't under specify them either.
Also think about the coil voltage, do you want to use the 5V or is there a higher DC voltage you have available? Using more voltage on the coil means less current through it.
Now, I am a newby in this area, so I hope I did my homework correctly when answering to your reply:
If I look at this drawing of a relais:
The S1 and S2 are connections made to the ground and the arduino, right? For that I have the 5v that the Arduino can deliver.
Then the 2 wires that are on the powerchord of the lights, I would cut one of them and connect one side of the cut wire to the C (common) and one to the NO (Normally Open). Plug the chord into the poweroutlet, put the switch on the light itself in the ON position and trigger the relay to switch on and off the lights.
So, would that mean I am looking at the relay with coil voltage of max 5v DC and the C and NO contacts will have to be able to handle 230v AC (not sure how many Amps)?
yes, s1 and s2 are the relay coil. You can connect s2 to ground, and s1 to an arduino pin (or the other way around, it doesn't matter), but only if the coil will activate with less than 40 ma. Bigger relays need more current than the arduino can source. You MUST put a diode across s1 and s2. Search in the forums for the explanation.
You will only get 3-4 V out of your arduino output pins, so you need a relay that will operate that low. A 6V relay won't. Many relays advertised as 5V actually will (because they are intended to be used with digital electronics powered from 5V, but actually delivering 3.4 - 4.1v on their outputs), but don't forget the current rating. Sometimes, you only get a coil resistance and voltage. You can convert that to current using Ohm's Law, I = E/R, in this case Amps = Volts / Ohms.
The contact has to handle your load. You may need to convert watts to amps, because the contacts are rated in amps. Power (in watts) = EMF (in volts) times current (in amps), so I = P/E. 230 watts at 230 volts is 1 amp. Make sure the contacts are rated for 230 volts.
It would be slightly safer for you to make sure that you cut the "hot" side of your power cord to your lights, allowing the "neutral' side to remain connected. However, you did describe the connections correct. Conventionally, the power source (plug side) would connect to the C, and the lamp side would connect to the NO, but it will work fine the other way.
With a lamp load, you might consider a 'solid state relay', rather than a mechanical relay. It is easier to drive an SSR with an arduino than it is to drive a mechanical relay. They are usually designed to be driven directly by the output pin, although some need a series resistor.
If you use an SSR, make sure you heat sink it appropriately.
No it says 5V at 280mW consumption.
Volts times Amps = power in watts.
So this relay will take 56mA to power it. This is too much for the arduino to supply.
In the data sheet for coil data it says 5V at 40mA not 4mA. This is still too much for the arduino.
It is common for data sheets to contradict themselves.
However it is rare you will find a relay that can handle contacts with a good load and switch on so little current.
You have to boost the current of the arduino with a transistor. See:- http://www.thebox.myzen.co.uk/Workshop/Motors_1.html
the first part is about driving relays.
With a mechanical relay like this you do not need a heat sink. A solid state relay (SSR) has no moving parts and can be switched direct from the arduino but it is sensitive to the current it switches, too much will destroy it. You have to know how much current you want to switch.
thanks grumpy_mike, that was an interesting read. Bookmarked and I will do experiments this week I hope.
However, I pasted the wrong link by mistake, I meant this relay:
that one states 200mW consumption and a 5VDC coil voltage, which means 40mA, correct? I believe I saw this one used elsewhere on an arduino project, but could not find the link.
Yes 40mA is still too much current. While people say that is the current limit the manufacturers say that is the absolute limit and sustained operation at that limit will cause damage. So you are better off using a transistor as well they are only a few pence.
I understand that the transistor is there to increase the current. However, due to my lack of knowledge, I do not understand why sustained operation would cause damage? Is it because of the current going through the coil that would damage the coil or something?
On a side note, elsewhere in the forum I found someone using this relay: http://www.crydom.com/en/Products/Catalog/s_1.pdf which takes a typical input current: 3.4 VDC, 20mA. This would be a bit more energy efficient I suppose?
Sustained operation of a relay that takes more than 40ma to power the coil will burn out the pin on the Arduino microprocessor, unless you use the transistor to supply the current. Arduino turns on the transistor that then uses its greater current carrying capacity to turn on the relay.
ok, so all in all, ideally I would be looking at a non solid state relay (in order not to have the heatsinks) that can switch at 5VDC, around 40mA, with a transistor to do the switching in order not to have the arduino pin continuously running the relay (and by it running the risc of damaging).
Now, I have to do some math I guess to figure out what transistor to use and the resistor to use...
thanks all, learned a bit here and lots of interesting links! The learning process is fun
I understand that the transistor is there to increase the current. However, due to my lack of knowledge, I do not understand why sustained operation would cause damage? Is it because of the current going through the coil that would damage the coil or something?
View it as this: the transistor isn't there to increase the current, the transistor is there to separate the circuit that drives the coil from the arduino pin (although in most places you see people saying that a transistor amplifies the signal, in most cases you can think of it as two circuits sharing a ground). Without the transistor, the current passing through the coil is the same as the current passing through the pin circuits inside the arduino chip, which can only tolerate low currents.
Whatever the current specifications for the relay, use a transistor to separate it from the pin, it's safer and cheap (much cheaper than buying a new atmega after burning a pin).
View it as this: the transistor isn't there to increase the current, the transistor is there to separate the circuit that drives the coil from the arduino pin (although in most places you see people saying that a transistor amplifies the signal, in most cases you can think of it as two circuits sharing a ground). Without the transistor, the current passing through the coil is the same as the current passing through the pin circuits inside the arduino chip, which can only tolerate low currents.
Ah, that makes sense. You use the smaller currents from the Arduino to "open" the transistor, which in turn will switch on the relay...
So, I guess I am looking to get an Omron G6D-1A-ASI (5VDC version), with a 2N2222 transistor (datasheet) for each device I want to switch on/off (lights and a pump). I saw here that a recommended diode would be the 1N4004 (400V, 1A).
Each combo will set me back less than ? 5 (relay, transistor, diode), which makes this one of my cheapest hobby's
A 2N2222 is a fine choice for the transistor. I think you can use a 1N4148 diode; you don't need 1A. Usually you will see a resistor in series with the output pin and the base of the transistor.
Pay attention to the line in the OMRON datasheet that says "Resistive load", 5A. Don't run anywhere near that with a motor or something that isn't resistive. Incandescent lights are resistive, start up currents for fluorescent are much bigger than the wattage of the bulb, and are not resistive.
I know, it has been a while since the last post. I have moved to a new house and started a new job, that took my full attention.
However, I am back to my little project again.
brtech, you made comment about the resistive load. I am planning to use a small 5 W waterpump. at a later stage I may add a growlight (to light crops in the greenhouse that did not receive enough natural light during the day).
Am I right to assume that a waterpump is resistive?
Am I right to assume that a waterpump is resistive?
No. Water pumps have motors and as brtech said above, that is not resistive, but inductive load. However, if your pump draws 5W@230V, current will be well below 5A.