Interfacing of led with 8051 microcontroller

Led Design output


This tutorial gives you an introduction a very basic operation of Led to get an output from the 8051 MCS family i.e. AT89S51. As we aware that in our day to day running life Led has a wide range of useful application in almost every electronics & electrical devices like as an indicator, in TV & monitor, in electronics circuit, digital clock, watches, traffic light panel etc. Due wide applications of Led this tutorial will show the principle behind the interfacing of Led with 8051 microcontroller’s family as shown in picture below. Now we are going to interface single Led with AT89S51 microcontroller in our explanation section.


Before proceed toward the interfacing of led, we should know about the basic Led operation, principle of Led working & AT89S51 microcontroller.

So for interfacing of Led with AT89S51 microcontroller, we will use the AT89S51, which belongs to the Atmel family of 8051 series of microcontrollers, is very commonly used by a large consumer’s of hobbyist, electronics lover, engineers & project designer for learning & developing purpose. Its simplicity and easy way of programming with inbuilt features with mostly device compatibly, easily makes its position in the top preferred list of microcontroller for both new learner and experts’ user for projects.

We need a one controlling unit in our circuit which understand programming logic which is written by us. So for this we are using an 8-bit AT89S51 8051 series microcontroller which has 64 kB Flash Memory (ROM) and 1024 bytes of data RAM which operates at 11.059n Mhz crystal frequency. It is 40 Pin Package which contain 4 Ports & 8 Pin each i.e. 32 pin of Input/output Programming & rest of 8 Pin for other operation like crystal oscillator pins, reset pin, external memory pins & its operate at 5V & 60mA current we can withdraw from Pins as shown in below picture. Its supports the in serial In-System Programming (ISP). ISP feature of 8051 MCS that allows a device which reprogrammed with high speed data that transfer with software control. AT89S51 has capability to update the application firmware makes a huge range of applications in industry.

8051 pin diagram 

As we can see that from above picture that our microcontroller AT89S51 has 4 ports P0, P1, P2, P3 each port contain 8 pin for input/output operations.

As we know that Light Emitting Diodes, mainly called LEDs, which emit the light when forward biased or we can say that it emits the light when it’s excited by external power voltage source. When we applied a voltage source across the terminals of led, means +ve terminal of source to anode of led & -ve to cathode then electron & holes recombine & reaches the higher energy state and higher energy state is unstable so that it release the energy in form of light (photons).

led circuit

Most of the commonly available LEDs have dropped a voltage of 1.3 V to 2.2 V and require 7 to 10 mA to glow Led at full intensity.But our microcontroller give an output of 5V & 60mA, due to this we will connect led through the resistance of 330 ohms using below formula.

R=(Vcontroller – Vled)/I

R = (Vcc-led voltage)/current.

R = (5-1.7)/10mA.

R= 330 Ohms.

Logic to Glow the Led from AT89S51 Microcontroller.

As we already explained that led will work on forward biasing means +ve to anode & -ve to cathode of led, similar way in digital electronics +5V means HIGH or Logic 1(one) & -Ve means LOW or Logic 0(zero).


So its means when Logic 1 or HIGH applied across to anode & LOW or Logic 0 to cathode then Led will Glow.

Circuit Design

Proteus Design of Interfacing of Led with 8051 microcontroller.

In the circuit of interfacing of led with 8051, we need an AT89S51 MCS, Led, resistor 330 ohms & connecting wires. Microcontroller need a clock for proper working & synchronization, without the clock the microcontroller will not do task. Hence a Crystal oscillator of clock 11.0592 MHz is connected between two pins 19 Xtal1 and 18 Xtal2 along with two 33pf capacitors as shown in design.

Led Design

As you can refer the above circuit image. We are connecting the Led to PORT 2 Pin number 0(zero) followed by resistance 330 ohms. When we put the program into microcontroller & then give the power to circuit then Port 2 Pin 0 give Logic 1 or HIGH to Led & Led Start Glowing with full intensity.

C Code

C Programming


This program is developed by EMBEDDINATOR DEVELOPERS.


sbit LED = P2^0;  // define Port2 pin as an LED

void delay(int k)  // Delay Function


int i,j;




void main()


while(1)  // infinite loop


LED = ~LED;  //  LED Glow


}// end of while loop

} // end of main
End program

Thank you for visiting our website


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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