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

Creating a Light Level Sensor Along With Light Compensation using Arduino/Microcontroller

By Soham Chetan Kamani July 17, 2013

 

This project is going to guide you through making your very own light level detector, using cheap components and also providing compensation in the form of artificial light whenever the ambient light level in the room is low. Additionally, sensitivity adjustment can also be added for more precise systems.The sensor system can be used for a variety of applications such as an automatic stabilizer for light levels at home or at work, or you can just make one as a fun hobby or for a project. For this project reader need knowledge about how to start with arduino

 
WORKING PRINCIPLE
      ·     The circuit measures the surrounding light using the photodiodes.
      ·     Two photodiodes are connected in parallel for optimum performance.
      ·     The photodiodes are connected in reverse-bias, in series with a 10k resistor.
      ·   Anode is connected to the resistor and also to the analog input pin of the arduino board while the cathode is connected to the power supply.
      ·     The light received by the diodes is given to the arduino in the form of an analog signal.
      ·     This analog signal is processed by the inbuilt ADC of the arduino board.
      ·     The processed signal is then calibrated to form data which maps to a suitable range.
      ·     The data is then fed in BCD form to the BCD to Seven segment (IC7447).
      ·     The IC converts binary data and directly determines the appropriate segments to show the desired output.
      ·     Simultaneously the arduino also switches on a number of led’s. this number is based on the measured value of surrounding light.
      ·    The sensitivity of the instrument can be varied by changing the value of resistance in series with the photodiode or by connecting more photodiodes in parallel.
      ·     Alternatively, if you wish to dynamically adjust the sensitivity, a 10k or 50k potentiometer can be connected in place of the resistor in series with the photodiodes.

 Guidelines & Code Algorithm

PROCEDURE AND GUIDELINES
    1) Gather the various components mentioned in the ‘components’ section. You can either use a breadboard to construct the circuit or for a more permanent model, a perf board can be used ( provided you have the adequate soldering skills).
      2) Connect female jumper wires to the arduino so they can be detached easily for any modifications.
      3) Connect the wires to the relevant pins of the IC. For soldered connections, an IC stand must be used, otherwise the IC could undergo heat damage.
      4)Place the seven segment display close to the IC as it will make connections easier and save wire.
      5) The photodiodes should be connected in reverse bias ( the longer of the two leads from the photodiode should be connected to ground).
     6) Two or three photodiodes are connected in parallel for better accuracy. If only one is used, any change in direction of the incoming light will drastically change the reading. Use of multiple photodiodes for measurement will make the system more independent of the direction of incoming light and hence will give a more accurate reading for the intensity.
      7) The photodiodes should be placed facing vertically upwards.
      8) Connect the resistor connected to the photodiodes to a 5v supply. If you are using arduino, the power supply can be found on the board itself. If you are using another microcontroller, a 5v or 6v battery can be used.
      9) Connect the leds to the appropriate pins on the arduino. The values of the resistors connected in series with the leds can be reduced in case the leds are too dim or not lighting at all.
     10) IC 7447 can be tested by grounding pin 3 of the IC. It is recommended to test the IC before making soldered connections to the 7 segment display.
      11) The anode of the CA 7 segment display can also be connected to the 5v power supply in series with a resistor.
      12) The arduino is connected to the PC using an A-B USB cable.
      13) Software used is open source and available on the arduino website.
      14) The code is written in C language.
CODE ALGORITHM
      a) The pins connected to the leds and IC7447 are configured as output pins, and the analog pin A0 is configured as an input pin.
     b) Three continuous readings are taken from A0 at 1ms delay. The highest of the 3 readings is taken as the true reading (since the photodiodes are highly directional, so a 0 reading is not uncommon).
     c) The absolute value of the reading is divided by 40, which gives the relative reading (can be divided by a lesser number if the sensitivity is to be increased).
      d)  Based on the value of the relative reading, the binary data is given to the pins connected to IC7447 and the pins connected to the leds are switched on or off. For example, if the relative reading is 5, 0101(5 in binary) binary data is given to the IC pins, and the amount of leds switched on is 2.
      e) The process is repeated to give continuous readings.
      

 

 

 

 

Project Source Code

###


void setup()
{
  Serial.begin(9600);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
}
int takereading()
{
  int r1=analogRead(A5);
  delay(1);
  int r2=analogRead(A5);
  delay(1);
  int r3=analogRead(A5);
  delay(1);
  int rr;
  if(r1>r2&&r1>r3)
  rr=r1;
  else if(r2>r1&&r2>r3)
  rr=r2;
  else
  rr=r3;
  return rr;
}
void loop()
{
  int reading=takereading();
  int value=reading/40;
  Serial.println(value);
  if(value==0)
  {
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    digitalWrite(10,HIGH);
  }
  else if(value==1)
  {
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    digitalWrite(10,LOW);
  }
  else if(value==2)
  {
    digitalWrite(2,LOW);
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    digitalWrite(10,LOW);
  }
  else if(value==3)
  {
    digitalWrite(2,HIGH);
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
  }
  else if(value==4)
  {
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
  }
  else if(value==5)
  {
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
  }
  else if(value==6)
  {
    digitalWrite(2,LOW);
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
  }
  else if(value==7)
  {
    digitalWrite(2,HIGH);
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,HIGH);
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
  }
  else if(value==8)
  {
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
  }
  else 
  {
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,HIGH);
    digitalWrite(6,LOW );
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
  }
    
  delay(100);
}

###

 


Circuit Diagrams

Ckt-Diagram-copy


Filed Under: Electronic Projects
Tagged With: Arduino, light level sensor, microcontroller
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.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

  • Identification of a 6 pin smd chip (sto-23-6) marked E2
  • Dynacord enter protect
  • IGBTs without negative gate drive
  • Need suggestions in task NI6363 retrigger (analog trigger)
  • Monte-Carlo simulation error on ADE-XL

RSS Electro-Tech-Online.com Discussions

  • Does US electric code allow branching ?
  • Faulty heat air gun (dc motor) - problem to locate fault due to Intermittent fault
  • Fun with AI and swordfish basic
  • Sump pit water alarm - Kicad 9
  • turbo jet fan - feedback appreciated.

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