relays with arduino – turning on the lights

33
Hobby Robotics Using Relays with Arduino – Turning on the Lights April 7, 2008 at 8:17 pm · Filed under Arduino, Circuit Warning!!! This project deals with AC electricity which is dangerous if you don’t know how to treat it safely. You must treat electricity with caution. There are many books and websites about electrical safety procedures and if you’re not sure how to be safe you should read that information. The most basic advice I can give is always assume any exposed wires are live and touching them will hurt a lot at best and kill at worst. Microcontrollers are good at controlling small devices, but frequently we DIY-ers want to use them to control things that aren’t so micro. In this post I’ll talk about how to turn on household lights with the Arduino microcontroller. Actually this technique isn’t limited to lights, it works for anything that gets plugged into the wall like a table saw or a small rail gun. The first thing you need is a cheap extension core that you are willing to cut in half. After cutting and stripping the wires you need to solder in a relay. A relay is just like a light switch only instead of using your finger to flip the switch you use a small amount of voltage. Any 5 or 12 volt relay would work, but I already had some OJE-SH-105DM relays sitting around. These relays handle 5Amps at 240V AC. This means they can safely handle 5 Amps at 120V like you find in the US power grid. To get a feel for how much power that is I used Ohm’s Law which states amps*volts=power or in our case 5A * 120V yields 600 watts. That’s enough wattage for me, but if you want to blow up the moon with a giant laser then you just need to use a bigger relay. I spliced the relay into the black wire on my power cord. For safety reasons you must splice the relay into the live wire. The standard coloring convention is that the black wire is live and the white wire is neutral. If Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics... 1 de 33 09-01-2013 19:03

Upload: linuxman-rj

Post on 01-Nov-2014

182 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Relays with Arduino – Turning on the Lights

Hobby Robotics

Using Relays with Arduino – Turning on theLights

April 7, 2008 at 8:17 pm · Filed under Arduino, Circuit

Warning!!! This project deals with AC electricity which is dangerous ifyou don’t know how to treat it safely. You must treat electricity withcaution. There are many books and websites about electrical safetyprocedures and if you’re not sure how to be safe you should read thatinformation. The most basic advice I can give is always assume anyexposed wires are live and touching them will hurt a lot at best andkill at worst.

Microcontrollers are good at controlling small devices, but frequently weDIY-ers want to use them to control things that aren’t so micro. In this postI’ll talk about how to turn on household lights with the Arduinomicrocontroller. Actually this technique isn’t limited to lights, it works foranything that gets plugged into the wall like a table saw or a small rail gun.

The first thing you need is a cheapextension core that you are willing tocut in half. After cutting and strippingthe wires you need to solder in a relay.A relay is just like a light switch onlyinstead of using your finger to flip theswitch you use a small amount ofvoltage. Any 5 or 12 volt relay wouldwork, but I already had someOJE-SH-105DM relays sitting around.These relays handle 5Amps at 240V AC.This means they can safely handle 5

Amps at 120V like you find in the US power grid. To get a feel for how muchpower that is I used Ohm’s Law which states amps*volts=power or in ourcase 5A * 120V yields 600 watts. That’s enough wattage for me, but if youwant to blow up the moon with a giant laser then you just need to use abigger relay.

I spliced the relay into the black wireon my power cord. For safety reasonsyou must splice the relay into the livewire. The standard coloringconvention is that the black wire islive and the white wire is neutral. If

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

1 de 33 09-01-2013 19:03

Page 2: Relays with Arduino – Turning on the Lights

you splice the relay into the wrongwire even when the relay is off thelight would still have power to it andyou could get electrocuted. I used aDMM to verify which wires wereactive, neutral, and ground. You cansee the schematic for details. Once

the relay is wired into the cable Iverified that when I applied thetrigger voltage (+5V for my 105DM)to the relay that I could hear it flippositions and also verified it wasacting as a switch for the extensioncord by using my trusty sidekick Mr.DMM again. At this point I kneweverything was working as expectedso I finished wiring the extension cordtogether and wrapped it withelectrical tape in a safe manor. Thisneeds to be done before you ever plugthe extension cord into the wall.Remember you are working with 120Vof AC power which is dangerous if not

handled properly. If you aren’t sure that you’re being safe then you shouldfind one of the many other websites or books dealing with AC wiring safety.Sorry for sounding like your mother, but I want to make it clear that if youmess this up and shock yourself or burn down your house it’s not my fault. Atthis point you have a magical extension cord that can power things on and offsimply by applying voltage to the relay. Ok maybe it’s not so magical. Applyvoltage to the cable seems to be more work than just plugging it in, but trustme in a little while it will be awesome! Test it with your light bulb and apower source to make sure everything is working.

The last step and the one that makes this project useful is getting themicrocontroller to control this relay. To do that you can use the followingcircuit. Most motors and relays shouldn’t be connected directly to amicrocontroller because they are inductive and require more current that amicrocontroller can safely supply. If you are using a low current 5 volt relayyou may be able avoid this circuit (you’d still need to clamp the relay with adiode), but using this circuit should work fine with these small relays so if indoubt use this circuit.

In this circuit the transistor acts as a switch and it allows you to turn on therelay. This circuit works for relays using 5, 9, or 12 volts (the common triggervoltages for relays). I picked a 5 volt relay because that lets me use theArduino board’s 5V volt output thus eliminating the need for another powersource. You also need to protect the microprocessor from back EMF current

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

2 de 33 09-01-2013 19:03

Page 3: Relays with Arduino – Turning on the Lights

and that is what the diode is doing.

The cost to build the circuit belowshould be under $15 dollars and half ofthat is for a cheap extension cord.RadioShack or online electronic storeswill have all the other components.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

3 de 33 09-01-2013 19:03

Page 4: Relays with Arduino – Turning on the Lights

The code to run this was amazingly simple since the transistor and relaymake turning on the extension cord as simple as turning on or off an LED.Here is a program that lets you toggle on and off the relay with the spacebar.

// Maurice Ribble // 4-6-2008// http://www.glacialwanderer.com/hobbyrobotics

// This code just lets you turn a digital out pin on and off. That's// all that is needed to verify a relay curcuit is working.// Press the space bar to toggle the relay on and off.

#define RELAY_PIN 3

