Smarthome Remote Control System Producer

KinCony Electronic —- makes our life more beautiful quality more excellent and life more intelligent

7.5. Experiment with Relay

Posted by admin July - 27 - 2010 - Tuesday

In modern controlling system, electronic circuit controlling electrical circuit is very common. Relay plays two roles in these systems. 1) it enables the electronic circuit to control the device or component (e.g., motor, electromagnet, lamp, etc.) electrical circuit. 2) it isolates the electronic circuit from the electrical circuit, for the sake of safety in both system and human being. Relay is therefore a bridge between electronic circuit and electrical circuit.

This experiment shows how to control the relay to open and close.

The Fundamentals of Relay

Relay is a electronic controlling device, which has the controlling system (so called input circuit), and controlled system (so called output circuit). Mostly working in automatic controlling circuit, it use low current to control high current. It functions as an adjustment, safety protection, transferring circuit, etc.

In most cases, a relay is an electromagnet. It consists of a coil of wire surrounding a soft iron core, an iron yoke. When an electric current is passed through the coil, the resulting magnetic field attracts the armature, and the consequent movement of the movable contact or contacts either makes or breaks a connection with a fixed contact. If the set of contacts was closed when the relay was de-energised, then the movement opens the contacts and breaks the connection, and vice versa if the contacts were open.

There are many types of relay, latching relay, polarized relay, reed relay, solid-state relay, etc. The relay used in the development board looks like the below picture.

Relay is also an inductance device. MCU I/O port should not be used to control relay directly. Normally, a PNP transistor is used to open and close the relay.

Circuit Design

Software Design

01 #include <reg51.h>

02

03 sbit RELAY = P1^3;

04

05 void Delay()

06 {

07 unsigned char i,j;

08 for(i=0;i<255;i++)

09 for(j=0;j<255;j++);

10 }

11

12 void main()

13 {

14 while(1)

15 {

16 RELAY = 0;

17 Delay();

18 RELAY = 1;

19 Delay();

20 }

21 }

Program Notes

Line 1: include the 8051 register definition header file

Line 3: sbit define relay to P1.3

Line 5-10: delay function, the delay time depends on MCU clock

Line 7: define2 unsigned char variable i, j

Line 8-9: loop by i and j self-increment

Line 12-21: main function

Line 14: the main loop, while loop

Line 16: open the relay

Line 17: invoke the delay function

Line 18: close the relay

Line 19: invoke the delay function

Leave a Reply

Universal Programmer | Gang Programmer | Device Programmer | ISP Programmer | Eeprom Programmer | IC Programmer
Copyright © 2003-2012 Programmerkit.com All Rights Reserved.
Add:Rm 852,4F,Zhejiang Shidai Electronics Market,Dengyun Rd 428, Hangzhou, Zhejiang, China. P.C.:310011