Thứ Sáu, 14 tháng 12, 2018

Intelligent LED light controller using AVR

Now a days LED light bulbs are becoming more and more popular because they have several advantages. Some of their advantages are listed below
·         Their energy (electrical) consumption is much more less
·         Their luminance is more
·         Their intensity can be varied
·         Their life time is more
So if LED lights are used in place of conventional lights we can save much more electrical energy that leads to saving of conventional energy sources like coal, petrol, diesel etc. Also the light intensity of LED can be varied as per ambient light. That is one more plus point in saving electrical energy. We can set the light intensity to required level and get dual advantage of having exact amount of luminous and saving of energy.
So here I am presenting a demonstration of varying LED light intensity as per change in ambient room light using AVR micro-controller. Like, when room light is maximum (during day time) no need of LED light so LED is off but as ambient room light decreases the LED light intensity starts increasing. LED light will be fully ON when room light is very low.
I have used LDR as light sensor. It senses ambient room light and gives signal to AVR micro-controller. Micro-controller determines this room light and varies intensity of LED light accordingly using PWM method.
Circuit diagram:
Connections: -
·         LDR is connected between Vcc and Gnd with fixed value 10 K resistor as shown. 10 K resistor provides bias to LDR
·         The LDR junction output is fed to ADC0 input pin of AVR micro controller
·         Two LEDs are connected to PORTD pins PD0 and PD1 through current limiting resistors. They indicate max and min LED intensity
·         The PWM output pin PB3 is fed to base of Darlington amplifier through 250E current limiting resistor
·         Darlington amplifier is made up of two NPN type 2N2222 transistors. It is used to increase the output current of micro-controller
·         A 10 V white LED bulb is connected at the output of Darlington amplifier as shown
·         A 16 MHz crystal with two 22 pf capacitors is connected to crystal input pins

Operation: -
·         During day time when room light is enough the LDR resistance is low. So its output voltage is less. It is converted in to digital value by built in ADC of AVR micro controller
·         This digital output is also very low. So LED light bulb is off. Its indicated by GREEN led
·         In the evening as room light decreases the LDR resistance increases that leads to increase in its output voltage
·         The micro controller start increasing width of pulse fed to LED light bulb. So its intensity gradually increases
·         Finally at night when no room light LED bulb intensity reaches to maximum. It is indicated by RED LED
intelligent

Software Program & Further Advancement

Software program:
The operation of the circuit depends upon the program downloaded in to micro controller. The program is written in C language in AVR studio software. It is compiled using AVR simulator available with AVR studio. When program is compiled the HEX file is created. This HEX file is loaded into ATMega16 micro-controller using any suitable AVR programmer. Here is the complete program given with necessary comments.
Further advancement:
Multiple LDR sensors are placed in different places of big room or in different rooms that controls different LED light bulbs placed at different places in room or different rooms.
A separate standalone unit can be made that can be placed at any remote location. The unit includes solar panel, battery, battery charging circuit, LED light bulb, LDR sensors and LED light controller circuit. 


Circuit:
Intelligent LED light controller using AVR: circuit Diagram
Code:
#include <avr/io.h>
#include <util/delay.h>
void adcinitliz()                   // initialize built in ADC
  {
      ADMUX = (1<<REFS0);
      ADCSRA =(1<<ADPS2) | (1<<ADPS1) | (0<<ADPS0);
      ADMUX=(0<<MUX2) | (0<<MUX1) | (0<<MUX0) ;
  }
unsigned int convert()              // convert 10 bit HEX value into
  {                                 // decimal equivalent
      unsigned int tmp1,tmp2,tmp3,t;
      tmp1 = (ADCL & 0x0F);
      tmp2 = ADCL >> 4;
      tmp3 = (ADCH & 0x0F);  
      tmp2 = tmp2*16;
      tmp3 = tmp3*256; 
      t = tmp1+tmp2+tmp3;           // and return decimal value  
      return t;
  }
void main()
 {
      unsigned int adc_value;
      DDRB=0x08;                    // configure PWM pin as output
      PORTB=0x00;
      DDRD=0xFF;                    // PORTD as output
      PORTD=0x00;
      TCCR0=0x6B;                   // configure timer as fast PWM
      adcinitliz();                 // initialize ADC
      while(1)
        {
            ADCSRA = (1<<ADEN) | (1<<ADSC);     // give start pulse to ADC
            while(!(ADCSRA & (1<<ADIF)));       // wait for conversion end
            ADCSRA = (1<<ADIF);
            adc_value = convert();              // get decimal value
            if(adc_value<99)                    // if its too less
              {
                  TCCR0 = 0x00;                 // stop timer
                  PORTB = 0x00;                 // LED light bulb off
                  PORTD = PORTD | 0x02;         // green LED ON
              }
            else TCCR0 = 0x6B;                  // start timer else
                        // change PWM width as LDR output (ADC value) changes
            if((adc_value>=99) && (adc_value<199)) OCR0 = 20;
            else if((adc_value>=199) && (adc_value<199)) OCR0 = 40;    
            else if((adc_value>=199) && (adc_value<299)) OCR0 = 60;    
            else if((adc_value>=299) && (adc_value<399)) OCR0 = 80;
            else if((adc_value>=399) && (adc_value<499)) OCR0 = 100;
            else if((adc_value>=499) && (adc_value<599)) OCR0= 140;
            else if((adc_value>=599) && (adc_value<699)) OCR0 = 180;
            else if((adc_value>=699) && (adc_value<799)) OCR0 = 200;
            else if((adc_value>=799) && (adc_value<899)) OCR0 = 220;   
            else if((adc_value>=899) && (adc_value<999)) OCR0 = 240;
            else if(adc_value>=999)       // if value is max 
              {
                  OCR0 = 250;             // set max width for PWM
                  PORTD = PORTD | 0x02;   // RED LED ON
              }
            _delay_ms(1000);              // wait for 1 sec
            PORTD = PORTD & 0xFC;         // both LED off
        }
 }

Không có nhận xét nào:

Đăng nhận xét

Bài đăng mới nhất

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01 # candientu ,  # fujihatsu ,  # candientufujihatsu  #candientu,  # candientufujhatsu , #fuji...

Bài đăng phổ biến