Project showcase
Reading a Photoresistor

Reading a Photoresistor © GPL3+

I will read the light value of the room, and have an LED turn on if it is dark and turn off if it is bright.

  • 25,897 views
  • 1 comment
  • 7 respects

Components and supplies

About this project

I got to use a potentiometer, which varies sresistance based on th twisting of knob and, in turn, changes the voltage being read by the analog input pin.

I will read the light value of the room and have an LED turn on if it is dark and turn off if it is bright.

As shown picture,

Using wires, I connected leds with resistors at breadboard.

Code

Redaing a photoresistorArduino
/*
  SparkFun Inventor's Kit
  Example sketch 07

  PHOTORESISTOR

  Read a photoresistor (light sensor) to detect "darkness" and turn on an LED when it
  is "dark" and turn back off again when it is "bright.

  This sketch was written by SparkFun Electronics,
  with lots of help from the Arduino community.
  This code is completely free for any use.
  Visit http://learn.sparkfun.com/products/2 for SIK information.
  Visit http://www.arduino.cc to learn about the Arduino.
*/


// As usual, we'll create constants to name the pins we're using.
// This will make it easier to follow the code below.

const int sensorPin = 0;
const int ledPin = 9;

// We'll also set up some global variables for the light level a calibration value and
//and a raw light value
int lightCal;
int lightVal;


void setup()
{
  // We'll set up the LED pin to be an output.
  pinMode(ledPin, OUTPUT);
  lightCal = analogRead(sensorPin);
  //we will take a single reading from the light sensor and store it in the lightCal
  //variable. This will give us a prelinary value to compare against in the loop
}


void loop()
{
  //Take a reading using analogRead() on sensor pin and store it in lightVal
  lightVal = analogRead(sensorPin);


  //if lightVal is less than our initial reading (lightCal) minus 50 it is dark and
  //turn pin 9 HIGH. The (-50) part of the statement sets the sensitivity. The smaller
  //the number the more sensitive the circuit will be to variances in light.
  if (lightVal < lightCal - 50)
  {
    digitalWrite(9, HIGH);
  }

  //else, it is bright, turn pin 9 LOW
  else
  {
    digitalWrite(9, LOW);
  }

}

Schematics

Redaing a photoresistor
555 bc0rol83ox

Comments

Similar projects you might like

Message Box Influence for Non-Disabled

Project in progress by 5 developers

  • 1,541 views
  • 0 comments
  • 8 respects

Turn On and Off LED by LDR (Toggle LDR)

Project showcase by muhammed amar slik

  • 51,824 views
  • 5 comments
  • 22 respects

Simulate GPS/Read Photoresistor with MKR1000/ADAFRUIT

Project showcase by Sebastian Hernandez and Juan Santana

  • 2,701 views
  • 0 comments
  • 10 respects

Arduino Traffic Light Simulator

Project tutorial by Zachary Haslam

  • 20,479 views
  • 10 comments
  • 46 respects

Ambient Light Sensor Using Photo Resistor and LED Lights!

Project tutorial by DCamino

  • 11,107 views
  • 9 comments
  • 22 respects

Photoresistor Characterization

by 3 developers

  • 5,792 views
  • 4 comments
  • 12 respects
Add projectSign up / Login