Saturday, September 7, 2013

Photosensitive Sensor Module Testing

I got this from DX: MN-EB-PTCMN Photosensitive Sensor Module - Orange.


Basically a photocell, after some investigation I got some help from this site, the code showed here is

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
int photoRPin = 0; 
int minLight;
int maxLight;
int lightLevel;
int adjustedLightLevel;

void setup() {
 Serial.begin(9600);
 
 //Setup the starting light level limits
 lightLevel=analogRead(photoRPin);
 minLight=lightLevel-20;
 maxLight=lightLevel;
}

void loop(){
 //auto-adjust the minimum and maximum limits in real time
 lightLevel=analogRead(photoRPin);
 if(minLight>lightLevel){
 minLight=lightLevel;
 }
 if(maxLight<lightLevel){
 maxLight=lightLevel;
 }
 
 //Adjust the light level to produce a result between 0 and 100.
 adjustedLightLevel = map(lightLevel, minLight, maxLight, 0, 100); 
 
 //Send the adjusted Light level result to Serial port (processing)
 Serial.println(adjustedLightLevel);
 
 //slow down the transmission for effective Serial communication.
 delay(50);
}

This code is property of Scott please take a look at his site for more interesting posts.

Thanks to this excellent piece of code you get a reading from 0-100 of the light sensed. Cool to build on to another things.

Here's an image of the serial console of the reading.

Heres a basic of the circuit, basic 3 pins (ground, 5v, signal(this goes to analog 0 in arduino))


No comments:

Post a Comment