There are many photodetectors. From simple photoresistors (which are very slow), through photodiodes (which are also slow too) ending on phototransistors (expensive, fast), but did you know that LEDs can act as photodetector as well?
If you illuminate the LED with a laser that has matching color of the LED, then a voltage will be induced on anode and cathode. When we measure it, it turns out that the voltage is exactly Forward Voltage. (which is about 1.3V in this case)
Surprised? You shouldn’t. Way it works is exactly the same as the way like in other photodetectors. It uses photovoltanic effect. Speaking shortly – if you illuminate surface of an exposed semiconductor, then there is a chance that electricity will be induced; the light is absorbed, causing electrons to “jump” into higher energy state thus creating electricity.
LEDs are a lot faster than photoresistors and photodiodes, they can be used as a tachometer. You will need an detector circuit to amplify the voltage induced on LED, as most microcontrollers or SBUs (like Raspberry Pi) won’t read pulses from the LED. We need about 2/3 of 3.3V for logic “1” which is the voltage that RPi runs on and to have logic “0” we need 1.3 of 3.3V which is 1.1V. Anything in between those voltages is indeterminable state. It can be read either “0” or “1” depending on device and circumstances.
In my case it is an op amp which amplifies the voltage from LED two times and a quad NAND gate, where first gate acts as ordinary NAND (IC1A) gate and second gate acts as NOT (IC1B) gate. This way I am sure that logic “1” will be 3.3V and logic “0” will be about 0.5V. Ignore LED2 as it was added just for test.
To calculate speed in RPM of a fan, we need to measure frequency of impulses from our LED. In my case it is about 101Hz. My fan has 7 blades which means that for every full rotation there will be 7 interruptions. We have to divide our base frequency by 7 which equals to about 14Hz. There is 60 seconds in a minute, so we multiply last value by 60 and we get 840RPM.
Conclusions? LEDs are suprisingly good photodetectors, which are sensitive to specific light, comparing to photoresistors or photodiodes. They react to any light unless you use an light filter.
Sources:
https://en.wikipedia.org/wiki/Photovoltaic_effect
https://www.khanacademy.org/science/physics/quantum-physics/photons/a/photoelectric-effect