Photoresistor Sensor With Arduino Uno R3

About: PrimeRobotics is a E-Commerce site, which focus on supplying right products to Electronics Hobbyists, Enthusiast & Students.

A photoresistor or photocell is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Components Required

Step 2: Principle

The resistance of the photoresistor changes with incident light intensity. If the incident light intensity is high, the resistance reduces; if low, increases.

In this experiment, we will use eight LEDs to indicate light intensity. The higher the light intensity is, the more the LED is lit. When the light intensity is high enough, all the LEDs will be lit. When there is no light, all the LEDs will go out.

Step 3: Schematic Diagram

Step 4: Procedures

Step1:

Build the Circuit

Step 2:

Download the code from https://github.com/primerobotics/Arduino

Step 3:

Upload the sketch to the Arduino Uno board

Click the Upload icon to upload the code to the control board. If "Done uploading" appears at the bottom of the window, it means the sketch has been successfully uploaded.

Now, if you shine the photoresistor with a certain light intensity, you will see several LEDs light up. If you increase the light intensity, you will see more LEDs light up. When you place it in dark environment, all the LEDs will go out.

Step 5: Code

/************************************

* name:Photoresistor

* function: if you shine the photoresistor with a certain light intensity, you will see several LEDs light up.

* If you increase the light intensity, you will see more LEDs light up.

* When you place it in dark environment, all the LEDs will go out.

*********************************************

/Email: info@primerobotics.in

//Website: www.primerobotics.in

const int NbrLEDs = 8;//8 leds

const int ledPins[] = {5, 6, 7, 8, 9, 10, 11, 12};//8 leds attach to pin 5-12 respectively

const int photocellPin = A0; //photoresistor attach to A0

int sensorValue = 0; // value read from the sensor

int ledLevel = 0; // sensor value converted into LED 'bars'

void setup()

{

for (int led = 0; led < NbrLEDs; led++)

{

pinMode(ledPins[led], OUTPUT);// make all the LED pins outputs

}

}

void loop()

{

sensorValue = analogRead(photocellPin); //read the value of A0

ledLevel = map(sensorValue, 300, 1023, 0, NbrLEDs); // map to the number of LEDs

for (int led = 0; led < NbrLEDs; led++)//

{

if (led < ledLevel ) //When led is smaller than ledLevel, run the following code.

{

digitalWrite(ledPins[led], HIGH); // turn on pins less than the level

}

else

{

digitalWrite(ledPins[led],LOW); // turn off pins higher than

}

}

}

Step 6:

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions