The LED Chasing Effect Project using Atmel AVR Microcontroller

The LED chasing effect project

One of the interesting projects for most of the embedded beginners enthusiasts or hobbyists is to build the LED chasing effect.

The LED chasing effect project

In this project we are going to use both the Arduino IDE and Atmel AVR Studio to program the AVR ATMega168 microcontroller, therefore you could learn to use these well known Integrated Development Environment (IDE) to program the project.
The LED Chasing Project
To complete the project you need the AVRJazz 28PIN board from ermicro store or Arduino board with eight 470 Ohm resistors, eight 3 mm LED, one 10K Ohm trimmer potentiometer (trimpot), and breadboard as shown on this following picture:

Schematic The LED Chasing Effect Project using Atmel AVR Microcontroller

Now let’s start with the Arduino sketch first version of the LED Chasing Effect:

/*****************************************************************************
//  File Name    : LED_Chase.pde
//  Version      : 1.0
//  Description  : LED Chasing Effect Project
//  Author       : RWB
//  Target       : AVRJazz 28PIN Board (ATMega168)
//  Compiler     : AVR-GCC 4.3.2; avr-libc 1.6.4 (WinAVR 20081205)
//  IDE          : Arduino 0022
//  Programmer   : AVRJazz 28PIN STK500 v2.0 Bootloader
//               : Arduino 0022 - avrdude
//  Last Updated : 18 February 2012
*****************************************************************************/
byte LEDPin[]={0,1,2,3,4,5,6,7};
char LEDDirection=1;
char LEDOn=0;
unsigned int LEDDelay;
void setup() {
  // Set the digital PIN (0-7) to the Output Mode
  for (byte count=0; count <= 7; count++) {
    pinMode(LEDPin[count],OUTPUT);
  }
}
void loop() {
  // Turn off all the digital Output (0 - 7)
  for (byte count=0; count <= 7; count++) {
    digitalWrite(LEDPin[count],LOW);
  }
  // Turn ON one LED
  digitalWrite(LEDPin[LEDOn],HIGH);
  // Changed to the next LED
  LEDOn += LEDDirection;
  // Change the direction when reach 0 or 7
  if (LEDOn >= 7)
    LEDDirection=-1;
  if (LEDOn <= 0)  
    LEDDirection=1;  
  // LED Chasing Delay  
  LEDDelay=analogRead(0);  // Select Analog PIN 0 for the Trimpot Input
  delay(LEDDelay);             
}  
/* EOF: LED_Chase.pde */

The program start with the variable declaration, where we connect the LED on pin 0 to 7 to the Arduino board digital output port. Next inside the setup() function we change the digital pin to the output mode (default is input mode) by using the pinMode() function.

After called the setup() function on the program execution, next the Arduino library will call the loop() function continuously; therefore we put the LED chasing effect algorithm together with the analog input reading inside this function.

// LED Chasing Delay
LEDDelay=analogRead(0); // Select Analog PIN 0 for the Trimpot Input
delay(LEDDelay);

The trimpot will function as the voltage divider circuit and supply the varying voltage input (0 to 5 volt) to the Arduino board analog input 0.

After compiling the LED chasing program we get about 1236 bytes of the Intel HEX code size (a binary file format used to program the microcontroller), the following is the slim Intel HEX code (842 byte) version of the LED chasing program using a “Non Arduino” approach of manipulating the digital output port.

Read more: The LED Chasing Effect Project using Atmel AVR Microcontroller

Leave a Comment

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