Connecting relay through transistor question.

I did a search but could find what im looking for.
Basicaly i have to power a 3 volt relay for very short periods of time (im supplying 5 volts to it at the moment as its working fine for the last year or so).
I know that i have to use a transistor and a diod.
I have bought a 2N7000 transistors and BC639 also have TIP142 and some 1N4001s diods.
I have searched the net for a diagram but couldnt find one.
Is there a chance some one could kindly help.
The relay is controlled by PicAxe8M.
I also know that most likely i'll have to stick in a resistor to the base of the transistor but not sure what value resistor to use.
And also what transistor would sout better for the job?
Thank you very much in advance.
 

hippy

Ex-Staff (retired)
Have a look at "PICAXE Manual 3" at "Standard Circuits 3 - The Relay Interfacing Circuit"
 

BeanieBots

Moderator
The principle is the same for any transistor so that circuit will be OK.
The 1N4001 is not ideal for back emf suppression but will fine in all but the most demanding of circuits.

It probably would be a good idea to fit a resistor in series with a 3v relay when running it from 5v. To calculate the required value we would need to know the resistance of the coil. (and which transistor you decide to use for the coil)
 
The principle is the same for any transistor so that circuit will be OK.
The 1N4001 is not ideal for back emf suppression but will fine in all but the most demanding of circuits.

It probably would be a good idea to fit a resistor in series with a 3v relay when running it from 5v. To calculate the required value we would need to know the resistance of the coil. (and which transistor you decide to use for the coil)
Cheers mate.
Well im off to assemble the circuit.
Thanks for all the advice.
I really appriciated.
Cheers.
 

boriz

Senior Member
Some basic rules for driving common emitter BJT switchers:

1. Establish the maximum collector current. (Ic max)
2. Establish the transistor gain (hfe) and suitability.
3. Calculate the base resistor and power dissipation.

---
Ic max is the most crucial figure and everything else is worked out from that. It’s the maximum current that will ever flow through the collector circuit when it is switched fully on. This is usually calculated from the resistance of the load and the voltage across the load using ohms law, I=V/R. In this case, Ic max = 5v / Rcoil. Where Rcoil is the DC resistance of the coil as measured using a multimeter.

Usually, the lower the voltage rating of the relay coil, the lower its resistance and the more current it draws. I can only guess at the resistance of your coil, so let’s say it’s 50 ohms. So Ic max = 5/50 = 0.1A or 100mA.

100mA is actually quite a lot for a signal transistor and you should be looking for a power transistor. The transistor data will show the maximum collector current for a particular transistor.

ALWAYS OVER ESTIMATE. If you need 100mA, get a 500mA or 1A transistor. If you need 500mA, get a 1.5A or 2A transistor etc.

In this case, for 100mA, a BC639 should be fine. I have loads of them and it’s probably what I’d use if I were choosing a BJT.

---

The gain (hfe) is quoted on the data sheet. It’s usually quoted with a collector current. The reason a collector current is given alongside the gain is that the gain varies as collector current varies. The higher the current, the lower the gain, for a particular transistor. This is one of the reasons why you should over estimate the Ic max. Another reason is that the quoted hfe is only an estimate and can vary quite a lot from device to device, even on the same production run.

The BC639 has a minimum gain of about 40 at 150mA. It’s gain at 100mA should be a little more but let’s stick with hfe=40 for now.

Suitability is primarily about maximum collector voltage (before breakdown), power dissipation and frequency. For low frequency, low voltage, low power hobby applications, almost any BJT will do. But always check the data anyway. More on power dissipation below.

---

The base current (Ib) flows through the base resistor, through the transistors base and emitter and then to ground. It must be large enough to fully turn on (saturate) the transistor when it’s driving Ic max. The gain is the relationship between the base current and the collector current, or to put it another way, the collector current (Ic) is equal to the base current (Ib) multiplied by the gain (hfe). So since you know the maximum collector current (100mA) and you know the gain (40) you can establish the minimum required base current to turn the transistor fully on thus: Ib min = Ic max / hfe, or in this case, Ib min = 0.1/40. So Ib min is 0.0025 or 2.5mA.

So with this transistor, to drive a load of 100mA, you need a base current of AT LEAST 2.5mA. The Picaxe outputs 5v and the base-emitter junction, just like a diode, requires about 0.7v to be forward biased. So the voltage across your base resistor is 5-0.7 = 4.3v.

Now you have the voltage across the base resistor (4.3v), and you have the current required to flow through it (2.5mA). Ohms law gives you the value of the resistor thus: R=V/I. In this case, Rb = 4.3/0.0025. So Rb is 1720 ohms, or 1.72K. Remember though, that this resistor has been calculated to provide the minimum required base current, and you’ll be unable to get hold of that exact value anyway, so to provide a little more than the bare minimum base current, use the next smallest resistor you can find. On the E12 series, that’s 1.5K.

