Relay Driver Circuit

Relay are used for driving high current load or if you want to isolate your load from your circuit. For example you want to turn on a 220Vac light using a microcontroller. Your microcontroller is only operating at 5Vdc and your is a 220Vac lamp. The microcontroller can’t drive the 220Vac lamp directly so if you want to isolate the line between the microcontroller and the lamp you need to use a relay. The main disadvantage of using a relay is that you can’t control the brightness of the lamp. Anyway it is also impossible to control LED, and florescent lamp brightness  because of their certain characteristic. LED bulb usually has a built in voltage regulator so it is not advisable to control its brightness, while florescent lamp has minimum operating voltage and it also needs a high voltage to start.

Choosing a Relay




 

There are 5 parameters for choosing a relay:

  • Coil Voltage – the voltage needed to drive the relay actuator. It is the voltage available on your control, usually 12V, 24V, and sometimes it is also 220V but those are not intended for microcontrollers. Choose the voltage available on your system.
  • Coil Current – The current needed to drive the relay actuator. This will determine the driver transistor to be used.
  • Operating voltage – The maximum voltage that the relay switch can operate.
  • Operating Current – The maximum current that the relay switch can operate.
  • N/O or N/C – switch configuration; normally closed or normally open. For most cases N/O or normally open are used. Normally open means that the switch is normally open when the coil is not energized(the relay is turn off).

Choosing Relay driver

We usually use NPN BJT to drive the relay but in some cases a PNP BJT or even a MOSTFET is used. It all depends on your circuit configurations. In this example I will use the most common NPN BJT configuration.

transistor-relay-driver

Above is the basic relay driver circuit.

R1 is used to reduce that current that the circuit draws from the microcontroller. R1 value is computed as:

R1 = (Vdrive – 0.7)/Ib

Where:
Vdrive = Microcontroller supply voltage(usually 5V or 3.3V)
Ib = Transistor driver base current.

Now, recalling your basic BJT formula:

tran40

We can rewrite the formula for R1 as:

R1 = ((Vm – 0.7) * B)/(Ic)

Where:
B = Transistor Beta/Hfe
Ic = Relay coil current requirement
Vm = Microcontroller Supply Voltage

The solution above is the R1 maximum value. Anything higher that what is computed may not have sufficient current to drive the relay coil. The minimum value for R1 will be computed as:

R1 = (Vm -0.7)/Im

Where:
Vm = microcontroller supply voltage
Im = microcontroller maximum current sink per pin

Im is usually around 10-20mA depending on the microcontroller being used. Read the datasheet to be sure.

D1 is used to protect Q1 during turning off the relay due to the inductive properly of the coil. You can use any rectifier diode such as 1N4007 for this purpose.

R2 and LED is optional, it is only used to indicate that the relay is ON. R2 can be computed as:

R2 = (Vcc – Vled)/iled

Where:
Vcc – relay supply voltage. In this case 12V
Vled – voltage of LED(usually 1.7 – 3V)
iled – current requirement of LED(usually 1-10mA)

Transistor Driver



 

There are 2 main specifications to consider for selecting the transistor driver for the relay. First is the Ic(collector current), to be safe; choose the transistor with at least twice the collector current of the required relay coil current. This is to make the system more reliable. Second is the Vce(collector-emitter voltage. Vce should not be less than the supply voltage of the relay. Consider the voltage fluctuations on the supply voltage. Vce should be higher than those levels. If possible make Vce at least twice the supply voltage.

Below is the specifications of 2N2222, a common transistor used for relay driver. You can use it for relay with maximum voltage of 24V and 300mA.

139380-DI1