Sunteți pe pagina 1din 10

WHAT IS A RELAY?

A relay is an electromechanical switch, which perform ON and OFF operations without any human interaction. Relays are devices which allow low power circuits to switch a relatively high Current/Voltage ON/OFF. Relays allow us to control the high power circuits or instruments using low power circuits and voltage levels such as output of microcontrollers. A relay consists of a coil which is driven by low power circuits such as microcontrollers in order to control high power ac circuits through output switches. General representation of double contact relay is shown in fig 1.1

Figure 1.1 Representation of Relay

Generally, the relay consists a inductor coil, a spring (not shown in the figure), Swing terminal, and two high power contacts named as normally closed (NC) and normally opened (NO). Relay uses an Electromagnet to move swing terminal between two contacts (NO and NC). When there is no power applied to the inductor coil (Relay is OFF), the spring holds the swing terminal is attached to NC contact. to the inductor coil, the current flowing through the coil generates a magnetic field which is helpful to move the swing terminal and attached it to the normally open (NO) contact. Again when power is OFF, the spring restores the swing terminal position to NC. 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.

Advantage of relay:
A relay takes small power to turn ON, but it can control high power devices to switch ON and OFF. Consider an example; a relay is used t control the ceiling FAN at our home. The ceiling FAN may runs at 230V AC and draws a current maximum of 4A. Therefore the power required is 4X230 = 920 watts. Off course we can control AC, lights, etc., depend up on the relay ratings. Relays can be used to control DC motors in ROBOTICs.

Types of Relays:
a. SPST (Single Pole Single Throw)

b.

SPDT (Single Pole Double Throw)

c.

DPST (Double Pole Single Throw)

d.

DPDT (Double Pole Double Throw)

Interfacing

There are many ways to interface a relay to 8051 microcontroller. But simple and easy way for beginners is by using ULN2003/ULN2803. In this tutorial, a 5volts operated relay is taken for the demonstration. But the circuits shown can be useful to 12Volts operated relays also.

WHAT HAPPENS WHEN A RELAY IS DIRECTLY INTERFACED TO 8051 MICRO CONTROLLER?


Generally, a relay takes 70mA (some relays may works with 50mA) current to excite the inductor coil. But the current sinking capability (IoL) of each port pin of 89S52/89C52/89C51 has 20mA. So whenever 70mA current flow into the port pin may cause damage to that particular port pin. So to avoid this problem we need a large current sinker.

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

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

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.

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.

WHAT IS THE NEED OF ULN2803/ULN2003?


As we discuss above we need a large current sinker circuit between the relay and 8051 microcontroller. A transistor which has current sinking capability greater that 70mA is enough to act as a relay driver between the microcontrollers and relay. But the biasing circuit required for the transistor is a bit clumsy. In some cases like robotic car, the number of relays required will increase. Therefore the number of transistors and its biasing components will increase, PCB size increases, debugging is a bit headache.

Figure 1.2 interfacing Relay with 8051 microcontroller using ULN2003

So the simple way to drive the relay with 8051 microcontroller is by using ULN2003/ULN2803. A ULN driver has 500mA current sinking capability for each output pin. When input pin of ULN driver is at logic high then the corresponding output pin is connected to ground via 500mA fuse. Internally each fuse is designed by using Darlington transistor pair. So interfacing the 8051 microcontroller to relay via ULN driver will not damage the microcontroller port pin. The interfacing circuit is shown in figure1.2.

USING ULN
ANOTHER OPTION FOR DRIVING RELAYS WOULD BE TO USE A HIGH-VOLTAGE, HIGHCURRENT, DARLINGTON ARRAY DRIVER IC SUCH AS THE ULN2803. THE ULN2803 CAN DIRECTLY INTERFACE TO THE DATA OUTPUTS OF THE 8051 PINS, AND PROVIDES MUCH HIGHER DRIVE-CURRENT. THE ULN2803 ALSO HAS INTERNAL DIODE PROTECTION THAT ELIMINATES THE NEED FOR THE FLY-BACK. YOU CAN CONNECT 8 RELAY USING THIS IC. SO I THINK ULN IS BETTER CHOICE IF YOU HAVE MORE THAN 3 RELAY. ( SIMPLE DESIGN OF CIRCUIT & PCB AS WELL ! )

WHAT IS THE NEED OF FLY WHEEL DIODE?


When power is applied to the relay inductor coil the current flowing through it causes magnetic field energy stored in it. This magnetic field is stored through the center of the coil and also outside of the coil.

B = LI2/2. When the current flowing through inductor is off (i.e, the current changes from max to zero) causes changes in the stored magnetic field which in turn produce electric field that opposes the change in the current. V = Ldi/dt. If the current change is fast, the derivative value will be very high. The voltage produced due to the electric field across the coil to opposite to the actual current direction (i.e., negative potential) and may reach hundreds of volts if the change in current is very fast. This large

voltage may damage the electronic parts.

Figure 1.3 Inductor coil connected across the collector terminal As shown in figure 1.3 the inductor coil is connected at the collector terminal of the transistor. When logic high is applied, the transistor is in ON state, so the current flows along the inductor and transistor. When a logic LOW is applied, the transistor enters into OFF state (OPEN circuit), which in turn stop the current flow. Inductor doesnt allow sudden changes in the current therefore large negative voltage is produce across inductor coil and causes electrons to cross the air gap as shown in figure. Therefore an electric spark/arc is produced across the open terminals of the transistor and it may damage the transistor as shown in figure 1.4

Figure 1.4 Spark Generated when inductor coil current is suddenly off

To avoid such problem, place a diode across the inductor coil as shown in below figure. When a power of the coil is OFF, the electric field (produced from the stored magnetic field) finds a path to flow electrons. Therefore the stored energy dissipates in the diode. When the relay coil power is ON, then the diode is not in conducting state. Whenever the power is OFF, the voltage appears across coil forward bias the diode and the current find a path to flow as shown in figure 1.5.

Figure 1.5 Flywheel diode across the inductor coil protects the transistor

WHERE DO WE SEE THE ELECTRIC SPARK IN DAILY LIFE?


You can see the electric spark by triggering the gas lighter or rubbing the positive terminal of the battery with its negative terminal by using a wire. You can see big electric arc in movie theaters at film projector room. You can see when a fan/light switch is on/off.

In A, NPN transistor (say a BC337 or BC338) is being used to control a relay with a 5 V coil. Series base resistor R1 is used to set the base current for Q1, so that the transistor is driven into saturation (fully turned on) when the relay is to be energized. That way, the transistor will have minimal voltage drop, and hence dissipate very little power as well as delivering most of the 5V to the relay coil. How do work out the value of R1?. Let us say RLY1 needs 50mA of coil current to pull in and hold reliably, and has a resistance of 24 Ohms so it draws this current from 5V. Our BC337/338 transistor will need enough base current to make sure it remains saturated at this collector current level. To work this out, we simply make sure that the base current is greater than this collector current divided by the transistors minimum DC current gain hFE. So as the BC337/338 has a minimum hFE of 100 (at 100mA), we'll need to provide it with at least 50mA/100 = 0.5mA of base current.

In practice, you give it roughly double this value, say 1mA of base current, just to make sure it does saturate. So if your resistance will be TTL Logic High Voltage (Min) /1ma ( 1K approx)

S-ar putea să vă placă și