Ambient Light sensor using an Op-Amp Comparator22 May 2013
Say you have a microcontroller circuit that does something when it goes dark. To save power, you want to put the chip to sleep when the ambient light drops below a certain level. One way to do this is using an LDR and an op-amp comparator.
Here is the schematic:
In the above circuit, the reference voltage at the non-inverting terminal of the op-amp is VCC/2. When it's dark, the LDR has a high resistance (over 20K), and the voltage at the inverting terminal (pin 3) is going to be less than VCC/2. Hence, the output of the op-amp will go to high when it is dark. When sufficient light falls on the LDR, its resistance falls, and the voltage at the inverting terminal (pin 2) exceeds VCC/2. At this point, the op-amp output goes low. We can control the threshold at which it goes from low to high by adjusting the potentiometer R1.
Here is what the circuit looks like on a breadboard. The supply is 5V regulated.
In this case, I am using the LM358 - a very popular general-purpose Op-Amp IC. This works fine for our purpose, but do note that there are dedicated comparator ICs with better switching characteristics for critical applications.
In my next post, I will describe how to hook this up to an ATmega168 and wake it up from power-save mode.