Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Intelligent LED light controller using AVR

By Ashutosh Bhatt March 20, 2014

 

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.It is assumed that the reader has gone through the project How to get started with AVR and done all the things discussed in it.

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

Prototype of AVR ATMEga16 based Automatic LED Light Controller

Fig. 1: Prototype of AVR ATMEga16 based Automatic LED Light Controller

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. 

Project Source 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
        }
 }







###

 


Circuit Diagrams

Circuit-Diagram-AVR-ATMEga16-Based-Automatic-LED-Light-Controller

Project Video


Filed Under: Electronic Projects
Tagged With: avr, LED light controller
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Finding past posts on edaboard?
  • Industrial Relay Board Design for Motorcycle Use
  • I think i have devised a new type of "super_transformer" for the Electricity grid?
  • What is the purpose of this relay?
  • mosfet driver problem in regeneration mode

RSS Electro-Tech-Online.com Discussions

  • Pic18f25q10 osccon1 settings swordfish basic
  • Sump pit water alarm - Kicad 9
  • Anyone jumped from Easyeda std to Easyeda pro?
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe