Interfacing Relay to Microcontroller
Written by Amol Shah, on Nov-2007
Views 29486    

Relays are devices which allow low power circuits to switch a relatively high Current/Voltage ON/OFF. For a relay to operate a suitable pull-in & holding current should be passed through its coil. Generally relay coils are designed to operate from a particular voltage often its 5V or 12V.

The function of relay driver circuit is to provide the necessary current (typically 25 to 70ma) to energize the relay coil.

Image
Figure 1

Figure 1 shows the basic relay driver circuit. As you can see an NPN transistor BC547 is being used to control the relay. The transistor is driven into saturation (turned ON)  when a LOGIC 1 is written on the PORT PIN thus turning ON the relay. The relay is turned OFF by writing LOGIC 0 on the port pin.

A diode (1N4007/1N4148) is connected across the relay coil, this is done so as to protect the transistor from damage due to the BACK EMF generated in the relay's inductive coil when the transistor is turned OFF.When the transistor is switched OFF the energy stored in the inductor is dissipated through the diode & the internal resistance of the relay coil.

As you can see we have used a pull up resistor at the base of the transistor. AT8951/52/55 has an internal pull up resistor of 10k so when the pin is pulled high the current flows through this resistor so the maximum output current is 5v/10K = 0.5ma, the DC current gain of BC547 is 100 so the maximum collector current we can get is 0.5ma x 100 = 50ma, but most of the relays require more than 70ma-130ma current depending on the relay that we have used, 0.5ma of base current is not suitable enough for turning ON the relay, so we have used an external pull up resistor. When the controller pin is high current flows through the controller pin i.e. 5v/10k=0.5ma as well as through the pull up resistor. We have used 4.7k pull up resistor so 5v/4.7k=1.1ma so maximum base current can be 0.5ma + 1.1ma=1.6ma i.e. collector current =1.6ma x 100 = 160ma which is enough to turn ON most of the relays.

 

NOTE: This relay driver circuit is to be used only with controllers for using this circuit with other digital IC's like LM 555 use a resistor should be used between that IC's output & the base of transistor.No need of  pull up resistor in that case. 

-Amol Shah

 



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!
Quote this article in website Favoured Print Send to friend Related articles Save this to del.icio.us

Users' Comments (10) RSS feed comment
Posted by srikanth, on Nov-2008,
1. hai
ur explanation is very good thank u for providing good information
 
» Report this comment to administrator
» Reply to this comment...

Posted by suresh, on Jan-2009,
2. help
sir, your explanation is so simple and clear. and i am doing project and in that there is a controller to power on/off electrical appliances. can i use this ? is there any ic that will operate about 4 to 8 devices with microcontroller?
 
» Report this comment to administrator
» Reply to this comment...
» See all 1 replie(s)

Posted by Administrator, on Jan-2009,
3. use ULN2803
you can use ULN2803 which has 8 NPN darlington transistors so can be used to turn ON/OFF 8 relays
 
» Report this comment to administrator
» Reply to this comment...
» See all 1 replie(s)

Posted by Elec, on Feb-2009,
4. Alternate drive
By putting the resistor in serie with the transistor base, there is no consumption when the relay is deactivated. It also prevents a short circuit case if the microcontroller pin is set to output high. 
It can also prevents relay activation while the processor is being reset. 
For small relays, direct microcontroller drive is possible using 2, 3 or 4 pins from the same port so that they can be set/reset together and share the load. The pins must not be programmed as open collector, as this would stress the micro's protection diodes. In this case, there is no need for external components.
 
» Report this comment to administrator
» Reply to this comment...

Posted by max, on Mar-2009,
5. turn off relay
When is the relay supposed to turn to be turned off.?
 
» Report this comment to administrator
» Reply to this comment...
» See all 1 replie(s)

Posted by jron, on Jul-2009,
6. help
what kind of relay can i use? it is possible to use 12v or 5v relay in the circuit?
 
» Report this comment to administrator
» Reply to this comment...

Posted by amol, on Jul-2009,
7. re:help
you can use any kind of relay, 5v, 12v even 24v relays can be used. but see to it that the current required to energize the relay coil is less than the max collector current of the transistor.
 
» Report this comment to administrator
» Reply to this comment...

Posted by Prasad, on Jul-2009,
8. AC relay
Hi, Thanks for the ckt. 
 
I need some suggestion. 
 
For a project I need to controll a solenoid switch using a relay (OFF and ON). 
 
What type of relay can be used (AC In -->Relay--> AC Out). The relay will be controlled by a 555 timer or a microcontroller. 
 
Thanks in advance, 
Prasad
 
» Report this comment to administrator
» Reply to this comment...

Posted by Prady, on Sep-2009,
9. Plz help
sir. i want to control solenoid switch from 8051, so plz provide me information with a schematic diagram.
 
» Report this comment to administrator
» Reply to this comment...

Posted by Harsh dodia, on Sep-2009,
10. Complement
Sir the way you explain stuff is awesome...I understood everything u said ! Really a spl thx to you... 
I have 2 que: 
(1) If i use uln2003a to turn on/off a 4, 5v relay using 8051, is it necessary to connect a diode with uln2003 to eliminate BACK EMF ???? 
(2) can i connect the same 5v supply of 8051 to energies 4 relays or is it necessary to use separate 5v supply for relays ???? 
 
 
Waiting for your reply!!!
 
» Report this comment to administrator
» Reply to this comment...
» See all 1 replie(s)

Add your comment



mXcomment 1.0.5 © 2007-2010 - visualclinic.fr
License Creative Commons - Some rights reserved
 
< Prev   Next >
Home arrow Tutorial arrow Interfacing Relay to Microcontroller