Rounding sensor values
-
I noticed my light sensor was very sensitive and tended to report sensor values back to the gateway much more frequently than I needed. So I added an Excel Ceiling function (rounds up a number to a specified roundup value) to my sketch. For my light sensor, I was only interested in changes of light values greater than 10. So after adding the function I only get light values to the nearest 10 points, e.g., 30, 40 etc. This really cuts down on reporting of insignificant light level changes to the gateway (which would be especially important on battery power). Will provide the code if any interest.
-
@Dan-S. said:
porting of insignificant light level changes to the gateway (which would be especially important on battery power). Will provide the code if any interest.
Hey @Dan-S. I would be interested in seeing the code - so yes pls!
Have you seen used the MAP function in arduino?
http://arduino.cc/en/reference/map
I think it might do the same as what you are wanting to do....Cheers,
Greg
-
This post is deleted!
-
oops! found an error in my code. Will repost after thoroughly debugging this time. Sorry!
-
OK another try:
here's the rounding (up) function, to be placed after the loop function in the sketch:
int Ceiling(int input, int ceilTo)
//input is the integer number to be rounded
//ceilTo is the desired rounding (up) value
{if ((input % ceilTo) != 0) { return ((int)(input / ceilTo) * ceilTo) + ceilTo; } else { return (input); } }
After the sensor input is read in the sketch, e.g. light level, insert the line
lightLevel = Ceiling(lightLevel,10);
Rounds all light level values upwards to the nearest 10. Depending on your rounding value, this will reduce the number of times the sensor sends an update to the gateway since updates are only sent when the value is different from the one previously sent.