So I have been wanting to try this out for a while now and I finally got around to doing it this weekend.
Due to the semiconductor properties of LEDs they are capable of detecting light in the same or close to the wavelength they would normally emit. This allows you to use LEDs as a light sensor. Using an Arduino Mega and its analog input pins I was able to make this little circuit which exploits this property. The voltage that is produced is quite small so the accuracy and resolution is not very hight, but it does work quite well.
What it does:
I then hooked up another lead of my RGB-LEDs to a pwm output and made the LED light up according to how much light it is sensing. This allows for some interaction with the circuit instead of just looking at numbers on the screen.
Keep in mind, this was just a quick weekend project, so the code and the circuit are not very elegant or anything.
How the code works:
- Configure all analog inputs to outputs and pull low to turn on all red LEDs.
- Turn one analog input pin into an actual Input and read the amount of light that is reflected into it.
- Turn that input back into an output and continue on to next.
- After all inputs have been read adjust the PWM of the blue LEDs according to the amount of light that was measured.
- loop forever…
Here is a short clip demonstrating how it works. Please excuse the flickering. This is due to the LEDs being switched on and off constantly and that interfering with the exposure time of the camera. Also I didn’t realize one of the LEDs wasnt working: