Project tutorial
Ambient Light Sensor Using Photo Resistor and LED Lights!

Ambient Light Sensor Using Photo Resistor and LED Lights! © GPL3+

Uses a photo resistor to determine whether a room is bright, average or dark. It shows this using 3 LEDs and/or the serial monitor.

  • 3,487 views
  • 4 comments
  • 17 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
Any board with an analog pin, at least two digital pins and at least three grounds will work.
×1
Adafruit industries ada161 image 75px
Photo resistor
×1
09590 01
LED (generic)
Two different colors.
×2
Mfr 25frf52 1k sml
Resistor 1k ohm
×1
Mfr 25frf52 100r sml
Resistor 100 ohm
I used 220 ohm resistors, but I think 100 ohm will work better.
×2
11026 02
Jumper wires (generic)
×1
12002 04
Breadboard (generic)
×1

Apps and online services

About this project

I’ve been using Arduino for a little while now and I’ve decided it’s past time to design my own project from scratch. I modified some circuits I found online from Alex Glow and Joe Coburn so they better suited this project. Please, if you find any problems, or think you found something that works better than my design, please comment below and I will get back to you.

Wiring

I have a photo resistor wired into analog pin 0 (any analog pin would work) and a 5V on the right side of the breadboard. It runs through a grounded 1K ohm resistor. I wired an LED (any color) on the opposite side of the breadboard into digital pin 13 (any digital pin would work) and a grounded 220-ohm resistor (a 100-ohm would also work). Slightly to the right of the first LED a wired an LED of a different color the same way, just with a different digital pin.

How It Works

If the photo resistor reads a value above 450, it prints “It is quite light!” on the serial monitor and turns all LEDs off, like this:

  if(light > 450) { // If it is bright... 
       Serial.println("It is quite light!"); 
       digitalWrite(13,LOW); //turn left LED off 
       digitalWrite(12,LOW); // turn right LED off 
   } 

If it reads a value between 230 and 450, it prints “It is average light!” on the serial monitor and turns on the left LED, like this:

   else if(light > 229 && light < 451) { // If it is average light... 
       Serial.println("It is average light!"); 
      digitalWrite(13, HIGH); // turn left LED on 
      digitalWrite(12,LOW);  // turn right LED off 
   }  

This only leaves us with values below 230 to account for. If a value is below 230, it prints “It is quite dark!” on the serial monitor and turns on both LEDs, like this:

   else { // If it's dark... 
       Serial.println("It is pretty dark!"); 
       digitalWrite(13,HIGH); // Turn left LED on 
       digitalWrite(12,HIGH); // Turn right LED on 
   }  

I added a delay of 1000 to the end of my loop to prevent an overload of information into the serial monitor, like this:

delay(1000); // don't spam the computer!

Make sure you look at the schematic and check your code before uploading or running anything.

Code

LED_PR_Light_ReadArduino
int light = 0; // store the current light value

void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600); //configure serial to talk to computer
    pinMode(13, OUTPUT); // configure digital pin 13 as an output
    pinMode(12, OUTPUT); // configure digital pin 12 as an output
}

void loop() {
    // put your main code here, to run repeatedly:
    light = analogRead(A0); // read and save value from PR
    
    Serial.println(light); // print current light value
 
    if(light > 450) { // If it is bright...
        Serial.println("It is quite light!");
        digitalWrite(13,LOW); //turn left LED off
        digitalWrite(12,LOW); // turn right LED off
    }
    else if(light > 229 && light < 451) { // If it is average light...
        Serial.println("It is average light!");
       digitalWrite(13, HIGH); // turn left LED on
       digitalWrite(12,LOW);  // turn right LED off
    }
    else { // If it's dark...
        Serial.println("It is pretty dark!");
        digitalWrite(13,HIGH); // Turn left LED on
        digitalWrite(12,HIGH); // Turn right LED on
    }
    delay(1000); // don't spam the computer!
}

Schematics

Component Setup
Lightsensorpusps tuczprouqa

Comments

Author

Dcamino
DCamino
  • 1 project
  • 2 followers

Additional contributors

  • I modified her led circuit. by Alex Glow
  • I modified his photo resistor circuit. by Joe Coburn
  • I added his schematic to the tutorial. it looks much better than the original! by loplo

Published on

January 27, 2018

Members who respect this project

AdambenzAvatar fofgrbxpczDefaultDefaultDefault

and 13 others

See similar projects
you might like

Similar projects you might like

Arduino Traffic Light Simulator

Project tutorial by Zachary Haslam

  • 8,026 views
  • 1 comment
  • 20 respects

Arduino Burglar

Project showcase by paolo_cravero

  • 2,399 views
  • 2 comments
  • 6 respects

Musical Fairy Lights

Project tutorial by Ian Cumming

  • 4,853 views
  • 0 comments
  • 11 respects

Turn On and Off LED by LDR (Toggle LDR)

Project showcase by muhammed amar slik

  • 19,980 views
  • 1 comment
  • 13 respects

Hall effect sensor with Arduino

Project tutorial by AMAL NS

  • 9,420 views
  • 1 comment
  • 22 respects
Add projectSign up / Login