Você está na página 1de 7

Home Sign Up!

Explore Community Submit


All Art Craft Food Games Green Home Kids Life Music Offbeat Outdoors Pets Photo Ride Science Tech

Connecting a 12V Relay to Arduino


by gandalfsz on January 16, 2009 Table of Contents License: Attribution Non-commercial (by-nc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Intro: Connecting a 12V Relay to Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 1: Measure the coil resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 2: Calculate how much current will flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 3: Choose your Transistor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 4: Calculating R1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 5: Choosing your diode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 6: The Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 7: Assembling the Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . step 8: The Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 2 3 3 3 4 4 4 5 5 5 5

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

License: Attribution Non-commercial (by-nc) Intro: Connecting a 12V Relay to Arduino


To connect a 12V Relay to the Arduino you need the following things: - 1 Arduino - 1 Diode for example 1N4007 - 1 NPN Transistor for example 2N2222 (in US) or BC548 (in Europe) - 1 Relay for example one with coil voltage 12V and switching voltage 125V AC max 10 A - 1 Multimeter

Image Notes 1. 12V Relay 2. Arduino Duemilanove 3. 1N4007 Diode 4. Transistor 5. Wire

Image Notes 1. max rating of things you could connect in this case: Not more than 10 Ampere 125V AC 2. german for coil 3. 12V DC thats the Voltage the Relay needs to switch

step 1: Measure the coil resistance


We are going to measure the coil resistance to calculate the current. First we must find the coil: On some relays the pins are labeled so you can just measure at pin 2 & 5. Otherwise you have to measure at every pin: Between two pins you should have between 100 and 10 000 Ohm. Remember that value. That are the two terminals of the coil. The coil is not polarized so its not important which one goes to V+ or GND. If you have found those there are only three left. Between two should be a connection (if you measure a few Ohm its okay but everything above 50Ohm is too much). One of them is NC and one is COM. To find out which is which let one probe connected and connect the other to the pin thats left over. If you connect the coil to 12V DC it should make a clicking noise. If your mulimeter now shows a low resistance you have found COM and NO. The one probe you didn't move is COM the other is NO.

Image Notes

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

Image Notes 1. Pin 1 COM 2. Pin 2 Coil A 3. Pin 5 Coil B 4. Pin 3 NO (= Normally Open) 5. Pin 4 NC (= Normally Closed)

1. The measured Resistance 0.41 KOhm means 410 Ohm 2. Range 20k 3. If this Button is pressed the Value will stay at 0.00

step 2: Calculate how much current will flow


The formula you need is a simple one: (maybe people in England or the US know the Voltage as "V" but i will refer to it as "U" as we call it in here) U=R*I Ok, but we want the current "I" rigtht ? So just divide through the Resistance "R". U = R * I / :R I = U/R For my relay that would be: I = 12V / 400Ohm I = 0.03 A => 30 mA (That is Ic) The Arduino can handle up to 20mA but its better to use a transistor even if your current is only 20 mA. So for 30mA you definitely need one.

step 3: Choose your Transistor


First find the Datasheet of your transistor. For example search for "2N2222 datasheet". Your Transistor should achieve the following things: - It has to be NPN not PNP !! - Ic should be bigger than the Value you calculated in step 2 - Vceo should be bigger than the supply voltage

step 4: Calculating R1
You can find the value of hfe in your datasheet: Mine says for BC548 its 75 at 10mA at 10V. Its not very precise cause its very difficult to build transistor with a accurate hfe. hfe = Ic / Ib We know hfe and Ic so lets calculate Ib: Ib = Ic / hfe For BC548: Ib = 0.03 A / 75 Ib = 0.0004 A => 0.4 mA Due to Ohms Law: R1 = U / Ib R1 = 5V / 0.0004 A R1 = 12500 Ohm

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

This is not very accurate to so we use 10kOhm.

step 5: Choosing your diode


The diode is needed cause the voltage will rise high if you suddenly change the voltage at the inductor. The formula for the voltage is: U_L = - L * delta i/delta t So theoretically if delta t equals zero U will be infinite. But due to the minus in front you can add a diode in the "false direction" parallel to the relay. So the current can flow till its zero so the voltage is also zero.

step 6: The Schematic


Finally here is the Schematic:

Image Notes 1. Connect the ground of your 12V source to the ground of your Arduino 2. If you forget that Diode you could destroy your Arduino. 3. The coil of your relay 4. R1 limits Ib 5. B 6. C 7. E

step 7: Assembling the Circuit


Your datasheet says which pins are E, B and C. Before you connect your Arduino connect a 4.5V Batteries negative Terminal to GND and its positive Terminal to R1. The relay should make a clicking noise if not check your circuit.

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

Image Notes 1. Many 12V relays work also at a bit lower voltage (like 9V) 2. The relay 3. R1 4. D1 5. Transistor 6. Connection between Arduino and the relay ground 7. USB conneection

step 8: The Program


The test program is just an edited version of the "Blink" example: /*-----------------------------------------------------------------------------------relaytest | Author: gandalfsz | Date: 18 Jan 2009 | Function: Toggles Pin 13 every 10 Seconds | */----------------------------------------------------------------------------------int outPin = 13; void setup() { pinMode(outPin, OUTPUT); } void loop() { digitalWrite(outPin, HIGH); delay(10000); digitalWrite(outPin, LOW); delay(10000); }

Related Instructables

Solderless Breadboard Layout Sheets (plug and play electronics) by oomlout

Time-Lapse Photography by randofo

Powering the Arduino Mega with a Lithium Battery by inthebitz

Web Controlled Valentine by gschoppe

Properduino When an Engineer Gardens - Part 1 - Le Propergator Watering System by grahamslawson

How to Program the Vexplorer Using Arduino by robotkid249

Arduino Tutorial Bundle .:Arduino Experimentation Kit:. (ARDX) by oomlout

Build a real bellstriking clock for your PC and a fire extinguisherstriking clock. by 5Volt

Advertisements

Comments
18 comments Add Comment

Decypher4 says:

Jan 19, 2009. 7:44 AM REPLY Why are you using a 12V excitation relay with the Arduino? 5V excitation SSRs that can handle a 120V 40A AC load are cheap and readily available. Did you just have a 12V relay laying around?

gandalfsz says:
Yes it was the only I had @home, its from an old washing machine. Where do you get cheap 5V SSRs ? In here the are expensive. greetz Daniel

Jan 19, 2009. 12:29 PM REPLY

Doom2099 says:
SPDT 5v amp realy $5.08 radioshack direct2U order

Sep 9, 2009. 1:56 AM REPLY

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

Decypher4 says:
I guess it also depends on your definition of cheap. This one is $15.00 US http://www.allelectronics.com/make-a-store/item/SSRLY-42/40-AMP-SOLID-STATE-RELAY/1.html

Jan 19, 2009. 3:14 PM REPLY

There are a bunch here too. There's a million different options to sort through, and I've seen them as cheap as $9.00 US. http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=1048664&keywords=solid%20state%20relay Happy hunting. Cheers

andrew101 says:
well i can get a 12 volt relay with 2 seperate switches for 4 $ canadian at my local ripoff store. i suppose i could get them cheaper online but its eaiser to buy them there.

Aug 15, 2009. 5:17 PM REPLY

gandalfsz says:
Ok in here you can get one like mine for ~1 (= 1,2951$) greetz Daniel

Jan 20, 2009. 6:18 AM REPLY

Decypher4 says:
That's cheaper than 9 bucks. Good instructable.

Jan 21, 2009. 7:25 AM REPLY

andrew101 says:

Aug 15, 2009. 5:15 PM REPLY cool. i made oneawhile ago that i can trigger thru serial to turn on and off some relays. i didn't realise i should add a diode. good tip :)

jtbz76 says:

Jun 29, 2009. 10:40 AM REPLY I made this circuit and when the 5v signal from arduino is off the the relay stays on until the 12 volts is disconnected. Its like the transistor is staying on. Any hints??

gandalfsz says:
What is the number on your transistor ? Sure that its a transistor not a triac or something ?

Jun 29, 2009. 11:09 AM REPLY

jtbz76 says:

Jun 29, 2009. 9:24 PM REPLY Nope i didnt pay attention that the diagram said view from bottom so i had the emitter and collector reversed. works great thanks!!!

inane says:

Feb 17, 2009. 2:23 PM REPLY Can I do without the transistor? I have a reed relay that claims a nominal current of 20mA...shouldnt the Arduino be able to drive it directly?

gandalfsz says:
If it really only needs 20mA it should be ok with Arduino, but it is better for the Controller if you use a transistor.

Feb 21, 2009. 2:23 PM REPLY

russ_hensel says:

Jan 20, 2009. 5:31 PM REPLY Microwave ovens ( the control panel ) usually have this type of relay ( more or less ) sometimes 3 of them. Coil voltage typically 12 or 24 volts. Voltage need not be very exact or regulated. Cost normally 0, priceless if you manage to kill yourself on the high voltage.

RCURV says:
super useful, I'm planning a sub project an this is just the thing

Jan 19, 2009. 2:02 PM REPLY

joejoerowley says:
Great! I was just looking for something like this! Thanks, Joe

Jan 18, 2009. 4:57 PM REPLY

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

Bongmaster says:
usefull :)

Jan 18, 2009. 12:07 PM REPLY

gandalfsz says:
Thanks :-)

Jan 18, 2009. 1:15 PM REPLY

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

Você também pode gostar