Difference between revisions of "Photo Cell Sensor"

From LinkSprite Playgound
Jump to: navigation, search
(Hardware)
Line 47: Line 47:
 
Using these data, you can make your own application according to your requirement.
 
Using these data, you can make your own application according to your requirement.
  
[[File:installation.jpg]]
+
[[File:installation.jpg | 400px]]
  
 
=== Programming ===
 
=== Programming ===

Revision as of 09:57, 6 December 2012

Introduction

This photo cell sensor module uses the GL5528 photoresistor to detect the light intensity of environment. An Op-amp LM358 is configured as a “voltage follower” to decease influence of resistance variation when light intensity changes.

Features

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

Schematic

Photo cell sensor schematic.jpg

Specifications

Key specification

Items Min
PCB Size 2.0cm*2.0cm
Interface 2.54mm pitch pin header
IO structure SIG,VCC,GND,NC
VCC 3~30V Type:5V
Supply current 0.5~3mA

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>