Photo Cell Sensor

From LinkSprite Playgound
Revision as of 05:37, 13 December 2012 by Katherine.d (talk | contribs)
Jump to: navigation, search

Introduction

Photocells are sensors that allow you to detect light. They are small, inexpensive, low-power, easy to use and don't wear out. For that reason they often appear in toys, gadgets and appliances. They are often referred to as CdS cells (they are made of Cadmium-Sulfide), light-dependent resistors (LDR), and photoresistors.

Photo cell.jpg

For most light-sentsitive applications like "is it light or dark out", "is there something in front of the sensor (that would block light)", "is there something interrupting a laser beam" (break-beam sensors), or "which of multiple sensors has the most light hitting it", photocells can be a good choice!

Photo cell-01.gif

Features

  • 2.54mm general interface
  • Wide supply voltage range: 3V–30V
  • 2.0cm x 2.0cm module
  • Application fields widely

Schematic

Specifications

  • Size: Round, 5mm (0.2") diameter. (Other photocells can get up to 12mm/0.4" diameter!)
  • Resistance range: 200KΩ (dark) to 10KΩ (10 lux brightness)
  • Sensitivity range: CdS cells respond to light between 400nm (violet) and 600nm (orange) wavelengths, peaking at about 520nm (green).
  • Power supply: pretty much anything up to 100V, uses less than 1mA of current on average (depends on power supply voltage)

Measuring Light

As we've said, a photocell's resistance changes as the face is exposed to more light. When its dark, the sensor looks like an large resistor up to 10MΩ, as the light level increases, the resistance goes down. This graph indicates approximately the resistance of the sensor at different light levels. Remember each photocell will be a little different so use this as a guide only

File:Graph.jpg

Note that the graph is not linear, its a log-log graph!

Photocells, particularly the common CdS cells that you're likely to find, are not sensitive to all light. In particular they tend to be sensitive to light between 700nm (red) and 500nm (green) light.

File:Cdsspectreturn.jpg

Usage

Hardware

Connect the module to the MCU the 2.54mm pitch pin header, then you can get a voltage value based on the light intensity of the environment.

Using these data, you can make your own application according to your requirement.

Installation.jpg

Programming

The program below uses the photo cell sensor to control the LED. As the picture shows above, the photo cell sensor is connected to analog port 0 and the LED is connected to port 12.

The resistance of the photoresistor which stands for light value can be calculated based on the voltage obtained through the analog port. Then you can use this data to control the LED or other thing you like.

<syntaxhighlight lang="c">

  1. include <math.h>

const int ledPin=12; //Connect the LED Grove module to Pin12, Digital 12 const int thresholdvalue=10; //The treshold for which the LED should turn on. Setting it lower will make it go on at more light, higher for more darkness

void setup() {

 Serial.begin(9600);                //Start the Serial connection
 pinMode(ledPin,OUTPUT);            //Set the LED on Digital 12 as an OUTPUT

} void loop() {

 int sensorValue = analogRead(0);
 float Rsensor;
 Rsensor=(float)(1023-sensorValue)*10/sensorValue;

 if(Rsensor>thresholdvalue)
 {
   digitalWrite(ledPin,HIGH);
 }
 else
 {
 digitalWrite(ledPin,LOW);
 }

 Serial.println(Rsensor,DEC);

}

</syntaxhighlight>