Caçador de LED usando AVR ATMega16

LED Hunter using AVR ATMega16

You may have seen many different LED tracker designs. Simple LED chaser can be built using IC555 and digital counter chips. Many LED chasers are built using microcontrollers. The microcontroller-based LED chaser has a variety of different chasing effects. One can generate an amazing LED chasing effect using microcontroller programming. There can be 8 or 10 or 16 or even more LEDs connected to the microcontroller and it will turn the LEDs on/off or vary their brightness or blink them to create wonderful effects. Mostly there are single color LED (probably RED), but now you can find multi-color LED chasers with different LED colors such as RED, GREEN, BLUE, YELLOW, ORANGE, etc. The latest LED chasers are based on RGB LEDs. RGB LED can generate a variety of different colors and effects.

This project presented here uses the AVR ATMega16 microcontroller. There are 35 multi-color LEDs (RED, GREEN, BLUE and GREEN) connected to generate an eye-catching chasing effect. For demonstration purposes, only 35 LEDs connected to just one port of the ATMega16 are used, but it is possible to connect up to 200 LEDs to generate different chasing effects. So let's see how this is done.

Circuit Diagram

As you can see, the circuit is built using AVR ATMega16 microcontroller and Darlington ULN2003A chip.

  • As shown in figure 5, LEDs of the same color are connected in parallel, forming a group. There are 7 of these LED groups, each with 5 LEDs, for a total of 35 LEDs.

  • All these groups of LEDs are connected to the PORTB via the Darlington ULN2003A chip. UNL2003A is used as a current driver to supply sufficient current to the LEDs.

  • PORTB pins PB0 to PB6 are connected to the inputs of the ULN2003A and the outputs of the ULN2003A are connected to the common cathode of the LED group.

  • The common anodes of all LED groups are connected to Vcc through a 300E current limiting resistor.

  • A button is connected to the PORTD PD2 pin which generates external interrupt when pressed

  • An 8 MHz crystal with two 22 pF capacitors is connected to the input pins of the crystal which provides basic clock for microcontroller operation.

Protótipo de circuito LED Chaser baseado em AVR ATMega16 projetado em placa de ensaio

Fig. 1: LED Chaser circuit prototype based on AVR ATMega16 designed on breadboard

Work and operation:

There are 6 different chase effects and the effect is changed by pressing the button. Initially when the project is turned on the 1 st the chasing effect will begin. This will continue until the button is not pressed. As the button is pressed, interrupt is generated and the controller will switch to 2 and chase effect. Likewise, pressing the button for the second time, for the third time and in the same way, will change the 3rd 4th 5th and 6th chase effect . Again, if the button is pressed, the microcontroller will initiate 1 st chase effect. Now let's see what these different stalking effects are.

1st chase effect: This is the simplest chase effect. It flashes all LEDs at 10 Hz for 5 seconds and then flashes alternating LEDs at 10 Hz for 5 seconds and repeats this continuously.

2 and chase effect: LED will light one by one from left to right and then from right to left

3 third chase effect: will vary the intensity of the alternating LEDs from maximum to minimum and from minimum to maximum. Just as when LED groups L1, L3, L5 and L7 have maximum intensity, L2, L4 and L6 have minimum intensity. Then, slowly, the L2-L4-L6 intensity increases and reaches a maximum, while the L1-L3-L5-L7 intensity decreases and reaches a minimum. This cycle is continuous.

4th chase effect : this effect is equal to 2 and but a small change is that it will light up two LEDs at a time, from left to right and again from right to left.

5th chase effect : this effect turns ON all the LEDs one by one from left to right and then turns them OFF from right to left

6th chase effect : this effect will turn on all the LEDs from both sides to the center and turn them off from the center to the sides.

All the above chasing effect is due to the program downloaded into the internal FLASH of the ATMega16 microcontroller.

Software program:

The program is written in C language. It is compiled using the AVR Studio software tool. It is simulated using the AVR 2 simulator for the ATmega16 device available with AVR Studio software. Here is the C program code

Project source code

###

#include

#include

#include


unsigned int j,count=0,new_effect_flag=0;

unsigned char byt, byt1;

void delay(unsigned int d1)

