I am working on using an Arduino and a relay to control a standard 120V outlet. I found some great material on using a 2N2222 along with a 5V relay (see below). From what I understand, I need a 5V power source (or whatever the coil needs) for the relay. What I would like to do is use a single power supply for both the Arduino and the relay. I understand enough electronics to know that if I have a 12V power supply, I need to use some resistors to bring the relay line to 5V. But I don't know enough electronics to know what kind of problems I will have using the same power supply for both. Are there issues doing this, and if not, any advice on the best way to wire this up?
I understand enough electronics to know that if I have a 12V power supply, I need to use some resistors to bring the relay line to 5V.
Then you know even less about electronics than you thought. Do not do this.
If it is a 5V relay then power it from the +5V line from the arduino, if it is a 12V relay then power it from that and plug the 12V into the power jack socket to power the arduino.
I am working on using an Arduino and a relay to control a standard 120V outlet
i dont even dare to play with the mains yet!
I would do a lot more research before going there, and if you dont listen to what grumpy said and end up wanting to use resistors as a voltage divider...at least go for a voltage regulator.
If you decide you must (for whatever reason) power a 5 volt DC relay coil from a 12 volt DC source, you must first find out what the relay coil's resistance is (or directly, it's coil current value) then you can calculate a series resistor size that would allow the 5 volt coil to work in a 12 volt circuit. Lets assume the relay coil consumes 100ma at 5vdc, then you need a resistor that would drop 7 volts at 100 ma or R= E/I or 70 ohms. The resistor would have to dissapate 1/2 watt of power so you would want a 1 or 2 watt rated resistor.
As GM said it would be better if you just powered the relay coil from the Arduino +5vdc pin, assuming the coil current requirements doesn't exceed the arduino's +5vdc current capacity.
Regarding what said GM, I would love to do this, but the relay that I am looking at needs 500mA, which is greater than the 5V pin can handle. I haven't seen a relay that could be directly driven from the 5V pin. If you know of one, please let me know, as it would make life much simpler.
So assuming that I get a 12V relay, can I use the same power supply for both? Just wire a junction? I was thinking that the relay might cause some sort of power surges/changes that could do the Arduino harm, so I would need a diode (or..???).
I haven't seen a relay that could be directly driven from the 5V pin. If you know of one, please let me know, as it would make life much simpler.
There are many 5 volt relays available that would require far less then 500ma coil current, some even small enough to be powered directly from an arduino output pin without needing a switching transistor. However before I bother linking to such, I would need to know what contact type (SPST?) and ratings you require (max volts and current being switched).
That is just a stupid current requirement for a relay, what size is it, it sounds like it is huge. Does it have to be that big?
You are not going to drive that with a 2N2222.
According to the data sheet you need 50mA base current for 500mA and you can't get that much from an arduino pin.
You are also right on the limit for current and power.
These 5V relays draw about 70ma, so 4 of them would take 280ma and be OK from the Arduino +5 output.
But if you have a separate 5V 1Amp supply (wall wart types are < $5) you can run separate +5 supply wires to Arduino and to relays. Then you can do 10 or 12 relays if necessary..
There are low-cost prebuilt relay boards with 1,2,4 or 8 relays, and also optically isolated versions: http://goo.gl/8ZEQ8