Led As Light Sensor.

I was watching videos on youtube today and I came across a video of an led being used as a light sensor. So I gave it a try and it all worked according to plan. So I thought I’d share the code. you connect the led + to analog pin 5 and the led- to ground. http://www.youtube.com/watch?v=S-uogFF-Ki4[/flash. heres the code.

/*
LED as light sensor
Created By Sean Jonson

Uses an IR LED (but it can be any kind)on analog pin 5 to turn off a regular LED on digital 13 when there is not much light on the LED.

The circut:
LED+ to analog pin 5
LED- to GND

A second LED+ to pin 13
A second LED- to GND

*/

int sensorPin = A5; // select the input pin for the LED
int ledPin = 13; // select the pin for the LED
float sensorValue = 0; // variable to store the value coming from the LED

void setup() {

pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT:
Serial.begin(9600); // begin the serial to the computer
}

void loop() {

sensorValue = analogRead(sensorPin); // read the value from the LED
Serial.println(sensorValue); // serialy print the value from the LED
if(sensorValue < 129){ // if the LED “see’s” less than 129 light, if you dont use the same LED im using you might want to tweek this number
digitalWrite(ledPin, HIGH); // turn on the light
}
else{
digitalWrite(ledPin, LOW); // turn it off
}

}

http://www.youtube.com/watch?v=S-uogFF-Ki4. there's a video of it in action. its not my video but its the one that I came across.

nice idea...who would have thought a led as light sensor...good post

thanks. :smiley: