Embedded Systems are widely used nowadays. Applications of the embedded system are innumerable. One such application as discussed here is Lift Overload Indicator. As the name implies, it restricts the elevator from transporting a number of people above the maximum prescribed limit.
The indicator used here is RGB led to indicate the warning signs. Moreover, it also displays the net number of people in the elevator using an LCD in 4-bit mode. The counting of the person is accomplished by using two IR sensors.
Fig. 1: Prototype of AVR ATMega16 based Lift Overload Indicator
DESCRIPTION:
RGB LED:
We know that using the three primary colours Red, Blue and Green, any secondary colour can be obtained. The RGB led uses the same principle. Different colours are generated by mixing of different intensities of the three primary colours.
Fig. 2: Image showing pin description of RGB LED
It has got four pins viz., Red supply, Blue supply, Green supply and Ground. The intensities of each of these colours are controlled using PWM (Pulse Width Modulation). The contribution of intensities of each of this colour determines the resultant colour in RGB led and it glows accordingly. The function for RGB led is written below. The RGB pins are controlled using three timers offered by ATmega16, particularly Timer0 and Timer1. Refer to my last article for more information on timers.
void rgb_led(unsigned char red ,unsigned char green, unsigned char blue)
{
OCR0=((255*blue)/100); //Output Compare Match Value for Blue Led
OCR1A=((255*green)/100); //Output Compare Match Value for Green Led
OCR1B=((255*red)/100); //Output Compare Match Value for Red Le
}
As shown above, we have used three different PWM for controlling intensity of each colour. The 16-bit TIMER-1 is split into two 8-bit timer (OCR1A & OCR1B).
The arguments of the above function are passed in the form of percentage which is then converted into its equivalent PWM. This is explained below with an example:
rgb_led(90,50,50);
This will illuminate the red colour by 90%, blue by 50% and green by 50%.The setting of various bits in the TIMER registers is shown below.
// Configure timer 1
TCCR1A=(1<<WGM10); // Fast PWM mode (8-bit) TCCR1A|=((1<<COM1A1)|(1<<COM1B1)); // Reset OCR on Compare Output Match TCCR1B=(1<<WGM12);// Fast PWM mode (8-bit) TCCR1B|=(1<<CS11);
// Prescaler set to 1/8 DDRD=((1<<PD4)|(1<<PD5)); // OCR1A and OCR1B set as output pins
// Configure timer 0
TCCR0|=((1<<WGM01)|(1<<WGM00)); // FAST PWM mode TCCR0|=(1<<COM01);
// set OCR0 on match TCCR0|=(1<<CS01); // pre-scaler set to 1/8; DDRB|=1<<PB3; // OCR0 set as output pin
LCD:
The LCD is used to display the number of persons inside the elevator at any point of time. The LCD is used in 4-bit mode .Refer to my last article for better understanding of the LCD. I have used a new function which passes string type argument to the LCD.
void lcd_string (char *z) // To display string on LCD
{ unsigned char i=0;
while (z[i]!=’