LED Interfacing with AVR

Embedded Systems With AVR Tutorial Series

LED Interfacing with AVR ATmega16

Hey LED..!! Start Blinking...!!

 

Contributed By:- Mitanshu Kumar

BEST_EMBEDDED_TRAINING_IN_BHOPAL

-----------------------------------------------------

 

LED (Light emitting diode) as clear from its name; is a semiconductor light emitting diode or light source. It is a P-N junction diode that emits light when an electric current passes through it.

   Fig.1  Light Emitting Diode

 

As it is P-N junction diode, It works only in Forward biased direction i.e. when It’s positive terminal(Anode) is at High Voltage(Logic1) and the negative terminal(Cathode) at Low Voltage(Logic0).

 

Generally; the working voltage range of LEDs are 1.5V to 5V and It can withstand only 20mA of current. That’s why Resistor of 1kΩ is always used with LEDs to protect them from getting damaged.

 

How to differentiate between the terminals of an LEDs?

By observing its external legs:-

Longer leg(Anode/Always Positive)

Shorter leg(Cathode/Always negative)

 

By observing its internal flags:-

Thinner flag(Anode/Always Positive)

Thicker flag(Cathode/Always negative)

 

By observing its bottom circumference:-

If you observe carefully the bottom surface of LED, It doesn’t look complete circular; there is a slight cut mark on its negative terminal side.

This method is used when the above two methods failed to differentiate the terminals.

 

By Using Digital Multimeter (DMM):-

This method is best and last method to differentiate the terminals of LEDs when all the above methods raised their hands.

In continuity mode of DMM, connect the terminals of LEDs to positive and negative terminals of DMM and check accordingly it lights up or not.

 

Blinking LEDs in different patterns are used in our day-to-day life at different places like; as indicators, Advertisement Hoardings, Information Boards at Railways, Traffic lights and many more.

 

 Here is the few LED Blinking pattern using AVR (ATmega16) for learners.

 

Things required:

Name

Proteus code

ATmega16 microcontroller

Atmega16

8 pieces of LEDs

Led active

wires

-

 

 

Infinite loop_8LEDs Blinking for Infinite Times

Write a program to blink 8 LEDs connected on PORT-D in an infinite loop.

(Language- Embedded C)

 

#define F_CPU 1000000UL       //Frequency of CPU = 1MHz

#include             //To provide i/o information to compiler

#include     //To use syntax for delay

 

void main()                   //Mains function starts here

{

DDRD= 0B11111111;             //PORT'D' declared as output

while(1)                      //To form an infinite loop

{

      PORTD= 0B11111111;            //To turn ON all the LEDs

      _delay_ms(500);         //To provide delay of 0.5sec.

      PORTD= 0B00000000;            //To turn OFF all the LEDs

      _delay_ms(500);         //To provide delay again           

}

}

 

 

Finite loop_finite blinking of 8 LEDs

Write a program to blink 8 LEDs connected on PORT-D in a finite loop.

(Language- Embedded C)

 

 

#define F_CPU 1000000UL       //Frequency of CPU = 1MHz

#include             //To provide i/o information to compiler

#include     //To use syntax for delay

 

void main()                   //Mains function starts here

{

DDRD= 0B11111111;             //PORT'D' declared as output

int i=0;

for(i=0;i<8;i++)              //To form a finite loop(8 times)

{

      PORTD= 0B11111111;            //To turn ON all the LEDs

      _delay_ms(500);         //To provide delay of 0.5sec.

      PORTD= 0B00000000;            //To turn OFF all the LEDs

      _delay_ms(500);         //To provide delay again           

}

}

 

CLICK HERE TO VIEW / DOWNLOAD AVR TRAINING SYLLABUS

 

CLICK HERE TO REGISTER NOW FOR AVR TRAINING..

 

 

Top