This is the third part of my tutorial series on relays. In the last two tutorials we learnt about what are relays and how they work. In this part we will cover their interface with microcontrollers.
The output port pins of microcontrollers can can only source few Milli amperes of current, so they cannot be directly used to energize relays. To solve this and interface a relay with any microcontroller or other logic chips we need a transistor.
A transistor is a three terminal electronic component. Two common transistors are shown in the image below. One has plastic casing and other has a metallic casing.
There are two types of transistors a NPN one and a PNP one. We wont go on much detail about transistors. For interfacing relays, a NPN transistor is generally preferred. The image below show the schematic symbol for a NPN transistor.
A very small current flowing from Base to Emitter causes a large current to flow from Collector to Emitter. So we connect output from our microcontroller pin to the Base of transistor. The complete circuit diagram is shown below.
Schematic for Relay Interface
Here you can see that output from microcontroller enter transistor via resistor R1 (4K7). This resistor limit the current and only very small current flows from the base to the emitter. When microcontrollers output port is in low state (0) no current flows to the base and the transistor is in off state. When microcontroller makes the output line high (binary 1), the transistor is switched on. Current flows from the 12v input to the relay and then to the ground via the transistors collector pin. This current switches on the relay which in turn switches on the AC load (the bulb)
The diode D1 (1N4007) is used as a Flyback diode. Whenever an inductive load (the the coils of relay) is switched off, a large voltage is generated across its terminal. This voltage can damage the transistor. To protect the transistor we put a diode in such a way that it short circuits this voltage.
We cordially thanks the following peoples who shared this page on various social networks and insprided us to develop more quality contents!
William, Diy Guy, ANANDAN KR, Rahul,