Personally, I like to assume my transistors are not quite to spec and would prefer to provide even more base current, just in case its gain is actually lower than specified. So I’d go one step down again on the E12 series, which is 1.2k.

The power dissipation is essentially the heat generated in the transistor quoted in Watts. Often this is negligible, but sometimes a heatsink may be required, or even a redesign with a bigger transistor. The power dissipated is a function of the voltage dropped across the transistor junctions and the current through them. It’s ohms law again.

Consult the datasheet for the saturation voltage (Vce sat). This is the voltage across the collector-emitter junction when it’s turned fully on. This is usually a very small value, less than half a volt, but again can vary from device to device, even on the same production run. The Vce sat for a BC639 is 0.5v maximum. Usually you will find that it’s actually lower, but you should use the maximum specified value to be sure.

So when the transistor is fully on, there is 100mA flowing through the 0.5v collector-emitter drop. Watts (P) = Volts (Vce) * Amps (Ic), so that’s P=0.5*0.1, so P=0.05 watts or 50mW. There is also a small contribution made by the base current. If using a 1.2k base resistor, the base current is 3.6mA. Through the 0.7v base-emitter drop, that’s about 2.5mW. So the transistor, when fully on, should generate about 52.5mW of heat.

That’s not much and should be fine without a heatsink. The calculations for exactly when a heat sink is required and how big it should be are a little complicated, but what I usually do is estimate then suck it and see. IE: Prototype the circuit, turn the transistor on and put my finger on the transistor. The rule of thumb is, if you can keep your finger held on the transistor indefinitely, then it’s ok. If you can’t, then heatsinking is required.

---

To recap.

Maximum base resistor value (Rb) = Base resistor voltage (Rv) / Minimum base current (Ib)
Minimum base current (Ib) = Maximum collector current (Ic) / hfe
Power dissipated (P) = Saturation voltage (Vce sat) * Collector current (Ic) + 0.7 * Base current (Ib)

And always overestimate!

And always use a reversed diode across the load if it’s inductive (IE: Coils, Motors etc).

---

More info on BJTs : http://www.allaboutcircuits.com/vol_3/chpt_4/1.html

EDIT: Remember. This example is for an Ic max of 100mA. You will need to do your own calculations based upon your load.
 
Last edited:
Some basic rules for driving common emitter BJT switchers:

1. Establish the maximum collector current. (Ic max)
2. Establish the transistor gain (hfe) and suitability.
3. Calculate the base resistor and power dissipation.

---
Ic max is the most crucial figure and everything else is worked out from that. It’s the maximum current that will ever flow through the collector circuit when it is switched fully on. This is usually calculated from the resistance of the load and the voltage across the load using ohms law, I=V/R. In this case, Ic max = 5v / Rcoil. Where Rcoil is the DC resistance of the coil as measured using a multimeter.

Usually, the lower the voltage rating of the relay coil, the lower its resistance and the more current it draws. I can only guess at the resistance of your coil, so let’s say it’s 50 ohms. So Ic max = 5/50 = 0.1A or 100mA.

100mA is actually quite a lot for a signal transistor and you should be looking for a power transistor. The transistor data will show the maximum collector current for a particular transistor.

ALWAYS OVER ESTIMATE. If you need 100mA, get a 500mA or 1A transistor. If you need 500mA, get a 1.5A or 2A transistor etc.

In this case, for 100mA, a BC639 should be fine. I have loads of them and it’s probably what I’d use if I were choosing a BJT.

---

The gain (hfe) is quoted on the data sheet. It’s usually quoted with a collector current. The reason a collector current is given alongside the gain is that the gain varies as collector current varies. The higher the current, the lower the gain, for a particular transistor. This is one of the reasons why you should over estimate the Ic max. Another reason is that the quoted hfe is only an estimate and can vary quite a lot from device to device, even on the same production run.

The BC639 has a minimum gain of about 40 at 150mA. It’s gain at 100mA should be a little more but let’s stick with hfe=40 for now.

Suitability is primarily about maximum collector voltage (before breakdown), power dissipation and frequency. For low frequency, low voltage, low power hobby applications, almost any BJT will do. But always check the data anyway. More on power dissipation below.

---

The base current (Ib) flows through the base resistor, through the transistors base and emitter and then to ground. It must be large enough to fully turn on (saturate) the transistor when it’s driving Ic max. The gain is the relationship between the base current and the collector current, or to put it another way, the collector current (Ic) is equal to the base current (Ib) multiplied by the gain (hfe). So since you know the maximum collector current (100mA) and you know the gain (40) you can establish the minimum required base current to turn the transistor fully on thus: Ib min = Ic max / hfe, or in this case, Ib min = 0.1/40. So Ib min is 0.0025 or 2.5mA.

