Designing Relay Driver Using BJT for Raspberry Pi, Arduino or Others

by ingits in Circuits > Electronics

163 Views, 0 Favorites, 0 Comments

Designing Relay Driver Using BJT for Raspberry Pi, Arduino or Others

RelayDriverThumbnail.jpg

In this instructable, I will demonstrate a step-by-step approach to design a Relay Driver using BJT from scratch

Supplies

Relay (x1) - I had 12V DC single pole relay lying around

BJT (x1) - I used BC547 (npn)

Resistors (x1) - We will learn how to determine the value

Breadboard x1

Wires

Power Supply - I used 12V DC to drive relay and 3.3V DC to drive BJT

Understanding Schematic

Screenshot 2023-12-09 at 4.18.00 PM.png

I decided to use a NPN BJT so as to be able to perform low side switching. In this case, the input or the driving signal to the BJT will be fed from pin labelled as Vin. We would strive to drive the BJT in the saturation region which is achieved by driving the Base-Emitter region into a forward biased state. When forward biased, the Vbe will be 0.7V.


Under saturation state, all the charge carrier available in the BJT will be contributing in conducting the current through the Collector-Emitter path.


In the schematic, we will select a suitable base resistor which will drive the BJT into saturation region when a signal is applied to Vin. This will cause the BJT to work as a closed path between Collector and Emitter terminals with Vce equal to 0V (almost). Hence, the relay coil will find itself connected directly between supply voltage and ground causing it to turn on.

Voltage Current Equation

For the base-emitter section, the voltage equation can be written as

Vin - Ib x Rb = Vbe

For saturation region,

Vbe = 0.7 V

Hence,

Rb = (Vin-0.7)/Ib

Just at the border line of saturation region,

Ic = Hfe x Ib or Ib = Ic/Hfe

This implies,

Rb = (Vin-0.7) x Hfe / Ic

Derive Component Value

I grabbed the multimeter and set it up under the current mode. Then I put the multimeter in series with relay and connected the circuit to 12V DC supply. This gave me a reading of 66mA on the multimeter. This became the Ic for my circuit (since the relay will be connected in series to collector terminal). The Ic is less than the max collector current (100mA) which BC 547 can handle. Hence, I considered it safe to proceed with BC 547. You may like to look for alternates if required.

Also, I am going to drive my circuit using Raspberry Pi. This tells me that Vin would be 3.3V DC.

I also measured the gain (or Hfe) of the BJT by connecting it to the multimeter. I got the Hfe as 320.

Substituting these values in the Voltage Current Equation,

Rb = (3.3-0.7) x 320 / 66m = 12.6K Ohms

So, I took a 12K resistor and added it to the base circuit as per the schematic.

Testing and Validation

BJT Based Relay Driver - Design, Test and Implement

With the value of base resistor now known, I quickly created the circuit on a breadboard and tested it.

Voila! the relay turned ON as soon as the 3.3V DC was fed to Vin. I measured the current (base and collector both) to make sure that the BJT is operating in a safe zone. The Ic turned out to be 53mA so I changed the Rb to 10K to see if it improves the collector current further. The Ic went up to 55mA which was still less than 66mA which the relay was able to draw directly from the power supply.

However, there was no jiiter in the relay and the contacts were closing without any problem. I was happy with the outcome.

Conclusion

The relay driver worked as expected and the circuit performed without any problem. I am planning to put this circuit to drive the door lock which will react to HTTP request sent to raspberry pi. This will allow me to setup a shortcut on Siri and would allow a keyless entry into my secured area.

I would recommend to measure the Ic over next 15-20 mins to see if any thermal runaway is trying to increse the collector current. If it happens, add a small value resistor between relay and collector terminal to compensate for the increase in current. In my case, the relay will be turned on briefly and will then be turned off.

Do check out the detailed video on this topic and let me know your comments.


Happy Tinkering! :)

Full Video Link

Designing a Relay Driver with BJT

The link to my channel where I have shared detailed steps on creating this circuit

Additional Items

Screenshot 2023-12-12 at 11.59.47 AM.png

In my case, I am planning to use the relay to drive another inductive DC load. For this reason, I will attach another freewheeling diode to the relay output (driven) terminals (N.O. terminal in my case). Updated schematic will look like this.