Working Of Relay And Its Interfacing With 8051 Microcontroller
What is relay and why we need to use it: Relay is an electromagnetic switch operated by DC voltage to switch between the devices. Relay consist on a magnetic coil operated by DC voltage. When we apply voltage to the coil. It becomes magnetic and pulls one connection to itself that cause of switch.
Relays specifications depends on input voltages and load current. Input voltages are DC 6V/12V and load current can be 10A/ 20A or 30A. depends upon the requirement how much load you want to operate via relay.
Simple relay have 5 pins two pins are used to operate the relay. Other three are named common C, normally connected NC and normally open NO.
Let’s discuss the function of C, NC and NO.
Common Pin: Common pin is connected to the common wire that used to switch between two other wires.
Normally Connected NC: when relay is turned off then the common pin is connected to NC pin. Means current pass from Common to Normally Connected Pin.
Normally Open NO: when relay is turned off then it is not connected to common pin that’s why it called normally open. When we apply voltage to the relay coil then Common pin disconnect from NC and connected to the NO pin.
Mostly relay is used to control high voltage using the controller’s low voltages.
Interface of relay with microcontroller:
As relays have operating voltages of 6V/12V but microcontroller’s pin output voltage is 5V so we can’t operate relay directly with the microcontroller’s pin voltage. So we need to operate relay via transistor’s switch method.
Suppose we want to operate a relay using microcontroller with the use of button. When we press button microcontroller will operate the relay.
Relay is connected to the microcontroller’s pin P3.0 (Port 3 and pin 0) and button is connected to P1.0 Commented Code of Microcontroller see in the picture below.
This program is written in C language.
This article was prepared for you by Hafiz Abdul Haseeb Tariq from FAST-National University of Computer and Emerging Sciences-Pakistan. He’s an Electronics & Embedded system engineer and has practical experience in circuit designing, networking, assembling, PCB making, 8051 & Arduino programming.
You can check out his previous article in the below link: