# 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 the US) or BC548 (in Europe)

- 1 relay for example one with coil voltage 12V and switching voltage 125VAC/10 A

- 1 multimeter

## 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 that’s left over. If you connect the coil to 12V DC it should make a clicking noise. If your multimeter now shows a low resistance you have found COM and NO. The one probe you didn't move is COM the other is NO.
 1-40 of 56 Next »
ConnorN31 month ago

Built it today, and it worked just as the author said it would. Only difference was that I substituted a different diode (1N4001) instead of the one suggested.

Thanks for the build!

Ok can someone tell me why da hell do we need a transistor or a mosfet if your using a relay? the both work the same way only that one is for Ac power "relay" and the other is for Dc power "transistor/mosfet" GATE/ latch on the transistor just needs 5v to trigger it and the same can be said about the relay it needs 5v to trigger the gate /SIGNAL to open/close the circuit so whats the point? BUT even a some relay's can be used with Batteries for DC 12-30V @ 10-30A not just AC so again why use a transistor? i can see why the diode or even a resistor but a NPN or PNP com'on someone break it down just as i have.

1 month ago

As the author stated: he use a normal 12v relay (maybe the only one he had at hand)

and it take 30mA from 12v control source.

If you apply 5v directly to the coil of 12v relay using IO pin of arduino maybe the current is not enough to switch the latch since 5v / 400 ohm = 0.0125 A or ~13mA compare to typical 30mA of 12v relay. So you have to use a transistor as a switch so that you can use 5v source of arduino to switch on 12v source to power the relay. Any 12v source would be fine if it is able to provide current larger than 30mA.

If you use 5v relay and use arduino IO pin to drive the relay directly, the coil resistor is around 70 ohm which needs ~71mA to work. This time 71mA excess the absolute 40mA current limit of arduino IO pin. It will likely damage your arduino. So again, you have to use transistor as a switch to amplify the current apply to the relay coil.

These are typical relay you will find on ebay.

Yes, when using a single mosfet or transistor, you need less components but it is more complicate with calculation and less flexible in general applications. Say, you wish to turn on a small LED stripe or a garrage door motor, the easiest way is using a relay.

1 month ago
ok so i just have to use a transistor or in my case a mosfet since im playing with DC motors who are higher then spec of both the MCU & Relay? and the mosfet i choose will have to have a output current of more then 71mOhms ? so that the current of the mosfet can pass thru the coil and make it to the gate of the triggering pin which activates the relay function ? on the relay it self?
1 month ago
ok i can take that i do see your logic, thanks for that @1413

tho now hear my point of view'

you said:
5v / i40mA = 0.0125 ohms or ~13 ohms compare to typical 30mA of 12v relay.

So if arduino has 40mA and the relay needs 30mA doing your math i see no reason for the over kill, the arduino looks like supplying 40mA of which the relay only needs 30mA as you said, so what is it im not understanding? theirs a extra 10mA of a overkill so if anything a resistor should be used to not fry the relay from excess mA's

on your 2nd statement your saying the coil of the relay is 70 ohms
so RxI=V (70 ohms x 30 mA = 2100)
whats going on?
1 month ago

ah I see, you misunderstood some concept.

Ohm laws: R*I = V or I = V / R.

and we work with Ampere and Volt and Ohm, if it is mA or mV or kOhm, you have to convert it to standard unit to work with the equation.

First, the recommended current of each IO pin of arduino is 20mA. The absolute Maximum Ratings - the point where damage will start to happen: DC Current per I/O Pin ........... 40.0 mA

http://playground.arduino.cc/Main/ArduinoPinCurren...

So anything that draw more than 20mA on a single IO pin is not recommended for a long time.

Second, you misunderstood my equation:

400 ohm is the resistor of the coil of the 12v-relay.

- If you apply 12v on the coil the, equation is:

I = V / R = 12 / 400 = 0.03 Ampere (30 mili Ampere)

This 30mA is the normal working condition of the relay under 12v control source

- But if you apply 5v on the coil, the equation would be:

I = V / R = 5 / 400 = 0.0125 Ampere (~13mili Ampere)

This maybe not enough to switch the latch.

And your equation : 5v / i40mA = 0.0125 ohms is not correct.

The correct equation is

R = V / I = 5v / 40mA = 5v / 0.04 A = 125 Ohm.

This means, if you can find a relay with the coil resistor is about 125 Ohm. It might work.

And this one is wrong too: RxI=V (70 ohms x 30 mA = 2100)

It should be 70 ohm x 30mA = 2100mV = 2.1v

It means if you have a 70 ohm coil, you want a current of 30mA goes through it, you will need to apply a voltage of 2.1v

OK. For a eqation like I*R = V , you should find which variable is the constant and which is not or what is known and what is not known so that you find the unknown.

Resistor, voltage = constant. You likely can't change them but you CAN mesure them using volt-ohm-meter BEFORE connect the coil to arduino. That leave Current is unknown. You haven't connect them so you can't mesure the actual current flow through the coil. And 30mA we are talking about is the ideal value for the coil to work, not the real current flow through the coil in real circuit.

Hope this will clear your mind.

JesseR53 months ago

Why do you show a 9V battery source when 12V is specified?

The specs for Duemilanove say pins can provide 40mA, not 20mA. If the relay coil was 5V 30mA you could power it with the 5V pin correct?

I don't understand transistors very well. A base current of .4mA with 75hfe will allow 30mA to pass from the 12V source and switch the relay, correct?

akshat gupta4 months ago
Kindly tell me how much oms resistance do we have to use to connect ardino and circuit please tell me as you connected please tell me as soon as possible
I made the circuit with 6v relay which I really needed. The instructions were really easy to follow.

I controlled a white led and a yellow led with the relay. The red led shows the status of digital pin.

It was fun to make!
Thank you!
mabedin16 months ago

The Ground from 12 Volt that is used to drive your Motor or other device is shared by the Arduino Ground and the Negative - 12Volt, this way Pin 13 is isolated & receives no +12 Volts which would obviously damage it. The relays trigger Current must be within Transistors power range, if well below milliamp (200Ma) should be OK, but a large one may be no good buy one off Bay is that's the case.

Eloisa CamelM6 months ago

thank you for this info..
but can i use 12v 120vac/10A RELAY? instead of 125vac?

Eloisa CamelM6 months ago

thank you for this info..
but can i use 12v 120vac/10A RELAY? instead of 125vac?

SasonoG7 months ago

5v arduino pin goes to transistor then goes to relay (which is need 12v), then where do relay get its 12v?? correct me if im wrong..

Anuj FALCON8 months ago

Very good

reedict1 year ago

it doest work ... your negative from the battery goes were???

1 year ago

Ground. This is the most simple control of a relay with a uC and it works. Have fun!

SamiulI1 year ago

First of all, I am new at this. So, if you start from the very basic, it would be helpful for me.
I have an 8pin 12v relay [exactly same as the given pic] and i don't have the pin configuration & datasheet. I want to make an water alarm system. Based on the water level I can control an LED without any hassle as arduino serves 5v which is enough for that LED.

Now I want to turn on a 12v speaker instead of the LED. Arduino cannot provide that desired 12v. Someone asked me to buy a relay and N-mosfet and these will do the job. But, i cannot understand a line. Could you please help me to build my circuit? I will be really thankful.

bogd1 year ago

Just one question (and please forgive me if you already mentioned this somewhere else): shouldn't it be R1=(U-Ube)/Ib?

With BC548 having a typical Ube ov around 0.7V, this would make it (5-0.7)/0.0004 = 10.75 KOhm.

Which makes your chosen value (10K) even more accurate :)

feedel1 year ago

I have 4 relays and I want to control it by Arduino form the following:

1 - if first relay work by Button No. 1 even if we pressed on any Switches last three relays will not work

2 - If the first switch off the second is work and it control on the third and fourth

3 - If the first and second switch off , third relay is working after pressing button 3

4 - If the first and the second and the third switch off ,forth relay is works after pressing button 4

5 -If the first switch working another time ,first relay is working and all another relays is off.

please how it work and sketch.

Hi. I love your article here it is very informative. I tried to make this and was somewhat successful. I say somewhat because it sorta works. When connected to my arduino uno it pulses like it is supposed to. I know because I checked the continuity between the emitter and the collector. It is clearly only open when the base has voltage to it. The problem I am having is even with no voltage to the base I connect my 12vdc power source (a car battery), and it seemingly ignores the transistor in the circuit and powers the relay coil. The coil does not lose power until the power source is disconnected. I am using the same transistor as you and the same diode. My relay is a 12v/12v and the resistance of the coil is 83 ohms making my resistor a 2.2k (tried a 2.7k it was to high). If you could help me out in understanding this it would be much appreciated.

1 year ago

Hello, I have a similar problem. I've successfully made your circuit using a 2N2222A transistor. I couldn't get the 10k resistor to work with it, so I tried a 1k which didn't work either. I then tried a 330 ohm resistor which seems to work. Only now the transistor pulls in the relay when it should but then latches, keeping the relay on until I remove the 12V supply to the coil completely. Any suggestions?

1 year ago

What are the ohms on the coil of your relay.

homunkoloss (author)  slr13371 year ago

Hey,

can you post a picture of the relay where one can see the label?

Regards,

Daniel

1 year ago

Thank you for getting back to me. I actually had a suggestion from a forum I posted on suggesting that I had the transistor's emitter and collector switched around. This was the case is working good now. Thank you.

Umair.saeed52 years ago
Nice Thanks man
KJ4ZVQ2 years ago
Nice! I had one in the making. Good point of showing the power formula to keep from burning up your board(that makes for a VERY bad day)!
Del Carmen2 years ago
Cool ! Now I know how to interpret the relay. I finally understood. very nice, thank you. Del Carmen
renefabri2 years ago
1. The photo does not show where are connected the green wires at the top, and the yellow wires at the bottom. Am I right to guess at the top (green) is a circuit with a lot of voltages and current (maybe 5V to 220V and 1A to 10A), and at the bottom (yellow) is a 4.5V battery?
2. The R1 resitor, is it what is called a pull-up resistor? I am puzzled because I don't see any connection to the 5V of the Arduino.
best tutorial ever
thank you so much
i searched the net alot
and that is the best one on the net
thanks alottt :)
salvocanna3 years ago
It's almost the same... but the relay is 5V and is a shield.. take a look :)
jashan5103 years ago
my coil resistance is just 71ohm so Ic comes really high
if i put a resistor in series wid d coil would it work?
dcutler19583 years ago
I'm a bit lost on the step of choosing a diode. How do you pick a diode knowing the current that passes across the relay coil?
gamingman3 years ago
Major point: Make sure you connect the 12V ground to the Arduino ground, or it will not work.
gabriel.hahmann4 years ago
I'm using a 5v relay and It is not working. By mistake I bought a 2N2222A, wich I saw on the datasheet had a Vebo of 6V, could you tell me if these is the problem? Congratulations for the great howto!
thecageybee5 years ago
Hi there.   Brilliant post.   Very informative, the formulas you have provided have been very helpful, as without them I'd of just been blindly putting components together.  Likely with disastrous results.

I've got a couple of questions for you though.

First the easy one.  Could you explain the formula in step 5.  What is "U_L", "L", "delta i" and "delta t"?  Where do I find their values in regards to the components I'm going to use.  Just not sure if it matters what rating diode I use, or if it's merely mathematical proof that I will need a diode and any diode will do.

Lastly, I'm going to be applying this for a project of my own, but want to make sure I can get the relay circuit working before I get an Arduino.  Can I simulate the arduino by applying a 5v positive to where the arduino would go, with the negative to ground in the circuit?

Again, many thanks for this guide, and thanks for any help you can give me.

Regards,
The Cageybee
homunkoloss (author)  thecageybee5 years ago
"U_L" (L is meant to be the index) is the voltage at the relays coil, Im writing U instead of V because thats how I learned it and how its written in europe. "L" is the inductance of your relays coil. "delta I" is the change of the current and "delta t" is how fast you apply the Voltage (Sorry cant explain this better). The problem is that the Voltage rises very high (probably about 100 to 300 V, but not harmfull because of the low current), this could destroy the transistor. So when choosing your diode you should use one that can stand high voltages.
5 years ago