Chat freely about anything...

User avatar
By PatrykW
#77977 Hey guys. I'm working on a little project here and I'm running into issues with handling data from a light sensor.
I need a way for the microcontroller to know when it's really dark and when it isn't. Sort of like in a regular light switch you use for your driveway lights.
Now, the issue is that that without some data filtering, stuff like a passing car at night, a fly landing on the sensor during the day etc. will full the thing.
At the moment I'm loading 60 readings into an array, once every second, and then I'm counting how many "dark" readings I got, but that doesn't seem very efficient as far as memory goes. Anyone has a better way?
User avatar
By btidey
#78024 If you are reading analog value of the sensor at regular intervals and then thresholding it then you could put a simple rolling average filter in before the thresholding.

E.g.

cValue = cValue * 15 / 16 + analogRead(0) / 16;

You can vary the proportions to trade-off smoothing against response time.