Você está na página 1de 4

4/10/12

Interfacing Relay to Microcontroller | 8051 Tutorial | Tutorial


.
Hom e About us Contact us

HOME

PROJECTS

DNA SHOP

TUTORIAL

CODE LIBRARY

DOWNLOAD

EVENTS

CONTACT US

FOLLOW US

Rs13.00 YOU ARE HERE: TUTORIAL 8051 Tutorial Interfacing Relay to Microcontroller Search...

INTERFACING RELAY TO MICROCONTROLLER


Tutorial - 8051 Tutorial
Written by Amol Shah
Share
Download SocButtons

RANDOM PRODUCTS
LM741

Like

Share

LM741

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. Rs9.00

74LS20

LATEST VIDEO

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. Normally 1N4148 can be used as it is fast switching diode with a maximum forward current of 300ma. This diode is also called as free-wheeling diode. The LED is used to indicate that the RELAY has been turned ON. The resistor R1 defines the current flowing through the LED thereby defining the LEDs intensity. Resistor R2 is used as a Series Base Resistor to set the base current. When working with 8051 controllers I have noted that its not compulsory to use this resistor as the controller has internal 10k resistor which acts as a base resistor. Microcontrollers have internal pull up resistors hence when a port pin is HIGH the output current flows through this internal pull up resistor. 8051 microcontrollers have an internal pull up of 10K. Hence the maximum output current will be 5v/10k = 0.5ma. This current is not sufficient to drive the transistor into saturation and turn ON the relay. Hence an external pull up resistor R3 is used. Let us now calculate the value of R3. Normally a relay requires a pull in current of 70ma to be turned ON. So our BC547 transistor will require enough base current to make sure it remains saturated and provide the necessary collector current i.e. 70ma. The gain (hfe) of BC547 is 100 so we need to provide at least 70ma/100 = 0.7ma of base current. In practice you require roughly double the value of this current so we will calculate for 1.4ma of base current. Base Current(1.4ma) =o/p current of controller (0.5ma) + 5v/R3

Rs12.00

Rs13.00

RANDOM ARTICLES
BIT BANGING Serial Communication is one of the most widely used methods of communications is... Capacitor Characteristics Capacitor Characteristics There are a bewildering array of capacitor... Zener Diodes The Zener Diodes In the previous Signal Diode tutorial, we saw that a "reverse... Capacitor Introduction Rs7.00 Introduction to Capacitors Just like the Resistor, the Capacitor, sometimes...

From the above equation the value of R3 comes out to be 5.55K. Typically I use 4.7K resistor. Whenever 8051 microcontroller is turned ON initially the controller is in reset state and all the controller pins are HIGH which would result in TURNING ON the relay every time power is turned ON or if there is a power fluctuation. This may also damage the device connected to relay so as to avoid this problem another transistor Q2 has been added between the controller & the previous transistor. This transistor acts as an inverter. Figure 2 shows the upated Relay Driver Circuit. So now when a High is applied from the controller the TRANSISTOR Q2 turns ON so the base of transistor Q1 gets 0 so the transistor Q1 turns OFF so the relay turns OFF. And when a LOW is applied from the controller the TRANSISTOR Q2 turns OFF so the base of transistor Q1 gets high voltage through the resistor R2 so the transistor Q1 turns ON which turns ON the relay So basically Q2 & R2 acts as an inverter.

SEARCH PRODUCTS
Search

www.dnatechindia.com/Tutorial/8051-Tutorial/Interfacing-Relay-to-Microcontroller.html

Search

1/4

4/10/12

Interfacing Relay to Microcontroller | 8051 Tutorial | Tutorial


Search

USER LOGIN
Username

Password

If you want to connect more relays to microcontroller then you can use ULN 2003 for connecting seven relays or ULN 2803 for connecting eight relays. Figure 3 shows how to connect a relay to microcontroller using ULN 2003/ULN 2803. These ICs are high voltage, high current Darlington transistor arrays with open collector outputs and free-wheeling clamping diodes hence there is no need of a diode across the relay. Also there is no need of the series base resistor as the IC has an internal resistor of 2.7K .

Login Forgot your password? Forgot your username? No account yet? Register

< Prev COMMENTS # Salman 2011-11-07 20:00 What are the values for R2, R3 & R4 for figure 2! Thanks is advance!

Next >

+2 Reply | Reply with quote | Quote

# Amol Shah

2011-11-08 16:16

+2

Quoting Salman: What are the values for R2, R3 & R4 for figure 2! Thanks is advance!

Value for R2 will depend on the current required by the relay. You can use 4.7k(else 2.2k), same for R4. For R3 you can use 1k. Reply | Reply with quote | Quote

# Vanessa 2011-11-20 08:02 what formula did you use in computing the values of each resistors? thanks in advanc

+1 Reply | Reply with quote | Quote

# amol shah

2011-11-20 10:15

+2

Quoting Vanessa: what formula did you use in computing the values of each resistors? thanks in advanc

The resistor in series with the led is for controlling the intensity of LED. Iled= (Vcc-1.2)/R.1 Normally Vcc =12v and I use 4.7k for red led. The formulas for the base resistor have been provided in the above article.... Reply | Reply with quote | Quote

