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.
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
Saving last known good state, but not in EEPROM
Development • 30 Jan 2024, 18:46 • OldSurferDude 15 Jan 2025, 08:51 -
PJON and Minicore not working
Development • 22 days ago • Trand 22 days ago -
Sending offset to node
Development • 31 Jan 2025, 00:59 • bsl88k 4 Feb 2025, 12:14 -
Radio waking up for no reason.
Development • 4 Jul 2020, 21:09 • Sasquatch 15 Jan 2025, 08:33 -
Home Assistant/MySensors quirks
Development • 27 days ago • OldSurferDude 27 days ago