Lesson 21 Photoresistor Sensor

Share for us

Introduction

The sensor is in fact a photoresistor which changes its resistance with varying light intensity. It can be used to make a photoswitch.

Components

– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * Photoresistor sensor module

– Jumper wires

Experimental Principle

A photoresistor or light-dependent resistor (LDR) 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.

In this experiment, hook up pin S to an analog port of the SunFounder board. When the light intensity changes, the resistance of photoresistor will change accordingly. Thus it will also change the output voltage of pin S. You can read the output voltage and display it on an LCD to observe this change.

Experimental Procedures

Step 1: Build the circuit

     Photoresistor Sensor Module          SunFounder Uno

                                    S ———————————————- A0

                                  –  ———————————————– GND

                                  + ————————————————- 5V

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno

Now, cover the photoresistor with a cloth or your palm to change the light intensity, and you will find the value displayed on the LCD changes accordingly.

Code

/*************************************************/
#include <LiquidCrystal.h>
const int photocellPin = A0;
const int ledPin = 13;
LiquidCrystal lcd(4, 5,9, 10, 11, 12);int outputValue = 0;
/*************************************************/
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}
/*************************************************/
void loop()
{
outputValue = analogRead(photocellPin);
lcd.setCursor(0, 0);
lcd.print(“Photocell:”);
lcd.setCursor(11, 0);
lcd.print(outputValue);//print the temperature on lcd1602
Serial.println(outputValue);
delay(1000);
lcd.setCursor(11, 0);
lcd.print(” “);
}
/*************************************************/