Difference between revisions of "Photo Cell Sensor"

From LinkSprite Playgound
Jump to: navigation, search
(Measuring Light)
(Usage)
Line 38: Line 38:
 
== Usage ==
 
== Usage ==
  
=== Hardware ===
+
=== Connecting a Photocell ===
  
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. 
+
Because photocells are basically resistors, they are non-polarized. That means you can connect them up 'either way' and they'll work just fine!
  
Using these data, you can make your own application according to your requirement.
+
[[File:installation.jpg | 400px]]
 +
 
 +
Photocells are pretty hardy, you can easily solder to them, clip the leads, plug them into breadboards, use alligator clips, etc. The only care you should take is to avoid bending the leads right at the epoxied sensor, as they could break off if flexed too often.
 +
 
 +
[[File:installation02.jpg]]
  
[[File:installation.jpg | 400px]]
+
=== Using a Photocell ===
  
=== Programming ===
+
'''Analog Voltage Reading Method'''
  
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 easiest way to measure a resistive sensor is to connect one end to Power and the other to a '''pull-down''' resistor to ground. Then the point between the fixed pulldown resistor and the variable photocell resistor is connected to the analog input of a microcontroller such as an Arduino (shown)
  
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.
+
[[File:anasch.jpg]]
  
<syntaxhighlight lang="c">
+
[[File:pulldowndiag.jpg]]
  
#include <math.h>
+
For this example I'm showing it with a 5V supply but note that you can use this with a 3.3v supply just as easily. In this configuration the analog voltage reading ranges from 0V (ground) to about 5V (or about the same as the power supply voltage).
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>
+
The way this works is that as the resistance of the photocell decreases, the total resistance of the photocell and the pulldown resistor decreases from over 600KΩ to 10KΩ. That means that the current flowing through both resistors increases which in turn causes the voltage across the fixed 10KΩ resistor to increase. Its quite a trick!

Revision as of 05:59, 13 December 2012

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

Graph.gif

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.

Cdsspectreturn.gif

Usage

Connecting a Photocell

Because photocells are basically resistors, they are non-polarized. That means you can connect them up 'either way' and they'll work just fine!

Installation.jpg

Photocells are pretty hardy, you can easily solder to them, clip the leads, plug them into breadboards, use alligator clips, etc. The only care you should take is to avoid bending the leads right at the epoxied sensor, as they could break off if flexed too often.

Installation02.jpg

Using a Photocell

Analog Voltage Reading Method

The easiest way to measure a resistive sensor is to connect one end to Power and the other to a pull-down resistor to ground. Then the point between the fixed pulldown resistor and the variable photocell resistor is connected to the analog input of a microcontroller such as an Arduino (shown)

File:Anasch.jpg

File:Pulldowndiag.jpg

For this example I'm showing it with a 5V supply but note that you can use this with a 3.3v supply just as easily. In this configuration the analog voltage reading ranges from 0V (ground) to about 5V (or about the same as the power supply voltage).

The way this works is that as the resistance of the photocell decreases, the total resistance of the photocell and the pulldown resistor decreases from over 600KΩ to 10KΩ. That means that the current flowing through both resistors increases which in turn causes the voltage across the fixed 10KΩ resistor to increase. Its quite a trick!