Don't Miss


Working Of Relay And Its Interfacing With 8051 Microcontroller

By on March 23, 2020
microcontroller relay circuit

 

 

 

 

 

 

 

 

 

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.

relay for microcontroller

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.

relay schematic

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.

static animation of relay

You may click on this link to see the animation

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.

microcontroller 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.

microcontroller c language for relay control

This program is written in C language.

hafiz Abdul Haseeb Tariq

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:

http://www.electronicsrepairfaq.com/working-of-16×2-lcd-and-its-interfacing-with-8051-microcontroller

 

Likes(43)Dislikes(2)

5 Comments

  1. Parasuraman S

    March 23, 2020 at 12:00 pm

    Good information giving insight into the Relay and controllers! Many thanks for sharing!

    Likes(1)Dislikes(0)
  2. Albert van Bemmelen

    March 23, 2020 at 1:24 pm

    Very nicely detailed article explaining using relays and programming in C Hafiz!
    Personally I prefer the programming language VHDL which is a concurrent programming language compared to C, Java, Arduino, Assembly, Basic etcetera that all are sequential languages. Why in VHDL we even can program Microprocessors and other hardware in (often ready made IP routines) code because all inputs, outputs and internal signal transfers happen at the same time at every new clock pulse. And at very high speeds!

    Likes(2)Dislikes(0)
  3. Waleed Rishmawi

    March 23, 2020 at 7:21 pm

    thanks for sharing this information with you. have a blessed sage day

    Likes(1)Dislikes(0)
  4. Robert Calk Jr.

    March 28, 2020 at 6:19 pm

    Good job, Hafiz!

    Likes(0)Dislikes(0)
  5. Humberto

    April 1, 2020 at 2:32 am

    Hi Mr. Hafiz Abdul Haseeb Tariq, I´ve really enjoyed reading yuor article, very interesting.

    Likes(0)Dislikes(0)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Free Report