{

unsigned int x;

for(x=0;x

_delay_us(2);

}

void effect1

{

while(new_effect_flag==0)

{

for(j=0;j<25;j++)

{

PORTB = 0x00;

_delay_ms(100);

PORTB = 0xFF;

_delay_ms(100);

}

for(j=0;j<25;j++)

{

PORTB = 0x55;

_delay_ms(100);

PORTB = 0xAA;

_delay_ms(100);

}

}

}

void effect4

{

unsigned char tmp;

while(new_effect_flag==0)

{

PORTB=0xFF;

_delay_ms(1000);

byt1 = 0xFC; // 1111 1100

byt = 0xFE; // 1111 1110

PORTB = byt1; // 1111 1100

_delay_ms(1000);

for(j=0;j<5;j++)

{

tmp = ~byte; // 0000 0001

byt1 = byt1<<1; // 1111 1000

PORTB = byt1 tmp;

byt = byt<<1; // 1111 1100

_delay_ms(1000);

}

byt1 = 0x1F; // 0001 1111

byt = 0x7F; // 1011 1111

byt = byt>>1;

for(j=0;j<5;j++)

{

tmp = ~byte; // 0100 0000

byt1 = byt1>>1; // 0000 1111

PORTB = byt1 tmp;

byt = byt>>1;

_delay_ms(1000);

}

}

}

void effect2

{

while(new_effect_flag==0)

{

PORTB=0xFF;

_delay_ms(1000);

byt1 = 0xFE; // 1111 1110

PORTB = byt1; // 1111 1110

_delay_ms(1000);

for(j=0;j<6;j++)

{

byt = ~byt1; // 0000 0001

byt1 = byt1<<1; // 1111 1100

PORTB = byt1 byt;

_delay_ms(1000);

}

byt1 = 0x7F;

for(j=0;j<6;j++)

{

byt = ~byt1; // 0000 0001

byt1 = byt1>>1; // 1111 1100

PORTB = byt1 byt;

_delay_ms(1000);

}

}

}

void effect3

{

unsigned int a,b,a1;

while(new_effect_flag==0)

{

for(a=10;a<100;a++)

{

a1 = 100-a;

for(b=0;b<10;b++)

{

PORTB = 0x55;

delay(a);

PORTB = 0xAA;

delay(a1);

}

}

for(a=99;a>10;a--)

{

a1 = 100-a;

for(b=0;b<10;b++)

{

PORTB = 0x55;

delay(a);

PORTB = 0xAA;

delay(a1);

}

}

}

}

void effect5

{

while(new_effect_flag==0)

{

PORTB=0xFF;

_delay_ms(1000);

PORTB=0xFE;

_delay_ms(1000);

for(j=0;j<6;j++)

{

PORTB=PORTB<<1;

_delay_ms(1000);

}

byt1 = 0xFE;

byt = ~byt1;

PORTB = byt;

_delay_ms(1000);

for(j=0;j<6;j++)

{

byt1 = byt1<<1;

byt = ~byt1;

PORTB = byt;

_delay_ms(1000);

}

}

}

void effect6

{

while(new_effect_flag==0)

{

PORTB = 0xFF;

_delay_ms(100);

PORTB = 0x3E;

_delay_ms(100);

PORTB = 0x1C;

_delay_ms(100);

PORTB = 0x00;

_delay_ms(100);

PORTB = 0x1C;

_delay_ms(100);

PORTB = 0x3E;

_delay_ms(100);

}

}


int main(void)

{

DDRB=0xFF;

MCUCR = (1<

GICR=(1<

know ;

while(1)

{

new_effect_flag=0;

switch(count)

{

case 0:

effect1;

break;

case 1:

effect2;

break;

case 2:

effect3;

break;

case 3:

effect4;

break;

case 4:

effect5;

break;

case 5:

effect6;

break;

case 6:

count=0;

break;

}

}

}


ISR(INT0_vect)

{

count++;

new_effect_flag=1;

_delay_ms(200);

 } ###

Circuit diagrams

Circuit diagram of LED Chaser based on AVR-ATMega16

Project video

Back to the blog

Leave a comment

Comments need to be approved before publication.