DCamino
Published © GPL3+

Ambient Light Sensor Using Photo Resistor and LED Lights!

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.

BeginnerFull instructions provided76,921
Ambient Light Sensor Using Photo Resistor and LED Lights!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
Any board with an analog pin, at least two digital pins and at least three grounds will work.
×1
Photo resistor
Photo resistor
×1
LED (generic)
LED (generic)
Two different colors.
×2
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 100 ohm
Resistor 100 ohm
I used 220 ohm resistors, but I think 100 ohm will work better.
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Component Setup

Code

LED_PR_Light_Read

Arduino
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!
}

Credits

DCamino

DCamino

0 projects • 7 followers

Comments