I have a problem in calibration an LDR sensor. I want to let the sensor goes all day long and I'm using the LDR sensor as a presence sensor. The calibration values (min and max) changes all the day, and I need to detect only the peaks, or continuously change the min and the max values. Are there some defined pattern or algorithms to use?
In this situation, it may be useful to look at the differential of the signal.
One way to do this is to store the value, wait some time and read another value. You can then do:
dv = current_value - last_value
Or if you have some time metric (Perhaps clock ticks, or a rtc):
dv = (current_value - last_value) / (current_time - last_time)
You would then want to only count significantly large changes in
dv. As the day progresses the light value will only change at a small rate but if someone were to block the light then there will be a large difference between
dv to be largely negative (Indicating a loss of a lot of light) and when they no longer block the light you will get the opposite, indicating there is no longer an obstruction. (Or rather, less of an obstruction.)