So with this transistor, to drive a load of 100mA, you need a base current of AT LEAST 2.5mA. The Picaxe outputs 5v and the base-emitter junction, just like a diode, requires about 0.7v to be forward biased. So the voltage across your base resistor is 5-0.7 = 4.3v.

Now you have the voltage across the base resistor (4.3v), and you have the current required to flow through it (2.5mA). Ohms law gives you the value of the resistor thus: R=V/I. In this case, Rb = 4.3/0.0025. So Rb is 1720 ohms, or 1.72K. Remember though, that this resistor has been calculated to provide the minimum required base current, and you’ll be unable to get hold of that exact value anyway, so to provide a little more than the bare minimum base current, use the next smallest resistor you can find. On the E12 series, that’s 1.5K.

Personally, I like to assume my transistors are not quite to spec and would prefer to provide even more base current, just in case its gain is actually lower than specified. So I’d go one step down again on the E12 series, which is 1.2k.

The power dissipation is essentially the heat generated in the transistor quoted in Watts. Often this is negligible, but sometimes a heatsink may be required, or even a redesign with a bigger transistor. The power dissipated is a function of the voltage dropped across the transistor junctions and the current through them. It’s ohms law again.

Consult the datasheet for the saturation voltage (Vce sat). This is the voltage across the collector-emitter junction when it’s turned fully on. This is usually a very small value, less than half a volt, but again can vary from device to device, even on the same production run. The Vce sat for a BC639 is 0.5v maximum. Usually you will find that it’s actually lower, but you should use the maximum specified value to be sure.

So when the transistor is fully on, there is 100mA flowing through the 0.5v collector-emitter drop. Watts (P) = Volts (Vce) * Amps (Ic), so that’s P=0.5*0.1, so P=0.05 watts or 50mW. There is also a small contribution made by the base current. If using a 1.2k base resistor, the base current is 3.6mA. Through the 0.7v base-emitter drop, that’s about 2.5mW. So the transistor, when fully on, should generate about 52.5mW of heat.

That’s not much and should be fine without a heatsink. The calculations for exactly when a heat sink is required and how big it should be are a little complicated, but what I usually do is estimate then suck it and see. IE: Prototype the circuit, turn the transistor on and put my finger on the transistor. The rule of thumb is, if you can keep your finger held on the transistor indefinitely, then it’s ok. If you can’t, then heatsinking is required.

---

To recap.

Maximum base resistor value (Rb) = Base resistor voltage (Rv) / Minimum base current (Ib)
Minimum base current (Ib) = Maximum collector current (Ic) / hfe
Power dissipated (P) = Saturation voltage (Vce sat) * Collector current (Ic) + 0.7 * Base current (Ib)

And always overestimate!

And always use a reversed diode across the load if it’s inductive (IE: Coils, Motors etc).

---

More info on BJTs : http://www.allaboutcircuits.com/vol_3/chpt_4/1.html

EDIT: Remember. This example is for an Ic max of 100mA. You will need to do your own calculations based upon your load.
Thank you very much BORIZ. At the moment i dropped the base resistor altogether and everything is working perfect. I'll leave the assembly running for a week or so with this set up to test it (relay on/off every 100ms).
Originaly i used 10k resistor for the base as per manual and the curent to the base was way too little so the realy was hardly energising. Once the resistor for the base was dropped working fine.
I'll see how the testing goes and if required will fit a 1.2k resistor.
Thanks very much for the explanation. It realy did help.
thank you.

PICAXE rocked. I built a "BOX" for my race bike which lets me Up Shift on acceleration without decelerating or pulling in the clutch.
You can buy this from different manufacturers but they cost in a region of 200-400 euro. So to built one myself for 20 quid was well worth it.
Thanks again. Love this forum, if only i had more time on my hands i'd do more projects like that.
Not sure if anyone is interested but here is a picture of my race bike on the track this season:
 

MPep

Senior Member
Hey Boriz,

You should write this up as a tutorial. Not sure where to stick them though.
Well written.

MPep
 

boriz

Senior Member
“At the moment i dropped the base resistor altogether and everything is working perfect”

This is a very bad idea. With a grounded emitter, the base will never go above 0.7v. So the Picaxe is trying to put 5v on its output pin, but it’s ‘pinned’ to 0.7v. As far as the Picaxe is concerned, it’s effectively a short to ground. This is considered a fault condition and is likely to eventually break the Picaxe. Were it not for the built-in fault current limiting, it would probably already be broken.

The internal protection circuitry is working hard, limiting the output current to its maximum, about 25mA, which will indeed turn your transistor on, but it’s about 10 times more base current than it needs. The remainder of the 5v is being dissipated inside the Picaxe. That’s 0.025*4.3 = 107.5mW.

Never draw more than 20mA from any Picaxe pin. And always provide current limiting for a BJTs base. If you want a demonstration of why, try connecting the base directly to 5v. (Wear goggles)
 
Top