void setup(){ pinMode(RELAY_PIN, OUTPUT); Serial.begin(9600); // open serial Serial.println("Press the spacebar to toggle relay on/off");}

void loop(){ static int relayVal = 0; int cmd;

while (Serial.available() > 0) { cmd = Serial.read();

switch (cmd) { case ' ': { relayVal ^= 1; // xor current value with 1 (causes value to toggle)

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

4 de 33 09-01-2013 19:03

Page 5: Relays with Arduino – Turning on the Lights

if (relayVal) Serial.println("Relay on"); else Serial.println("Relay off"); break; } default: { Serial.println("Press the spacebar to toggle relay on/off"); } }

if (relayVal) digitalWrite(RELAY_PIN, HIGH); else digitalWrite(RELAY_PIN, LOW); }}

Credits

I’m not sure who designed this circuit diagram, but I found it referenced onthe Arduino website and it was very useful while designing my relay circuit.

I would like thank Oracle, spiffed and the others who helped me make this abetter and safer article.

Permalink

90 Comments »

sanspot said,

June 4, 2008 @ 6:36 am

HI! i found out this tutorial very interestin….problem is in the code…itdoes not work.When i compile it says that in the void loop function &gtwas not declared in this scope…any idea why?I’d really like to make this work!

Thanks

1.

Glacial Wanderer said,

June 4, 2008 @ 7:34 am

For some reason when I pasted the code into this some of the code wascorrupted. It should be fixed now.

You could also get the code from this link which is the file I used whentesting this. http://www.glacialwanderer.com/_blog/blog2008/04_April

2.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

5 de 33 09-01-2013 19:03

Page 6: Relays with Arduino – Turning on the Lights

/relay.pde

sanspot said,

June 4, 2008 @ 9:38 am

thanks for the link, i saw it after i posted …but the problem remains thesame…when i plug arduino in the usb the light bulb suddenly turn on,when it should be off untill i tell arduino to turn it on right? I amwondering if the problem is in the circuit….it is the same of your, expectfor one thing…you connect on the breadboard from the bulb threewires, two from the relay(green wires) and another, that i don’tunderstand were is it from( the black one).I have only the two wires from the relay. i would post a photo if i could.

3.

sanspot said,

June 4, 2008 @ 9:41 am

in fact i got two wires from the bulb: one goes to the relay one on theplug of the wall.Then from the plug the remaining wire goes in therelay…then from the relay the 5 volt wires are plugged in thebreadbord…

4.

Glacial Wanderer said,

June 4, 2008 @ 5:31 pm

The 3 wires going into the relay are +5V, pin3(signal), and ground to thegrounding wire. I suspect your problem is with the circuit some how.You can test the relay without an Arduino (thus eliminating the softwarecomplication). All you need to do take the signal wire (it’s currentlyconnected to pin 3), and put that to +5V to turn on the relay and GND toturn off the relay. You should hear the relay flip on and off. If thatdoesn’t work then adjust your relay circuit until that works. Once that’sworking you can connect the arduino again and see if the software halfis working.

5.

sanspot said,

June 5, 2008 @ 1:17 am

I now understand what that black wire is…but I put a another wire thatgoes from the 220V plug to the gnd on the bread board ( as your circuit,in which you have the two green wires of the relay and the black onethat comes from the blue wire on the plug…).In both cases ( with and without the black wire ) the relay works if i

6.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

6 de 33 09-01-2013 19:03

Page 7: Relays with Arduino – Turning on the Lights

conect it to a battery…even when connected to the Arduino…theproblem is that instead of being off waiting for Arduino to turn on it isalways on…the relay just don’t wait for arduino to turn on the bulb…Idon’t understand where the problem is

Glacial Wanderer said,

June 5, 2008 @ 5:52 am

So it sounds like you’ve narrowed it down to the arduino software. Asyou can see the program is very simple. Have you tried running theBlink example program? http://www.arduino.cc/en/Tutorial/Blink Maybeyou aren’t loading the program properly or something. Once you’ve gotan LED blinking you can change the blink program to use pin 3 and itshould blink your lightbulb. You could also use a DMM and check thevoltage of pin 3 with the current program. I’d then start modifying to it’ssimplest state so it would set pin 3 high to verify that turns on the ligthbulb, and recompile it with pin 3 low to see that turns off the lightbulb.My best guess right now is that the program isn’t getting loadedcorrectly. Once you’ve got those simple versions working make sure youremember that you need to make a serial connection before thespacebar will toggle the light on and off (but it should be defaulting tooff).

7.

atomriot said,

September 12, 2008 @ 8:46 am

I first have to say Nicely done. This was exactly what I was looking for!

I have implemented this layout for a project for work. I am in much thesame book as you where I am a software guy tinkering in the world ofelectronics.

My implementation uses 3 of your circuits and i have 2 of them workingjust fine but the third will not throw the relay. When I hook up the DMMI see the 5v on the pin from the Arduino, and I see around .7v on thebase pin of the 2N2222. and when I check the collector pin, it is around3.23v when its switched.

I cannot figure out what is not working. I have changed out the 2N2222and tested resistance in the 1K resistor and verified the diode isn’tpassing back current, and I don’t see any crossover on the soldering andI can manually flip the relay. I am just not sure what it is doing though toget the 3.23V on the collector. Tonight I am going to try and replaceeverything 1 by 1 but as I said it all tests out individually.

Any ideas?

8.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

7 de 33 09-01-2013 19:03

Page 8: Relays with Arduino – Turning on the Lights

Glacial Wanderer said,

September 12, 2008 @ 10:28 am

Are you using the same pin on the Arduino to test all 3 of your circuits?If you’re using a circuit board and there is flux on it, you might want totry washing that off with alcohol. Then triple check for shorts. If none ofthose are the problem I’d try replacing each component like youplanned on doing.

9.

atomriot said,

September 12, 2008 @ 11:49 am

Yes, same pin for testing. and i tested all three on three different pins. Iwill have to give the alcohol thing a try but I will most likely try newcomponents on a different part of the board with clean new solders.

Thanks for the input! I will post back after i try it.

10.

atomriot said,

September 13, 2008 @ 12:43 pm

Ok, I don’t get it. I removed all the components and tried them on abreadboard and it worked just fine. I moved them to 2 different placeson my circuit board and it does the 3.23v thing when active. I have triedcleaning it as you said but i see no difference and the other 2 sets of thiscircuit work fine.

I am lost on this one. Thanks again for your input though!

11.

atomriot said,

September 14, 2008 @ 8:48 pm

well, I know I implied defeat before but I am stubborn headed I guess.After trying 4 more 2N2222′s since everything else seemed to test out, iall but gave up on soldering and started making it on the breadboardagain with all new parts. when i tested it…i got the 3 volt thing againand the relay wouldn’t kick. then i though about it and wondered whatthe little transistor transistor would do if I had it backwards. I switchedit around and then it worked…

so the batch of transistors i got from radio shack were labeledbackwards and that is what has been causing all of this frustration. sonow on my board i have 2 facing one way and one facing another but theorientation of the diodes and ground wires are still the same.

12.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

8 de 33 09-01-2013 19:03

Page 9: Relays with Arduino – Turning on the Lights

thanks again for your input, and sorry to have flooded your post:)

