I am clearing out my old files. Most 25 year old projects are no longer relevant, technology marches on and old parts disappear. I did find this in the "stupid LED tricks" file and thought it might be interesting. It was popular 25 years ago but I haven't seen it lately.
It uses the LED junction capacitance and photoelectric effect to measure light intensity. The LED is reverse biased which pulls the charge carriers away from the junction into the bulk P and N materials. The cathode is then grounded and the anode voltage monitored. As the charges drift back to the junction the anode voltage drops and as it passes the digital threshold voltage the reading changes from 1 to 0. If the junction is illuminated with high enough energy light (more on that later) electrons will be released which will speed up the recovery time.
The Led is then forward biased (normal use) for a time based on the recovery time. In this case longer for less light.
Due to the differences in LEDs and digital thresholds it is probably not useful beyond a demo. It may be an interesting middle school science project. Trying different LED colors for the sensor and source. Hint: a red LED illuminating a blue one won't do much. The opposite will work. Why?
Spoiler alert: The illuminating light must be the same or shorter wavelength (higher energy) than the color emitted by the LED. Search photoelectric effect. Einstein's only Nobel prize was for explaining it.
/*
* Led Sense
*
* Use Led as light detector
* Reverse bias led which will charge the junction capacitance.
* Then determine time for recovery from reverse bias.
* This will be the time for carrier recombination which is
* light dependent - more light will speed recombination
*
* Use the result to light the LED for a time based on the light level
*
*/
// connect an LED with 1K series resistor across these pins. The resistor can be on
// either the anode or cathode side.
const int ledCathode = 6;
const int ledAnode = 7;
void setup() // run once, when the sketch starts
{
pinMode(ledAnode, OUTPUT);
pinMode(ledCathode, OUTPUT);
Serial.begin(115200);
}
void loop() // run over and over again
{
unsigned long int startTime,recoverTime;
// reverse bias the led
digitalWrite(ledCathode, HIGH);
digitalWrite(ledAnode, LOW);
delay(200); // wait for charge time
// Measure recovery time
pinMode(ledCathode, INPUT); // set to input
digitalWrite(ledCathode, LOW); // ground reference
startTime = micros();
do ;
// nothing
while (digitalRead(ledCathode) == 1); // wait for charge to leak off
recoverTime = micros() - startTime;
Serial.println(recoverTime);
// turn led on based on light level
pinMode(ledCathode, OUTPUT);
digitalWrite(ledCathode, LOW); // forward bias the led
digitalWrite(ledAnode, HIGH);
delay(recoverTime/50); // on longer in dark - 50 is juat to adjust the time modify to suit
digitalWrite(ledAnode, LOW); // turn off Led
// delay(1000); // waits for a second
}