Arduino Vs 12vdc relay

I am trying to drive a 12vdc relay via one of the Arduino outputs.

I have the following circuit which works, but don't want to burn out the transistor..

the transistor is a standard 2n3904 npn. the circuit I took it from had 2 100k resistors in parallel for about 50k ohm total value connecting the trigger output to the base pin of the transistor... but that was just driving an LED from a 5v output. When hooked to the relay it barely drove it..

I reduced the resistor to 20k by putting two 10k resistors in series. It drives the relay fully. What is the best way to calculate what size resistor to use for the base pin?

You should use a 1K resistor between Ard. output and the transistor base.

Rough calculations:

  • Around .7V Base-emitter will saturate the transistor so that it is fully on
  • OK, now you need to pick a base current for the transistor
  • transistors have a gain called Hfe. Look in the datasheet, it's about 100 for a 2N3904. So you need 1milliamp through the BE junction of a 2N3904 to for every 100 ma through the CE
  • let's go for 5ma through the base-emitter, so you will get 500 ma thorough C-E

  • now let's figure out the resistor. We'll find the resistance value with ohms law.

  • 5V comes out of Arduino

  • 4.3V gets dropped by the resistor

  • voltage across resistor is 4.3V

  • R= V/I

  • R= 4.3V / .005 ma

  • R= 860 ohms

  • 680 ohms or 1K will work fine

After while you won't need to calculate this, it will just be "ok, use a 1K"...

( BTW If you use a 20K, as above, the current through the base will be I=V/R = 4.3/20,000 = .215 milliamps, which is tiny. Multiply this by 100and you have about 22 millimaps going through the CE junction of the transistor to turn the relay on. This is probably why your relay is "barely on")

My relay shows 30ma @12v nominal coil current.. I have my power supply at 13.7 so this is why it works... I will adjust and re-test later.



rule of thumb is to slap a 1K or 470R on there and drive the transistor into saturation, so that it is "wide open" and dissipates as little heat as possible.