Roland said,

January 26, 2009 @ 10:14 pm

I am currently using reed relays connected directly to the IO pins of myArduino Diecimila. See elexp.com, part#22RD-5. Coil is 5v, 500 ohm.That’s only 10mA!Easily within specs. Cheap too, $1.10 each for 10 or more.

13.

joe said,

February 13, 2009 @ 12:35 pm

That’s not Ohm’s law you’re stating

14.

Bryan Johns said,

April 1, 2009 @ 1:20 pm

How would one wire up a 12v relay instead of the 5v one you used?Basically I’m a little confused about using 5v (arduino) and 12v in thesame circuit.

15.

Maurice Ribble said,

April 1, 2009 @ 4:13 pm

I believe the circuit would be the same as above. You just need to makesure your 2n2222 transistor and diode support 12+ volts. Then replacethe 5V power supply with a 12V power supply.

16.

Alan Wend said,

May 27, 2009 @ 1:01 am

I’m not a EE but I’m pretty sure you are not supposed to makeassumptions about which prong of the power cord is hot and which isground. You should use a double-pole relay and interrupt both wires.Thanks for doing this. I’m going to set up an Arduiono as a thermostatto run my swamp cooler. Mostswapmp coolers have separate controls for the pump and the fan, sothere are opportunities to save energy and water by running just the fanif the outside temp is already cool enough. Also, if you have tempsensors outside, inside the house, and at one of the vents, you can figureout the humidity. Is there some kind of little display panel that would fitin the Ardiouno box?

17.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

9 de 33 09-01-2013 19:03

Page 10: Relays with Arduino – Turning on the Lights

Maurice Ribble said,

May 27, 2009 @ 5:22 am

That sounds like a neat project! I’m not sure what display you are using,but I’ve used this one and it works well. http://www.sparkfun.com/commerce/product_info.php?products_id=461

There is a standard so I think it is ok to to use a single pole relay. I’velooked at some lamp switches and they are single pole. I don’t see anyproblems with a double pole relay as long as you have a 3 prong plugwith the separate ground.

18.

Hobby Robotics » DIY Outdoor Time-Lapse Photographysaid,

June 13, 2009 @ 7:38 pm

[...] The basic premise is to run an Arduino as a timer and once an hourit turns on a relay. The reason for the relay is minimize power usagewhile the Arduino is running as a timer. When the relay is powered upthe servo and camera also get turned on. Then the Arduino uses a servoto turn on the camera and take a picture. A 5 volt regulator is used tomake sure the system could provide enough current to the servo andcamera. After seeing how little current my camera draws, I realized Icould have used the 5 volt regulator on the Ardunio board, but theregulator is cheap so there is no harm in using it like I did. You want tomake sure the coil on the 5 volt relay you choose uses less than 40 mAor you will exceed the max current draw from an Arduino pin whichcould damage the Arduino after extended use. If you want to use a relaywith a greater than 40 mA current draw you should use a circuit like Idescribed in this article. [...]

19.

Steve said,

June 16, 2009 @ 4:02 am

Here’s a device that might simplify things.

http://www.powerswitchtail.com

20.

peter said,

June 23, 2009 @ 9:07 pm

@steve: patent pending, eh? How’s that search for prior art going?

21.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

10 de 33 09-01-2013 19:03

Page 11: Relays with Arduino – Turning on the Lights

matto said,

July 1, 2009 @ 1:09 pm

I’m loving this tutorial.. its something that everyone who’s into arduinostuff should know.

Are there any considerations / modifications you can suggest forapplying this to a British power supply (240v)?

Thanks

22.

Maurice Ribble said,

July 6, 2009 @ 8:46 am

The main thing that would change is making sure the relay you choosesupports 240 volts at the current you want. The other thing to consideris the British probably use different colors for their wires. You want tomake sure you put the relay on the active wire. If you don’t know thecolor for the active wire I’m sure google can help out.

23.

Zashkaser said,

August 5, 2009 @ 11:23 am

I wanted to ask, is there any chance for a modified version of thedirectory listing script, with an iphone-stylish like design?

24.

Maurice Ribble said,

August 5, 2009 @ 2:49 pm

Zashkaser, I’m not sure what you mean by “directory listing script”.Maybe you mean code? Anyways I don’t plan to do any modifications tothis for the iphone since I don’t have one or plan to get one. Perhapssomeone else will.

25.

Ricardo Carvalho said,

September 3, 2009 @ 4:14 am

hey guys, I’ve got a few questions and was wondering you you couldhelp:

1. The relay that you mention for the tutorial: OJE-SH-105DM,095tolerates voltage up to 240V, meaning this would be OK for UK mainsright? What does the term contact rating mean?

26.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

11 de 33 09-01-2013 19:03

Page 12: Relays with Arduino – Turning on the Lights

2. Do relays normally have a maximum restriction and not a minimumrestriction?

3. You mention that your circuit produces 600w (5*120V), so us here inEurope would produce 1200w, correct? What relation does this havewith the wattage of the light bulb we use?

4. If I want to have more than 1 light bulb, do I need to have one relayfor each one?

5. I would like to have my lights fade in and out as it they were pulsatinglike a heart beat, what type of light bulb would be best suited for this?(using the arduino of course)

Thanks in advance for your help!!

ric

Ricardo Carvalho said,

September 3, 2009 @ 4:32 am

I found this UK company that sells all sorts of different relays which Ipresume work at 5A @ 240VAC but there are some characteristics thatI’m still not quite understanding:

http://search.digikey.com/scripts/DkSearch/dksus.dll

–> Coil Voltage? Does it have to be exactly the same as the arduinoboard? (5V)

–> Control On / Control Off? How does this affect my circuit? Do I needto worry about this?

–> Coil Current? Why is this different from the Current discribed in theContact Rating?

Of these ones from the list which is the best suited for using witharduino?

again thanks for your help!!!

27.

Maurice Ribble said,

September 3, 2009 @ 6:04 am

1) Yes, 240V means it should work in the UK.3) Yes, it should support 1200W on 240V. In releation to a light bulb thismeans you could drive 12 100W light bulbs with a single relay.

28.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

12 de 33 09-01-2013 19:03

Page 13: Relays with Arduino – Turning on the Lights

4) You can run multiple light bulbs from a single relay, but they will allgo on and off at the same time. If you want to control each lightbulbindependently. If you need to control lots of Lights independently lookinto shift out registers which let you expand the number of outputssupported by a microcontroller.5) You can’t use florescent bulbs when dimming. And incandescent bulbshould work. You could either do dimming with pulse width modulationor additional hardware to control voltage. If you go with PWM makesure the relay is fast enough (might need solid state). Also the relay willmake a lot of noise and you need to calculate it’s life span. You mightwant to consider hacking a light dimmer switch. I don’t know what thebest answer is here. I’d recommend researching this and doing somesmall experiments.

Most any relay that is driven by 5V input and supports your requiredamps is fine if you aren’t doing light dimming. With light dimming thingsget more complicated and you will need to figure that out.

Jake said,

October 2, 2009 @ 7:16 pm

PDF of the circuit from Arduino: http://www.arduino.cc/playground/uploads/Learning/relays.pdf

29.

raziiq said,

December 24, 2009 @ 1:14 am

Hi there.

I am trying to build the same project, but i am using a SSR instead ofsimple relays, so i think i dont need Transistor, right?

30.

Maurice Ribble said,

December 27, 2009 @ 10:03 pm

Raziiq, that is correct.

31.

Vinz said,

January 22, 2010 @ 11:03 am

Hi,I read these posts but I still have a doubt.

In my house I already have a relay based light switching system. I mean,

32.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

13 de 33 09-01-2013 19:03

Page 14: Relays with Arduino – Turning on the Lights

I have push buttons on the wall, connected to a finder 220vots relay,connected to a 220volt lamp (consider about 60-80w in the worst case).I push teh button on the wall one time and the light turns on, I push tehbutton on the wall another time and the light turns off. Simple, isn’t it?

I’ve already put other puch buttons in parallel to the existing relay andeveryting works fine and I can switch the same lamp from differentplaces in the house.

Now I’d like to put in parallel my beautiful Arduino and use it to switchthe same lamp. I just have to put something (a transistor? anothersmaller relay?) in parallel to the existing relay and simulate the pushingof the button on the wall, giving to the 220v relay a 220v pulse to switchon/off.

In other words, I just need to control a 220v relay from arduino, usingthe minimal electronic. I have to do this to many lamps and otherappliances and I have to do it in a cheap but safe way, so no costlyredoundant, unneeded components, but just the minimal right ones.

Some of you gentle people would help me in solving this simple, basicelectric problem?

I thank you very much and I’me sure this is a common problem and theright solution would help many people…

Vinz

James Fowler said,

February 17, 2010 @ 1:12 am

I won’t lie im a coder by no means lol i know basic electronics and ibought this for some inspiration but i fear i jumped in over my head withrocks in my pockets lol

how would i go about having this exact same circuit but 2 or 3 diffrentrelay controls my problem isn’t with the electronics my problem is withthe code i want to be able to press 1 to toggle pin 12 on and off press 2for 11 on off and press 3 for 10 on / off thats it lol but for the life oftrying to play with the code i can”t figure it out lol it certainly is no html

33.

Maurice Ribble said,

February 17, 2010 @ 6:46 am

Vinz, your use case sounds like the exact circuit in the article. Is theresomething specific you have a question about? If not just use that

34.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

14 de 33 09-01-2013 19:03

Page 15: Relays with Arduino – Turning on the Lights

circuit.

James, you just need to do something similar to what I did for thespacebar. I recommend checking out some of the tutorials here(http://arduino.cc/en/Tutorial/HomePage) to get an understanding ofhow the code works. If you spend time understanding a few simpleexamples I’m sure you can write the code to do what you want.

James Fowler said,

February 18, 2010 @ 1:15 am

I solved my problem after much thought and a bit of help if anyone elseis intrested

#define RELAY1 13#define RELAY2 12

void setup(){pinMode(RELAY1, OUTPUT);pinMode(RELAY2, OUTPUT);Serial.begin(9600); // open serialSerial.println(“Press 1 or 2 to toggle relay on/off”);}boolean relay1State = false; // Assume off to start withboolean relay2State = false;void loop(){static int relayVal = 0;int cmd;

while (Serial.available() > 0){cmd = Serial.read();

switch (cmd){case ’1′:{relay1State = !relay1State; // If true make false if false make truedigitalWrite(RELAY1, relay1State);break;}case ’2′:{relay2State = !relay2State; // If true make false if false make truedigitalWrite(RELAY2, relay2State);

35.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

15 de 33 09-01-2013 19:03

Page 16: Relays with Arduino – Turning on the Lights

break;}default:{Serial.println(“There are only 2 options Relay 1 or Relay 2″);}}}}

Mark Crosbie said,

April 27, 2010 @ 3:59 pm

Hey really good tutorial and helpful comments from all, working on aproject at college were we need to turn on lights individually through anarduino, perhaps a set of christmas lights! Probably have a lot morequestions but for Robbie I was wondering did you put this code in thearduino software or did you put it in Flash CS4 Code actionscript? If notany tips on transferring it into flash?Thanks very much,Mark Crosbie,The Project Free Bird Team.http://www.theprojectfreebird.wordpress.com

36.

Mark Crosbie said,

April 28, 2010 @ 4:12 am

Hey sorry, just noticed I said Robbie instead of James Fowler, although ifanyone has any tips on my last post am all ears!Thanks

37.

Maurice Ribble said,

April 28, 2010 @ 7:15 am

The code above is uploaded to the Arduino. If you want to control thelights with flash you’ll probably do that over serial (or if you wantwireless use something like xbee). You’d need to write a flash app thatdoes sends Arduino commands and then modify the Arduino code toprocess those commands. I’m sure if you looked on an the Arduino sitethere would be tutorials on how to do this. I’ve never used flash becausethe Adobe tools are closed source and too expensive for me. I have donethis sort of interfacing with C, perl, hacking directing in xterm, andprobably the easiest was processing.org.

38.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

16 de 33 09-01-2013 19:03

Page 17: Relays with Arduino – Turning on the Lights

Ciaran Mc Guirk said,

April 28, 2010 @ 11:50 am

hey guys, i’m a bit simple when it comes to electronic blueprints. waswondering if there was clearer pictures of wiring up the relay and whatway the breadboard wiring works. sorry for the hassle. thanks a million,it would be appreciated

39.

Ciaran Mc Guirk said,

April 28, 2010 @ 11:52 am

hey guys, i’m a bit simple when it comes to electronic blueprints. waswondering if there was clearer pictures of wiring up the relay and whatway the breadboard wiring works. sorry for the hassle. thanks a million,it would be appreciated if you could get back asap

40.

Phil said,

May 14, 2010 @ 11:43 am

I blow a breaker every time the relay switches on.

41.

Maurice Ribble said,

May 14, 2010 @ 11:52 am

Ciaran, I don’t have time to revisit this right now. Sorry. I bet with somegoogling you can fine what you want.

Phil, that means your wiring for the lighbulb is wrong. You must beshorting ground to power. Double check your wiring to make sure therearen’t any shorts.

42.

jeff said,

August 17, 2010 @ 12:32 pm

hey there… i’ve used this example with some good results… but just gotcompletely stumped when i tried to wire up 5 circuits… and one by oneall my relays seem to be stuck on now… would i need more than the 5vcoming off the arduino to get this working? i still hear the relaysclicking, but they are always on– does that mean they got too muchcurrent? also, if you wire several circuits such that they are all drawingfrom the same power, is the circuit closest too the power receiving morecurrent than the others (whatever relay i put there sounds different)…any help you could give me would be great… thanks

43.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

17 de 33 09-01-2013 19:03

Page 18: Relays with Arduino – Turning on the Lights

Maurice Ribble said,

August 17, 2010 @ 1:05 pm

Jeff, do you have 5 transistors and 5 pins coming from the Arduino soyou have one pin to control each relay?

Take a look at the spec for your relay and figure out how much currentthe coil takes. It might be something like 100 mA. So 5 relays would be500 mA which might mean you need an external 5V power supply to getenough current.

Just to make sure the software and wiring is correct try disconnecting 4of the relays to verify a single one still works with the wiring andsoftware changes.

44.

jeff said,

August 17, 2010 @ 2:24 pm

too clarify, whichever relay is connected to digitalPin 0 is louder thanthe others… but on the software end I’m sending osc:

/*/digitalWrite $1

so, shouldn’t all the outs act the same?

45.

jeff said,

August 17, 2010 @ 2:29 pm

I have 5 transistors, and 5 relays (your circuit 5 times)…

when i unhook all of them, and just try one the relays click (so long as iuse digitalOut 0), but are stuck on… could I have killed the relay withtoo little current?

also, if i am toggling all the outs, I should be able to hook up any out andget the same results right? does this sound like a software problemalso?

46.

jeff said,

August 17, 2010 @ 2:44 pm

if the nominal current is 20mA, then I’m looking at 100mA total?and do i also need to consider that each relay’s coil resistance is 250ohms?

47.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

18 de 33 09-01-2013 19:03

Page 19: Relays with Arduino – Turning on the Lights

Maurice Ribble said,

August 19, 2010 @ 7:52 am

Jeff, I don’t understand most of your questions. Could you try restatingthem in complete thoughts?

To answer the ones I do understand. If your circuit is similar to mine youdon’t need to worry about the ohms (I’d suggest reading about ohms lawto understand why). 100 mA is correct if each relay is 20 mA and youhave 5.

48.

Jeff said,

August 19, 2010 @ 5:37 pm

sorry for the confusion-

i bought an external regulated 5vdc power souce (1000mA), so when itcomes the only connection to the arduino will be the digital outs- right?

how’s does external power work in terms of grounding the dc circuit? doi still need use the ground on the arduino as well?

as far as weirdness i found when trouble shooting, i found the digital out0 made all the relays click louder than the other digital outs– so i’mlooking at the software to fix that right? (i guess i don’t understand, ifpower is coming from 5v on the arduino, or an external power, what’sbeing sent out a digital out?)

and lastly, is it possible to damage a component by powering it with toolittle current?when i try to run only one (normally open) relay, its stuck closed– but ishould have enough current for one relay circuit, no problem? so therelay is damaged? does that make sense?

do you have any recommendations for an electronics primer- the book ihave (the art of electronics) is a bit too dense for me so far

49.

Silenc3 said,

August 26, 2010 @ 11:34 pm

Hi, im kinda new to the arduino boards so im not really sure whats theright info to look for so i was hoping someone could answer myquestion?

With arduino can you A. Program it to flip a switch from an externalsource that would input information that the arduino board would take

50.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

19 de 33 09-01-2013 19:03

Page 20: Relays with Arduino – Turning on the Lights

and interpret the data too turn the relay off and on?

and

B. If A is possible thru some means can i then just hook up the arduinoboard to a power source and use the external device to input off and onto whatever the board is hooked up too

sorry if this sounds stupid i dont know much about this i only recentlygot into this

gamelan and electronics: relay | Jeff Aaron Bryant said,

September 5, 2010 @ 7:06 pm

[...] first built a circuit as described on this post and it worked great. Isoldered the circuit into a PCB and it was totally fine. The secondworked [...]

51.

lifeinla said,

September 9, 2010 @ 12:22 pm

complete noob here, but interested b4 i get to buying and trying this outto know if you can integrate a motion sensor into this a circuit like this –so that the bulb is on as motion is detected.

52.

Matthew A said,

September 24, 2010 @ 2:28 am

I, as well as the others in this room, am a noob and just have a quickquestion. I am trying to use a Ping))) as well as a servo in combinationwith an arduino board to convert my boring ole light switch into a coolstate-of-the-art motion detector switch. As you may guess, I plan onusing the Ping))) to detect motion up to a certain point and then turn theServo to flip the switch on the light. However, my question comes inthe..physics.., if you will, of the situation. When hooking up this projectis it safe to connect the arduino directly to the power from the house inorder to properly flip the power on and off? I understand the arduinocan carry a maximum of 5V, but the house would be pushing 120V tolight the light bulb. Will I blow the hardware no matter what or is therea way to hook up everything to were the power just goes passed thearduino and onto the light fixture. Thanx for any help at all I am aninspired engineer and am excited to work with this here Arduino

53.

Raphael Cerqueira said,54.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

20 de 33 09-01-2013 19:03

Page 21: Relays with Arduino – Turning on the Lights

October 17, 2010 @ 10:46 pm

I think you would like to see your work been used.

http://arduitter.blogspot.com/2010/10/rf-links-reliable-messaging.html

newbie said,

April 30, 2011 @ 2:14 pm

Hello!

I have a quick question (full disclosure – I suck at all things circuitdesign, programmer here)

Where is the white wire (+5v) going) on the breadboard ?

Thank you in advance…

55.

Rian said,

October 5, 2011 @ 2:30 am

Hi,

Your write up has helped me a lot with getting started in controllingthings with Arduino.

I do have a question about the circuit though that has me stumped.

What modification would I have to make to have an LED come on whilethe relay is off and then have the LED go off when the relay is switchedon without using an output pin from Arduino just to control it.

Thanks,

Rian

56.

Maurice Ribble said,

October 5, 2011 @ 6:37 am

All you need is inverter off of pin3. There are logic buffers that would dothis or you could use a pnp transistor.

57.

Rian said,

October 6, 2011 @ 4:45 am

58.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

21 de 33 09-01-2013 19:03

Page 22: Relays with Arduino – Turning on the Lights

It has been 10+ years since I knew what the common electricalcomponents do so I’m struggling a bit. Is anyone able to elaborate onMaurice’s comment because while I know what these things are andbasically what they do I have no idea how to intergrate them into thecircuit.

Rian said,

October 8, 2011 @ 3:05 am

Ignore the above I worked it out.

59.

kardamyla said,

October 8, 2011 @ 2:29 pm

Hi,I’m and end user, I do not know anything about relays. I been trying fordays to hook up a relay to turn on a light using an Axis camera with anI/O switch. This is the relay http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&itemSeq=105585863&uq=634536768231996536&DPU=submitThis is the manual for the Axis 207 207W camera http://www.axis.com/files/manuals/um_207w_mw_33158_en_1208.pdf. the camera is 3,3 voltwith a max 50ma, I dont even know if this is correct relay. I’m willing topay someone for help me make this work. Thank you

60.

kardamyla said,

October 8, 2011 @ 2:32 pm

This is what I got from Axis

Thank you for contacting Axis Communications. While I have not testeda specific relay to use. I would suggest looking at http://digikey.com asthey have a large variety of relays.

The relay should be 3.3volts and a max of 50ma.

61.

kardamyla said,

October 8, 2011 @ 2:36 pm

This company makes a relay that works but they are asking 70euro=110 dollars plus 30 shipping. For a relay that cost 5 dollars. Iknow they need to make a profit but this outrageous.

62.

kardamyla said,63.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

22 de 33 09-01-2013 19:03

Page 23: Relays with Arduino – Turning on the Lights

October 8, 2011 @ 2:37 pm

Sorry this is the link http://www.ibou.fr/cameras/cameras.html

francis said,

October 30, 2011 @ 8:41 am

hey really i need the circuit fast and i dint understand urs (bcs im notgood)so could just tell me how to connect i saw a 5 pin realy at the storeurs is a 4pin so could ya just show to me i dint get the cicuit (the relaypart)

64.

fabienne said,

November 21, 2011 @ 2:49 am

Hi there, first i’d like to say thanks so much for this super sweet &simple tutorial! setting up the circuit and understanding how thingsshould theoretically work (as an inexperienced arduino tinkerer) was apiece of cake!

there’s only one aspect i am not getting or having problems with. Thisspacebar on off switch doesn’t seem to be working for me. I tried to testout the circuit on an LED but connecting the ground of the LED directlyto the ground on the breadboard and putting the relay inbetween the 5vand the positive lead of the LED. From what i understood this shouldwork..

but then i realized that i dont understand how the arduino ‘knows’ wheni hit the spacebard. i realize its written in the code but in terms ofhardware, how does the arduino recognize the keyboard on mycomputer? It seems like this ought to be a simple solution.

also, any suggestions for how to use a PIR sensor in place of thespacebar?

65.

fabienne said,

November 21, 2011 @ 3:18 am

Nevermind!

simple ‘rookie’ oversight since im so unfamiliar with the arduinoapplication!thank you so much! still looking for any suggestions on integrating thePIR though… !

66.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

23 de 33 09-01-2013 19:03

Page 24: Relays with Arduino – Turning on the Lights

Saw0 said,

November 29, 2011 @ 9:57 pm

fabienne, which PIR do you have, and how do you want it to act exactly?

67.

David said,

January 3, 2012 @ 10:16 am

Thanks for a simple, effective tutorial.

I do have one small problem though. Everything works, apart from whenI connect the diode. I don’t want to fry my arduino with flyback voltagefrom the relay, but the circuit just doesn’t work with it in there.

The diode I have is a 1N4004G, not just 1N4004. Would that make adifference?

Thanks for anyone’s help. I’ll be sure to post again if I manage to work itout.

68.

Chez said,

January 4, 2012 @ 10:59 pm

David, you wouldn’t fry the Arduino, only the transistor. What you mighttry (I’m doing this now) is sinking the relay from the Arduino instead ofthe 2N2222. Most silicon devices can sink (provide connection toground) more current than they can source (provide connection to VCC).I’m running a relay of about the same size directly from the Arduino. Sotie the relay to Arduino pin 3 but tell the code HIGH means off, LOWmeans on.

Here’s a push-button toggle program I modified from the “button.ino”example:

// constants won’t change. They’re used here to// set pin numbers:const int buttonPin = 2; // the number of the pushbutton pinconst int ledPin = 13; // the number of the LED pin

// variables will change:int buttonState = 0; // variable for reading the pushbutton statusint relayState = 0; // relay is off at start

void setup() {// initialize the LED pin as an output:pinMode(ledPin, OUTPUT);

69.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

24 de 33 09-01-2013 19:03

Page 25: Relays with Arduino – Turning on the Lights

// initialize the pushbutton pin as an input:pinMode(buttonPin, INPUT);}

void loop(){// read the state of the pushbutton value:buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.// if it is, the buttonState is HIGH:if (buttonState == HIGH) {// change relay state// see if relay is on or off:if (relayState == HIGH) {digitalWrite(ledPin, HIGH);relayState = 0;// if relay is on, turn it off// counterintuitive, but HIGH turns relay off}else {digitalWrite(ledPin, LOW);relayState = 1;// if relay is off, turn it on// counterintuitive, but LOW turns relay on}delay(250);// debounce}}

Give that a try?

R//Chez

David said,

January 5, 2012 @ 1:53 pm

Hey R//Chez,

Thanks for the tip! I’ve changed the 240v wiring on the relay to [on asdefault], messed around with my code and made it work. (I won’tmention the part when I forgot to turn the transistor around).

Here’s the code I’m using to achieve a randomish strobe of the lampevery few seconds.

Thanks for the help!

70.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

25 de 33 09-01-2013 19:03

Page 26: Relays with Arduino – Turning on the Lights

David

//Blink_Randomly

int ledPin = 3; // Transistor connected to digital pin 3long randOn = 0; // Initialize a variable for the ON timelong randOff = 0; // Initialize a variable for the OFF time

void setup() // run once, when the sketch starts{randomSeed (analogRead (0)); // randomizepinMode(ledPin, OUTPUT); // sets the digital pin as output}

void loop() // run over and over again{randOn = random (30, 130); // generate ON time between 0.1 and 1.2secondsrandOff = random (1000, 6000); // generate OFF time between 2 and 9secondsdigitalWrite(ledPin, HIGH); // sets the Transistor OFFdelay(randOff); // waits for a random time while OFFdigitalWrite(ledPin, LOW); // sets the Transistor ONdelay(randOn); // waits for a random time while ON}

David said,

January 5, 2012 @ 1:55 pm

Forgot to mention, I left the Transistor in, as a safeguard. It’s cheaper toreplace than an Uno.

D

71.

Light controller | Jeff's projects said,

January 15, 2012 @ 5:24 pm

[...] control circuit, not the sensing circuit, was based onhttp://www.glacialwanderer.com/hobbyrobotics/?p=9. The differencebetween my version and his is that I thought the transistor wasunnecessary, so I [...]

72.

Coffee Maker Mod - (Baltimore) Harford Hackerspacesaid,

January 23, 2012 @ 10:11 am

73.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

26 de 33 09-01-2013 19:03

Page 27: Relays with Arduino – Turning on the Lights

[...] wall cord and the power switch on the coffee pot. The relay iscontrolled by his arduino. He used this tutorial as a guide. [Show asslideshow] Share [...]

Sources d’information utilisées « Bon Matex said,

February 15, 2012 @ 11:37 pm

[...] http://www.glacialwanderer.com/hobbyrobotics/?p=9 [...]

74.

Tim said,

February 18, 2012 @ 8:57 pm

Hello people,

Thanks for the great tutorial, very easy to follow.But unlike Fabienne, who said: “but then i realized that i dontunderstand how the arduino ‘knows’ when i hit the spacebard. i realizeits written in the code but in terms of hardware, how does the arduinorecognize the keyboard on my computer? It seems like this ought to be asimple solution.”,I can’t to overcome the simple rookie oversight. Could anyone help meout and explain to mehow the keyboard function works?

Many many thanks!

Tim

75.

Roombox Blog | Third functionality: Switching relaysusing arduino said,

March 1, 2012 @ 10:08 am

[...] i’ve managed to switch relays using my arduino kit. I found thiscircuit on the web and edited it to switch a couple of relays instead of[...]

76.

Easiest/cheapest way to computerize and automate agrow? said,

March 30, 2012 @ 10:57 pm

[...] moisture sensors that can be connected to a computer? (1)Microcontroller + Relay = WIN http://www.glacialwanderer.com/hobbyrobotics/?p=9 (2) Plenty of OTC temp, and humidity sensors tochoose from. Soil moisture should just be a [...]

77.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

27 de 33 09-01-2013 19:03

Page 28: Relays with Arduino – Turning on the Lights

Diego Aguilera said,

May 21, 2012 @ 10:38 am

NO and NC relays.

First off, I don’t want to scare anyone off from doing a project like this.This is just a caution. Relays come in different variations: normally open,normally closed, and CO (Change over). Depending on your project,depends on the relay you need to buy. For example, if you have a circuitthat will constantly be on and off when the Arduino sends a voltage to it,you want a normally closed. If your light is normally off and turns onwhen the Arduino tells it to turn on, then buy a normally open. Thereason for picking the correcnt relay is current. Because a relay willalways have some internal resistance, you will have power loss in therelay (P = i*r). This loss is always in the form of heat. Normally closedrelays are designed to be able to handle current being constantlysupplied. If you don’t account for this current, the relay could burn up.Not to say it’s going to catch fire. It will most likely smoke and justnever work again. But why risk it? I’ve also used this same circuit with arelay from Sparkfun to turn my Christmas tree off/on for a few weeks. Itworked just fine. Great write up!

78.

Salvo's Blog said,

June 8, 2012 @ 8:03 am

Scheda relè / Relay Shield…

Realizzare una scheda relè è abbastanza semplice (Immagini realizzateutilizzando fritzing) Necessario: 1 Prototyping board 1 Relè 5V DC(SRD-05VDC) 1 Diodo 1N4007 1 Resistenza da 1 kΩ (io ho usato una da465Ω e va bene lo stesso) 1 Transistor NPN (2…

79.

Cool Data Log images | The art of data acquisition said,

June 21, 2012 @ 2:53 pm

[...] Image by jmsaltzman First mockup of Arduino-controlled garden,here switching a relay attached to a submersible pump to automaticallywater two [...]

80.

Arduino Garage Door Opener Pt 2 | The Heffies said,

July 27, 2012 @ 7:49 pm

[...] done it even close to correctly. To do so, I used this Arduino sketchthat this fellow had on his site, that allows you to control the relay using

81.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

28 de 33 09-01-2013 19:03

Page 29: Relays with Arduino – Turning on the Lights

the serial interface on the Arduino, by hitting the [...]

Mr.Mechatronics said,

August 10, 2012 @ 5:59 am

Hi there,This is more interesting question…Speaking of Home automation/security:

I have a relay which I will be using to bypass my existing switch(light)SPSTCondition1:Ardruino will turn on the relay (let say PIN 13) stand alone, withoutcommunicating with the computer.Condition2:The output will trigger using its internal clock , let say 1st day :12:00am up to 12:15am then switch on 12:30am-12:32…….RANDOM time inRANDOM INTERVAL……up to 3:00am.Condition 3:Audrino will make a random combination in 7 days…but limited onlybetween 12:00 to 3:00am.(to fool the burglars that they are expected…hmmmm)I hope that this will also be helpful to others…never mind the electricbill ….security is PRICELESS!And please help me with the code.. A only know basic switching—-ramdomized switching give me headache!TNX in advance

82.

Taku said,

August 21, 2012 @ 11:54 pm

Hey there, very great project. I live in europe and since the color codingis different and can even differ from cable to cable could you please tellus exactly which wire you connected to what pin on the relay and alsotell us which color is which on your particular cable. Is it black –liveWire/phases ; green – ground ; white – neutral ???And why does the green cable have two different greens with the onemore cyan looking?? Shouldn’t the green part be the same color if thecable was spliced ? Why is the black wire twisted together with thegreen one under the cap ? And on what pin did you connect the blackand the green to the relay. I understand most of the stuff but those arethe things that confuse me.

Also if I look at http://www.glacialwanderer.com/_blog/blog2008/04_April/hb_relay1.jpgI can see 9 cables: 2 black cables going to the relay, 2 green cables

83.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

29 de 33 09-01-2013 19:03

Page 30: Relays with Arduino – Turning on the Lights

going to the relay, 2 green (more cyan looking) cables + 1 black cableunder the cap, 2 white cables under a cap,

So if I’m counting correct thats 9 cables from a spliced wire that had 3wires before being spliced. So if my math doesn’t trick me 3+3 makes 6.Please explain. Are those the wires that would be going to the arduino??

It would be really nice if you could answer my question so I could go onwith my project. Thanks a lot.

Interruptor “touch” com Arduino Pro Mini said,

August 30, 2012 @ 11:15 am

[...] à parte técnica, usei isso para o relé, só troquei o transistor 2N2222por um BC548 (tem funcionado bem). E o código, usei o exemplo da [...]

84.

more details said,

September 14, 2012 @ 1:10 am

I’m really inspired along with your writing talents as smartly as with thelayout on your blog. Is that this a paid subject or did you modify it yourself? Either way keep up the excellent high quality writing, it isuncommon to peer a great weblog like this one these days..

85.

J5 said,

November 8, 2012 @ 4:29 pm

Great project! what does the diode do in this circuit and why do we needit? Also, what does the transistor do and why do we use it?

86.

Derek Harrington said,

November 16, 2012 @ 5:31 pm

Both of these are for using the +5 volts to switch the relay. I think theouput pins on Arduino are not a full +5V, but there is a constant 5Vsource on the board. This is not a “pin” though.

So, Arduino pin 3 goes to the base of the transistor. Activating the basewill let current flow through the collector to the emitter side. (top tobottom on the schematic).

If you look at the 5V source at the top, it is linked to the relay and outthe relay down to the transistor. So, there is always 5V at the relay, but

87.

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

30 de 33 09-01-2013 19:03

Page 31: Relays with Arduino – Turning on the Lights

the transistor is keeping it from being grounded. Once pin 3 goes high,the transistor opens and the 5V source can run current to ground. Thenthe relay will be tripped. The 5V has to be able to get to ground.

The diode only lets current flow one way. If it got to choose it would gothe path of least resistance, so it may not go through the relay. Thediode forces the current from the 5V source to go through the relay.

dZ. said,

November 20, 2012 @ 12:54 pm

quick nice and easy

thank you !

my 0.1 prototype works like a charm on an arduino ethernet connectedto a cheap wifi router.0.2 will use v usb to connect a classic arduino to the router through usb,next will use a ATtiny84 in place of the arduino )

see ya !

88.

Brad said,

November 29, 2012 @ 3:13 pm

HAHAHA yes!!thank you so much! its very simple, and straight forward. Up until now ihave been making manual switches from motors that physically turn thedial or switch on anything that was 120v. That was taking a very longtime, and using all my motors to turn the on / off switches. I keptthinking there has got to be a better way! Obviously i am new tothis..but you made it so easy… A relay hunh? what a beautiful thing.

89.

jek said,

December 28, 2012 @ 4:25 pm

how about adding physical switch of the bulb..because it is essential tohave a hardware part switch not only in the arduino. Does anybody canmake it?

90.

RSS feed for comments on this post · TrackBack URI

Leave a Comment

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

31 de 33 09-01-2013 19:03

Page 32: Relays with Arduino – Turning on the Lights

Name

E-mail

URI

Submit Comment

CAPTCHA Code *

Search

Links

ForumsLife is for the LivingStore

Categories

ArduinoCircuitCNCPhotographySensorUncategorized

Archives

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

32 de 33 09-01-2013 19:03

Page 33: Relays with Arduino – Turning on the Lights

August 2011July 2011March 2011February 2011January 2011October 2010September 2010June 2010April 2010February 2010December 2009November 2009August 2009June 2009March 2009January 2009December 2008November 2008October 2008September 2008August 2008June 2008May 2008April 2008

Meta

RegisterLog inEntries RSSComments RSSWordPress.org

Contact Info

Please feel free to email me with questions about an article, consultingwork, product review requests or any other reason you [email protected]

Design by Beccary and Weblogs.us · XHTML · CSS

Hobby Robotics » Using Relays with Arduino – ... http://www.glacialwanderer.com/hobbyrobotics...

33 de 33 09-01-2013 19:03