Welcome to www.agpgames.com ---- HANGZHOU KinCony ELECTRONICS CO.,LTD.
About Us Contact Us          Our Patents Our Articles        Forum      SiteMap    Chinese Version

Chapter 1. Overview Chapter 2. Emulation Guide Chapter 3. Build Your First Project Chapter 4. In System Programming
Chapter 5. USB Interface Installation Chapter 6. LED Display Application Chapter 9. FAQ Chapter 10. System Configuration and Service
 
Chapter 7. Basic Experiments
7.1. Experiment with LED 7.2. Experiment with Flowing LEDs 7.3. Experiment with Keys 7.4. Experiment with Beeper
7.5. Experiment with Relay 7.6. Experiment with LED Display 7.7. Experiment with Serial Port  
 
8.1. Experiment with Matrix Key 8.2. Experiment with Stepping Motor 8.3. Experiment with 1-Wire Digital Thermometer DS18B20
8.4. Experiment with 24C01 EEPROM 8.5. Experiment with 93C46 Serial EEPROM 8.6. Experiment with DS1302 Real-time Clock
8.7. Experiment with 8-bit Serial AD Converter ADC0832 8.8. Experiment with 1602 Character LCD Module 8.9. Experiment with 12864 Graphic LCD
8.10. Experiment with Infra-red Remote Controller 8.11. Experiment with Wireless Encoding Module Chapter 11. User Feedback

Chapter 7. Basic Experiments

7.5. Experiment with Relay

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



COPYRIGHT2003--2008 HANGZHOU KinCony ELECTRONICS CO.,LTD. All Rights Reserved

Add:Rm 11-3-702, Pujing Jiayuan, Gongshu District, Hangzhou, Zhejiang, China.
Tel:+86-0571-87615070,Fax:+86-0571-87615070 E-mail: hificat@163.com  ICQ:164806453  Webmaster:Hificat