8051 – Relay Interfacing by using ULN2803

In this tutorial we will learn Relay interfacing with 8051. Relay is very important component to interface the heavy appliances with the help of microcontroller.


Relays are devices which allow low power circuits to switch a relatively high Current/Voltage ON/OFF. A relay circuit is typically a smaller switch or device which drives (opens/closes) an electric switch that is capable of carrying much larger current amounts.


Current flowing through the coil of the relay creates a magnetic field which attracts a lever and changes the switch contacts. The coil current can be on or off so relays have two switch positions and most have double throw (changeover) switch contacts.

Construction and working

Relays are made up of electromagnet and a set of contacts generally based on Single Pole Double Throw (SPDT) or Double Pole Double Throw (DPDT) switching method. It has 3 pins to perform function –

  • COM = Common, always connect to NC; it is the moving part of the switch.
  • NC = Normally Closed, COM is connected to this when the relay coil is off.
  • NO = Normally Open, COM is connected to this when the relay coil is on.

You can easily understand the concept of Relay by looking this below image.

Suggest To Read

Before getting into Interfacing, You should know about the Relay Driver (ULN2803) and its need and working.

Relay Interfacing with 8051

Circuit Diagram

In this tutorial I’m connecting One Relay in Port 0.



If you want to make Relay ON, Just give the High Signal (1) to that pin which is connected to ULN2803. The concept of this code is just turn On the Relay for Some time and Turn Off the relay for some time.


sbit relay=P0^0;

void main()
    unsigned int i;
    while(1) {
        relay=1;                //Realy ON
        relay=0;                //Relay OFF


[ Please find the output image ]

That’s all guys… So Programming wise its very simple. It is like a LED program. But Hardware wise we should be careful. Because we might connect AC power supply devices here. So Be careful guys. Here I have given some Tasks. Please try that. and you may connect Fan, AC Motor, Lamp etc to relay.


  • Program to display the status of the relay in LCD display
  • Program to control the relay through serial communication
5 1 vote
Article Rating
Notify of

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

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
Ads Blocker Image Powered by Code Help Pro
Ad Blocker Detected!!!

It seems you are using adblocking software that prevents the page from fully loading.

The revenue we earn by advertisements is used to manage this website. Still, If you want to disable the ads, please become a premium member. Ads are disabled for Premium members.

Or please add www.embetronicx.com to your ad blocker whitelist or disable your adblocking software and reload the page.

Note: Please disable the ad blocker to access the membership pages also.

False Detection? Please write a mail to [email protected]