# Triggering a 12 v relay with an arduino

I am trying to trigger a 12 V relay with an arduino input. All I am doing in the Arduino sketch is to make pin 13 go high and low every 1 sec (1000 ms). The relay refuses to get triggered. Can someone please tell me what am I doing wrong? Struggling with this for way too long.

• Did you double check the transistor was good? And 14k resistor seems too weak for this. Try 1k or 2k. Commented Dec 26, 2014 at 15:40
• The 14kohm resistor shows just how important the math for this is. Commented Dec 26, 2014 at 15:51
• Are you sure your 12V source could get enough current for turning the relay on?
– Bip
Commented Dec 26, 2014 at 15:53
• possible duplicate of What determines how much current can flow through a 2N2222 A? Commented Dec 26, 2014 at 15:54
• It looks to me like you have your 12V + and - mixed up, and your diode would be backwards if you sorted that out too. I'm surprised you haven't blown something up. Commented Jan 4, 2015 at 17:09

Adding to what other people said in their answers. You must ensure that the current needed to power the coil of your relay doesn't exceed BC548's maximum current rating (with a suitable safety margin).

The maximum collector current for a BC548 is 100mA, so (to be really on the safe side, even when its temperature rises), I wouldn't want to have it switch a current above, say, 50mA. If your relay needs more than 50mA of current, you should choose a BJT with a greater maximum collector current rating.

To check your relay current absorption connect the relay directly across a power supply (12V) and measure the current it draws from it.

• I connected my relay directly to the 12 v supply. It worked nicely drawing 30mA current. I believe it does not need more than 30 mA. In that case BC 547 should still work.. right? The hfe for BC 547A is 110-200 which means that the Ib should be (0.03/150) = 0.000267 Amp. To generate that small a current, I guess I will have to put a 20K ohm resistor at the base... right? I dont have one right now with me but if these calculations look ok, I will go get one... Please do let me know. Commented Dec 30, 2014 at 11:00
• BTW: 0.03A/150=0.0002A=0.2mA. Besides that small computation error, that is the base current that drives the BJT at the edge of the linear region (assuming an hFE=150, but you should design for the worst case, i.e. hFE=110, according to the datasheet). What you need is to switch the BJT completely ON, i.e. to drive it in full saturation independently of any other condition. This means you have to choose a base current which is much greater than that value you have computed. Say ten times bigger: Ib=2mA. This leads you to Rb=(5V-0.7V)/2mA=2.15kOhm (a standard 2.2kOhm will do). Commented Dec 30, 2014 at 12:35
• I did the 2K ohm and I also measured the current passing through the relay. When the Arduino output is HIGH, the relay is passing 24mA current and when the Arduino output is LOW, the relay is passing 17mA current. I think as a result the RELAY is always ON ... it never switches off. I measured the potential diff between Arduino out and the Transistor base and at a HIGH, it is 11V and at a LOW it is 6V... Is my wiring wrong? Let me try posting a real picture of the wiring in my post. Any help will be much appreciated. Commented Dec 30, 2014 at 15:08
• Maybe I don't see it well, but it seems you didn't connect the Arduino ground to your breadboard. You should connect Arduino's GND terminal to the same ground of the external 12V power supply. Commented Dec 30, 2014 at 15:29
• Wait! I was put off track by your use of colored jumpers. You are using a red jumper to connect Arduino GND to the emitter of the BJT and an orange one to connect that terminal to the positive 12V rail, if the wiring from the 12V power supply are color-coded correctly. It seems that you got the 12V power supply rails swapped. Moreover also the diode is reversed: the cathode is the terminal with the white band. It is the other terminal (the anode) that must be connected toward the collector of the BJT. Commented Dec 30, 2014 at 15:38

I assume you're actually trying to drive it with an Arduino output- an input won't drive anything.

A lot of power 12V relays need around 100mA (or more) coil current. That means your base current should not be much less than about 5mA to guarantee the transistor is well saturated. If you have a 5V Arduino it might drive to 4.5V at higher current, the transistor base needs 0.7V so that's about 270uA (a lot worse if the micro is 3.3V), so it will only drive about a 5mA relay safely. From the transistor datasheet:

Reduce the 14K resistor to something more like (4.5V - 0.7V)/0.005 = 750$\Omega$ and you'll be able to drive a 100mA relay safely (assuming a 5V micro).

• Thanks for sending your response. I will try again and post back but in the past I have tried using a 1K ohm resistor but each time it burns the transistor. I can try again with all calculations and post back. Commented Dec 27, 2014 at 3:40
• @coderatlarge check you do not have the diode backwards and that the relay coil measures 120 ohms or more. Commented Dec 27, 2014 at 3:44
• I connected my relay directly to the 12 v supply. It worked nicely drawing 30mA current. I believe it does not need more than 30 mA. In that case BC 547 should still work.. right? The hfe for BC 547A is 110-200 which means that the Ib should be (0.03/150) = 0.000267 Amp. To generate that small a current, I guess I will have to put a 20K ohm resistor at the base... right? I dont have one right now with me but if these calculations look ok, I will go get one... Please do let me know. Commented Dec 30, 2014 at 11:05
• Relay coil measures 300 ohm. Also I have the diode correct. Still the 1K resistor did not work. Commented Dec 30, 2014 at 11:08
• Wiring was wrong... I got it working. Thanks so much Commented Dec 30, 2014 at 17:46

Most likely the transistor can't sink enough current to turn on the relay. Look up how much current the relay needs with 12 V applied. Divide that by the minimum guaranteed gain of the transistor. That tells you how much base current you need. If that is more than your digital output can source, then you need more amplification in there somewhere. If the digital output can source the minimum required base current, then size the base resistor accordingly.

Figure 700 mV B-E drop in the transistor. If the digital output drives to 5 V when high, then that leaves 4.3 V across the base resistor. (4.3 V)/(14 kΩ) = 300 µA. If the transistor gain is 50, for example, then that can only support 15 mA of relay current.

Most likely your digital output can source at least 5-10 mA. A few mA base current should be possible, which should be able to support the coil current of a modest relay.