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 current_value and last_value, causing 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.)

| improve this answer | |
  • yes I came at this solution too – nkint Dec 2 '14 at 18:38
  • Anyway, cool. Where to find some more documentation and algorithm about this kind of simple signal processing things in C? – nkint Dec 3 '14 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.