# Vanessa thanks!

2011-11-20 12:17

-1 Reply | Reply with quote | Quote

# Vanessa 2011-11-20 12:31 is the gain of the transistors you use here is the same for an npn 2n2222 transistor gain?

-1 Reply | Reply with quote | Quote

# amol shah 2011-11-20 13:30 0 you can use 2n2222 instead of BC547 i think the gain of 2n2222 is greater than BC547 so you can increase the value of BC547...but you can even continue with the above values Reply | Reply with quote | Quote

# rakshith 2011-11-08 23:13 0 R1 value depends on the type of LED normally u can use b/w 470ohm to 1K, higher the value of R1 lower the intensity of LED Reply | Reply with quote | Quote

# rakshith 2011-11-08 23:12 +1 R1 value depends on the type of LED normally u can use b/w 470ohm to 1K, higher the value of R1 lower the intensity of LED Reply | Reply with quote | Quote # palaniappan 2011-11-19 19:19 i need project based on interfacing relay to optocoupler +2 Reply | Reply with quote | Quote

# amol shah

2011-11-20 10:11

+1

Quoting palaniappan: i need project based on interfacing relay to optocoupler why do you require optocoupler to interface relay? The relay will give the required isolation. what project are you implementing?

www.dnatechindia.com/Tutorial/8051-Tutorial/Interfacing-Relay-to-Microcontroller.html

2/4

4/10/12

why do you require optocoupler to interface relay? The relay will give the required isolation. what project are you implementing? Reply | Reply with quote | Quote

Interfacing Relay to Microcontroller | 8051 Tutorial | Tutorial

# jacqueline 2011-12-28 02:00 hi I jsut want to thank you about ur article it has given me a lot of input

+1 Reply | Reply with quote | Quote

# gocha 2012-01-02 17:41 how to use no and nc in circuit?

+1 Reply | Reply with quote | Quote

# prashanth 2012-01-23 21:08 hi ur article is very good...........

0 Reply | Reply with quote | Quote

# Niket 2012-01-26 14:49 0 what if I want to control the microcontroller with a RF module or lets say a xbee,in case we want to control the whole operation wirelessly.....what is the procedure? Reply | Reply with quote | Quote

# tushar 2012-02-03 08:22 sir how to interface gsm module

0 Reply | Reply with quote | Quote

# Tabi 2012-02-13 17:05 Hats up for you man . it helped me a lot thanks once again.

0 Reply | Reply with quote | Quote

# faheem 2012-02-15 14:35 what value of r1 & r2.

0 Reply | Reply with quote | Quote

# omer 2012-02-24 00:24 flawless tutorial ... keep it up

0 Reply | Reply with quote | Quote

# sunkanmi 2012-03-07 18:30 please i want u to give me the practical step on how to design a circuit for interfacing.

0 Reply | Reply with quote | Quote

# hisham

2012-03-14 21:40

can you give the value of resistor R1 to interface with ULN2003A?

0 Reply | Reply with quote | Quote

# pria.s 2012-03-16 12:03 0 12v relay s not getting enough voltage from 8051 board to switch on the device.what could i do to rectify it?is this board problem or supply prob? Reply | Reply with quote | Quote

# David 2012-04-05 21:27 For those looking for a good resource for hooking up relays, check out: learningaboutelectronics.com/.../... It tells you how to connect spst, spdt, and dpdt relays, which will help with wiring a project such as this one.

Reply | Reply with quote | Quote

Refresh comments list RSS feed for comments to this post ADD COMMENT Name (required) E-mail (required, but will not display) Website

1000 sym bols le ft

Notify me of follow-up comments

Refresh

Send

www.dnatechindia.com/Tutorial/8051-Tutorial/Interfacing-Relay-to-Microcontroller.html

J C omments

3/4

4/10/12

Interfacing Relay to Microcontroller | 8051 Tutorial | Tutorial


J C omments

FEATURED PRODUCTS
MQ6 LPG Gas Sensor RFID READER MODULE GPS Module With Patch Antenna HP03S Pressure and Temperature Sensor

. .

Rs600.00 Rs540.00 You Save: 10.00%

Rs180.00

Rs1 700.00

Rs500.00

. PROJECTS .

. POPULAR .
Project List Synopsis and Abstract About Us DNA Shop Totorial Code Library Download

. CONTACT US .
Mr. Amol Shah DNA Technology Nashik, Maharashtra 422009 India Phone : 0253-3023939 Mobile : 09225145135 Email : contact@dnatechindia.com

TUTORIALS
8051 Tutorial Power Supply

CODE LIBRARY
. 8051 Assembly C Code Library

DOWNLOADS
. Datasheets Download

Copyright 2011 DNA TECH INDIA . All Rights Reserved. Web Design by Dream z Infotech

Hom e

About US

DNA Shop

Tutorial

Code Library

Contact US

www.dnatechindia.com/Tutorial/8051-Tutorial/Interfacing-Relay-to-Microcontroller.html

4/4

Você também pode gostar