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.
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.
01 #include <reg51.h>
03 sbit RELAY = P1^3;
05 void Delay()
07 unsigned char i,j;
12 void main()
16 RELAY = 0;
18 RELAY = 1;
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