Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Rounding sensor values

Rounding sensor values

Scheduled Pinned Locked Moved Development
5 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Dan S.D Offline
    Dan S.D Offline
    Dan S.
    Hero Member
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • greglG Offline
      greglG Offline
      gregl
      Hero Member
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      0
      • Dan S.D Offline
        Dan S.D Offline
        Dan S.
        Hero Member
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        1
        • Dan S.D Offline
          Dan S.D Offline
          Dan S.
          Hero Member
          wrote on last edited by
          #4

          oops! found an error in my code. Will repost after thoroughly debugging this time. Sorry!

          1 Reply Last reply
          0
          • Dan S.D Offline
            Dan S.D Offline
            Dan S.
            Hero Member
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            23

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            Posts


            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular