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
This is not very accurate to so we use 10kOhm.
<p>I have 5V relay with 70 OHM coil resistance,and i'm using 2N2222A transistor and it doesn't work with Arduino ???!!!!! any help please???</p>
<p>Can some1 post diagram on how to use the relay with arduino with 12V 1A power supply to Arduino and no different power source for the relay.</p><p>Also note the protection diode is needed.<br>I have made the relay work but not with the protection diode.<br>And engineers, please, in the diagram please display from with pin to which pin the diode is used for newbies like me.</p><p>Thank you.</p>
<p>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.</p><p>Thanks for the build!</p>
<p>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 &quot;relay&quot; and the other is for Dc power &quot;transistor/mosfet&quot; 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.</p>
<p>As the author stated: he use a normal 12v relay (maybe the only one he had at hand)</p><p>and it take 30mA from 12v control source.</p><p>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.</p><p>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.</p><p>These are typical relay you will find on ebay.<br><br>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.</p><p>Sorry for my bad english</p>
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 &amp; 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?
ok i can take that i do see your logic, thanks for that @1413<br><br>tho now hear my point of view'<br><br>you said:<br>5v / i40mA = 0.0125 ohms or ~13 ohms compare to typical 30mA of 12v relay.<br><br>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 <br><br>on your 2nd statement your saying the coil of the relay is 70 ohms<br>so RxI=V (70 ohms x 30 mA = 2100) <br>whats going on?
<p>ah I see, you misunderstood some concept.</p><p>Ohm laws: R*I = V or I = V / R.</p><p>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.</p><p>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</p><p><a href="http://playground.arduino.cc/Main/ArduinoPinCurren..." rel="nofollow">http://playground.arduino.cc/Main/ArduinoPinCurren...</a></p><p>So anything that draw more than 20mA on a single IO pin is not recommended for a long time.</p><p>Second, you misunderstood my equation:</p><p>400 ohm is the resistor of the coil of the 12v-relay.</p><p>- If you apply 12v on the coil the, equation is:</p><p>I = V / R = 12 / 400 = 0.03 Ampere (30 mili Ampere)</p><p>This 30mA is the normal working condition of the relay under 12v control source</p><p>- But if you apply 5v on the coil, the equation would be:</p><p>I = V / R = 5 / 400 = 0.0125 Ampere (~13mili Ampere)</p><p>This maybe not enough to switch the latch.</p><p>And your equation : 5v / i40mA = 0.0125 ohms is not correct.</p><p>The correct equation is </p><p>R = V / I = 5v / 40mA = 5v / 0.04 A = 125 Ohm.</p><p>This means, if you can find a relay with the coil resistor is about 125 Ohm. It might work.</p><p>And this one is wrong too: RxI=V (70 ohms x 30 mA = 2100) </p><p>It should be 70 ohm x 30mA = 2100mV = 2.1v</p><p>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</p><p>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.</p><p>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.<br><br>Hope this will clear your mind.</p>
<p>Why do you show a 9V battery source when 12V is specified?</p><p>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?</p><p>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?</p>
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. <br><br>I controlled a white led and a yellow led with the relay. The red led shows the status of digital pin.<br><br>It was fun to make!<br>Thank you!
<p>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 &amp; 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. </p>
<p>thank you for this info.. <br>but can i use 12v 120vac/10A RELAY? instead of 125vac?</p>
<p>thank you for this info.. <br>but can i use 12v 120vac/10A RELAY? instead of 125vac?</p>
<p>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.. </p>
<p>Very good</p>
<p>it doest work ... your negative from the battery goes were???</p>
<p>Ground. This is the most simple control of a relay with a uC and it works. Have fun!</p>
<p>First of all, I am new at this. So, if you start from the very basic, it would be helpful for me.<br>I have an 8pin 12v relay [exactly same as the given pic] and i don't have the pin configuration &amp; 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.<br><br>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.</p>
<p>Just one question (and please forgive me if you already mentioned this somewhere else): shouldn't it be R1=(U-Ube)/Ib? </p><p>With BC548 having a typical Ube ov around 0.7V, this would make it (5-0.7)/0.0004 = 10.75 KOhm.</p><p>Which makes your chosen value (10K) even more accurate :)</p>
<p>I have 4 relays and I want to control it by Arduino form the following:</p><p>1 - if first relay work by Button No. 1 even if we pressed on any Switches last three relays will not work </p><p>2 - If the first switch off the second is work and it control on the third and fourth </p><p>3 - If the first and second switch off , third relay is working after pressing button 3</p><p>4 - If the first and the second and the third switch off ,forth relay is works after pressing button 4 </p><p>5 -If the first switch working another time ,first relay is working and all another relays is off. </p><p>please how it work and sketch.</p>
<p>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.</p>
<p>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?</p>
<p>What are the ohms on the coil of your relay.</p>
<p>Hey,</p><p>can you post a picture of the relay where one can see the label? </p><p>Regards,</p><p>Daniel</p>
<p>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.</p>
Nice Thanks man
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)!
Cool ! Now I know how to interpret the relay. I finally understood. very nice, thank you. Del Carmen
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? <br>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 <br>thank you so much <br>i searched the net alot <br>and that is the best one on the net <br>thanks alottt :)
I made this: <a href="http://blog.salvocannamela.it/scheda-rele/" rel="nofollow">http://blog.salvocannamela.it/scheda-rele/</a><br> It's almost the same... but the relay is 5V and is a shield.. take a look :)
Very useful :) And I bought all these stuff on www.sainsmart.com They are very patient with all my questions. I recommand this store.
my coil resistance is just 71ohm so Ic comes really high <br>if i put a resistor in series wid d coil would it work?
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?
Major point: Make sure you connect the 12V ground to the Arduino ground, or it will not work.
A U.S. State Department official confirmed the meeting took place but said it was only to deliver a clear and firm message that Gadhafi must step <a href="http://www.mbtcheapest.com/" title="MBT Shoes"><strong>MBT Shoes</strong></a> down. The U.S. official said it was not a negotiating session and no future meetings were <a href="http://www.mbtcheapest.com/" title="MBT Outlet"><strong>MBT Outlet</strong></a> planned.The talks came after Friday's decision by the United States and more than 30 other nations meeting in Istanbul to recognize the eastern-based rebels fighting Gadhafi's government as the country's legitimate <a href="http://www.mbtcheapest.com/" title="MBT Footwear"><strong>MBT Footwear</strong></a> representatives,<br><br><a href="http://www.mbtcheapest.com/" title="MBT On Sale"><strong>MBT On Sale</strong></a><br><a href="http://www.mbtcheapest.com/" title="MBT Walking Shoes"><strong>MBT Walking Shoes</strong></a><br><a href="http://www.mbtcheapest.com/" title="MBT Shoes Clearance"><strong>MBT Shoes Clearance</strong></a><br> <br>He described it as a &quot;a first-step dialogue&quot; to see about repairing relations between the two <a href="http://www.mbtcheapest.com/" title="Cheap MBT"><strong>Cheap MBT</strong></a> countries, U.S. lawyer Deirdre Agnew helped persuade a court in Chester County, <a href="http://www.mbtcheapest.com/" title="http://www.mbtcheapest.com/"><strong>http://www.mbtcheapest.com/</strong></a> Pennsylvania, to accept the couple's testimony via Skype.
President Barack Obama last year signed a landmark <a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin"><strong>Christian Louboutin</strong></a> law repealing the policy that forced gays to keep their sexual orientation secret if they want to be in the military. The Pentagon has been in the process of writing rules for the new policy.The issue of <a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin Shop"><strong>Christian Louboutin Shop</strong></a> military service has long been a key issue for the gay community, along with same-sex marriage.Last year, a California district court judge found that the &quot;Don't Ask, Don't Tell&quot; policy violated the U.S. Constitution, and issued an injunction. But the 9th Circuit U.S. Court of Appeals put that injunction on hold as the Department of Justice appealed the ruling.In an order on <a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin Store"><strong>Christian Louboutin Store</strong></a> Wednesday, a three judge panel of the 9th Circuit noted that the process of repealing DADT is now &quot;well underway.&quot;The <a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin for Sale"><strong>Christian Louboutin for Sale</strong></a> government &quot;can no longer satisfy the demanding standard&quot; to keep the injunction on hold, the court ruled.<br><br><br><a href="http://www.christianlouboutindiscounts.com/" title="Cheap Christian Louboutin"><strong>Cheap Christian Louboutin</strong></a><br><a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin Heels"><strong>Christian Louboutin Heels</strong></a><br><a href="http://www.christianlouboutindiscounts.com/" title="Louboutin Heels"><strong>Louboutin Heels</strong></a><br><a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin On Sale"><strong>Christian Louboutin On Sale</strong></a><br><a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin Sale"><strong>Christian Louboutin Sale</strong></a><br><a href="http://www.christianlouboutindiscounts.com/" title="Louboutin Sale"><strong>Louboutin Sale</strong></a><br><a href="http://www.christianlouboutindiscounts.com/christian-louboutin-shoes-c-6.html" title="Christian Louboutin Shoes"><strong>Christian Louboutin Shoes</strong></a><br><a href="http://www.christianlouboutindiscounts.com/christian-louboutin-shoes-c-6.html" title="Louboutin Shoes"><strong>Louboutin Shoes</strong></a><br><a href="http://www.christianlouboutindiscounts.com/christian-louboutin-sandals-c-15.html" title="Christian Louboutin Sandals"><strong>Christian Louboutin Sandals</strong></a><br><a href="http://www.christianlouboutindiscounts.com/christian-louboutin-boots-c-14.html" title="Christian Louboutin Boots"><strong>Christian Louboutin Boots</strong></a><br><a href="http://www.christianlouboutindiscounts.com/christian-louboutin-pumps-c-3.html" title="Christian Louboutin Pumps"><strong>Christian Louboutin Pumps</strong></a><br><a href="http://www.christianlouboutindiscounts.com/christian-louboutin-boots-c-14.html" title="Louboutin Boots"><strong>Louboutin Boots</strong></a><br><a href="http://www.christianlouboutindiscounts.com/" title="http://www.christianlouboutindiscounts.com/"><strong>http://www.christianlouboutindiscounts.com/</strong></a><br><br><br>The Pentagon said it was still studying the <a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin Outlet"><strong>Christian Louboutin Outlet</strong></a> ruling, but added it would comply with the court order. A spokesman, Colonel Dave Lapan, said the U.S. military was immediately taking &quot;steps to inform the field of this order.&quot;A Justice Department <a href="http://www.christianlouboutindiscounts.com/" title="Louboutin Outlet"><strong>Louboutin Outlet</strong></a> spokeswoman did not immediately respond to a request for comment.R. Clarke Cooper, executive director of the Log Cabin Republicans which filed the suit said the ruling &quot;removes all uncertainty - American service members are no longer under threat of discharge as the repeal implementation process goes forward.&quot;Since the ban became <a href="http://www.christianlouboutindiscounts.com/" title="Christian Louboutin Cheap"><strong>Christian Louboutin Cheap</strong></a> a formal policy in 1993, an estimated 13,000 people have been expelled from the armed forces for violating the rules.
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!
No group so far has claimed <a href="http://www.uggsbaileybuttonsale.com/" title="Cheap UGG Bailey Button"><strong>Cheap UGG Bailey Button</strong></a> responsibility for last Thursday's bombing, but suicide attacks are the trademark of the Islamic State of Iraq, an al-Qaida <a href="http://www.uggsbaileybuttonsale.com/" title="UGGS Bailey Button Sale"><strong>UGGS Bailey Button Sale</strong></a> front group believed made up mostly of Sunni <a href="http://www.uggsbaileybuttonsale.com/" title="UGG Bailey Button On Sale"><strong>UGG Bailey Button On Sale</strong></a> religious extremists. Such groups have frequently targeted Shiite civilians, in part because of <a href="http://www.uggsbaileybuttonsale.com/" title="UGG Women Boots"><strong>UGG Women Boots</strong></a> religious differences and because Shiite parties gained <a href="http://www.uggsbaileybuttonsale.com/" title="UGGS Bailey"><strong>UGGS Bailey</strong></a> power after the 2003 U.S.-led invasion toppled Saddam Hussein's Sunni-dominated regime. Since the end of Saddam's rule, Shiite politicians have encouraged huge turnouts at religious rituals, which were banned under the former regime, as a demonstration of Shiite power. <br><br><a href="http://www.uggsbaileybuttonsale.com/" title="UGG Bailey Button Boots"><strong>UGG Bailey Button Boots</strong></a><br><a href="http://www.uggsbaileybuttonsale.com/" title="UGG Bailey Button Sale"><strong>UGG Bailey Button Sale</strong></a><br><a href="http://www.uggsbaileybuttonsale.com/" title="Bailey Button UGGS Sale"><strong>Bailey Button UGGS Sale</strong></a><br><a href="http://www.uggsbaileybuttonsale.com/" title="UGGS Bailey Button"><strong>UGGS Bailey Button</strong></a><br><a href="http://www.uggsbaileybuttonsale.com/" title="UGGS Bailey Button Boots"><strong>UGGS Bailey Button Boots</strong></a><br><br>Also Monday, police said two <a href="http://www.uggsbaileybuttonsale.com/" title="UGG Boot Outlet"><strong>UGG Boot Outlet</strong></a> bombs in Baghdad killed an Iraqi Army intelligence officer and his driver and wounded eight bystanders in separate strikes that hit a <a href="http://www.uggsbaileybuttonsale.com/" title="UGG Boots Sale"><strong>UGG Boots Sale</strong></a> Shiite and a Sunni neighborhood. Hospital officials in <a href="http://www.uggsbaileybuttonsale.com/" title="Cheap UGGS"><strong>Cheap UGGS</strong></a> Baghdad confirmed the fatalities. A roadside bomb exploded near Tikrit as Salahuddin provincial Gov.
Hi there.&nbsp;&nbsp; Brilliant post.&nbsp;&nbsp; Very informative, the formulas you have provided have been very helpful, as without them I'd of just been blindly putting components together.&nbsp; Likely with disastrous results.<br /> <br /> I've got a couple of questions for you though.<br /> <br /> First the easy one.&nbsp; Could you explain the formula in step 5.&nbsp; What is &quot;U_L&quot;, &quot;L&quot;, &quot;delta i&quot; and &quot;delta t&quot;?&nbsp; Where do I find their values in regards to the components I'm going to use.&nbsp; 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.<br /> <br /> 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.&nbsp; Can I simulate the arduino by applying a 5v positive to where the arduino would go, with the negative to ground in the circuit?<br /> <br /> Again, many thanks for this guide, and thanks for any help you can give me.<br /> <br /> Regards,<br /> The Cageybee<br />
&quot;U_L&quot; (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. &quot;L&quot; is the inductance of your relays coil. &quot;delta I&quot; is the change of the current and &quot;delta t&quot; 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.<br />
Oopps!&nbsp; 'mybad.&nbsp; Need to read the whole of the post.&nbsp;&nbsp; Second question answer in step 7.<br /> <br /> Appologises!&nbsp; :-)<br /> &nbsp;The Cageybee<br />
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?
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
SPDT 5v amp realy $5.08 radioshack direct2U order
I guess it also depends on your definition of cheap.<br/><br/>This one is $15.00 US<br/><br/><a rel="nofollow" href="http://www.allelectronics.com/make-a-store/item/SSRLY-42/40-AMP-SOLID-STATE-RELAY/1.html">http://www.allelectronics.com/make-a-store/item/SSRLY-42/40-AMP-SOLID-STATE-RELAY/1.html</a><br/><br/>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. <br/><br/><a rel="nofollow" href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=1048664&keywords=solid%20state%20relay">http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=1048664&amp;keywords=solid%20state%20relay</a><br/><br/>Happy hunting.<br/><br/>Cheers<br/>
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.
Ok in here you can get one like mine for ~1&#8364; (= 1,2951$)<br/><br/>greetz Daniel<br/>

About This Instructable


180 favorites


More by homunkoloss: Connecting a 12V relay to Arduino How to make your GNOME Desktop even cooler
Add instructable to: