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. Hardware
  3. Rain Barrel Sensor

Rain Barrel Sensor

Scheduled Pinned Locked Moved Hardware
11 Posts 6 Posters 3.6k Views 6 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.
  • CrankyCoderC CrankyCoder

    I have made a sensor for my rain barrels using the distance sensor example using the newping library.

    However, my readings seem to be kind of back and forth. I have tried to do some smoothing using some averages and what not.

    Here is my current code. I am already looking at taking my smoothing code out and using the newping library option of taking multiple readings.

    void loop()      
    {     
      
      float dist[cycles];
      for (int x=0; x<cycles; x++)
      {
      
      dist[x] = metric?sonar.ping_cm():sonar.ping_in();  
      Serial.println(dist[x]);
      sleep(500);
      }
      float avgdist =0;
      //loop through all 3 iterations and average
      for (int x=0; x<cycles; x++)
      {
        avgdist=avgdist+dist[x];
      }
      avgdist = avgdist / cycles;
      Serial.print("Avg Dist");
      Serial.println(avgdist);
      Serial.print("Ping: ");
      Serial.print(avgdist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
      Serial.println(metric?" cm":" in");
      //set dist to avgdist
      float distval;
      distval=avgdist;
      
      if (distval != lastDist) {
          send(msg.set(String(distval)));
          lastDist = distval;
      }
    
      sleep(SLEEP_TIME);
    }
    

    So it works. But it seems that the values bounce around. Here is my graph

    alt text

    Ignore the big spike, that's when i took the sensor off to work on something and it thought my barrels were full.

    Just wondering if anyone else has any recommendations on how often you take readings ect.

    I am also debating on switching to a 1 hour reading, and have an interrupt fire from a rain tip sensor when it starts raining that tells it to take readings more frequently when it's actually raining.

    YveauxY Offline
    YveauxY Offline
    Yveaux
    Mod
    wrote on last edited by Yveaux
    #2

    @CrankyCoder I have no experience with ultrasonic distance measurement, but looking at your chart the averaged resolution seems to be 2.5cm/inch (the smallest discrete step in your data. Can't tell if you're plotting imperial or metric).
    If you're averaging over 3 samples (that's what the comment in the code suggests) the raw resolution of the sensor is 7.5cm/inch.

    The 'jumping' up and down is probably just noise on your measurement data.
    I'm afraid you can't expect to get any more accuracy out of this setup.

    http://yveaux.blogspot.nl

    1 Reply Last reply
    0
    • wallyllamaW Offline
      wallyllamaW Offline
      wallyllama
      wrote on last edited by
      #3

      There is another tread on measuring water levels in a tank, and it uses a distance sensor also, I'm curious if either project considered a capacative sensor? It needs two conductors (copper tape is good) and would work much like a touch sensor. If so what was the reason for rejecting it?

      1 Reply Last reply
      0
      • CrankyCoderC Offline
        CrankyCoderC Offline
        CrankyCoder
        wrote on last edited by
        #4

        I considered the the capacitive but working inside the barrels wasn't something I was up for. was definitely a consideration

        Home Automation Tinkerer
        www.CrankyCoder.net

        Controller: HomeAssistant in Kubernetes
        Gateway: MQTTClientGateway
        MySensors: 2.3

        1 Reply Last reply
        0
        • wallyllamaW Offline
          wallyllamaW Offline
          wallyllama
          wrote on last edited by
          #5

          Maybe i dont remember how they work, but i thought the strips went on the outside. I dont want to change your project, I'm just curious because I want to a similar thing for water tanks on my camper/caravan.

          1 Reply Last reply
          0
          • CrankyCoderC CrankyCoder

            I have made a sensor for my rain barrels using the distance sensor example using the newping library.

            However, my readings seem to be kind of back and forth. I have tried to do some smoothing using some averages and what not.

            Here is my current code. I am already looking at taking my smoothing code out and using the newping library option of taking multiple readings.

            void loop()      
            {     
              
              float dist[cycles];
              for (int x=0; x<cycles; x++)
              {
              
              dist[x] = metric?sonar.ping_cm():sonar.ping_in();  
              Serial.println(dist[x]);
              sleep(500);
              }
              float avgdist =0;
              //loop through all 3 iterations and average
              for (int x=0; x<cycles; x++)
              {
                avgdist=avgdist+dist[x];
              }
              avgdist = avgdist / cycles;
              Serial.print("Avg Dist");
              Serial.println(avgdist);
              Serial.print("Ping: ");
              Serial.print(avgdist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
              Serial.println(metric?" cm":" in");
              //set dist to avgdist
              float distval;
              distval=avgdist;
              
              if (distval != lastDist) {
                  send(msg.set(String(distval)));
                  lastDist = distval;
              }
            
              sleep(SLEEP_TIME);
            }
            

            So it works. But it seems that the values bounce around. Here is my graph

            alt text

            Ignore the big spike, that's when i took the sensor off to work on something and it thought my barrels were full.

            Just wondering if anyone else has any recommendations on how often you take readings ect.

            I am also debating on switching to a 1 hour reading, and have an interrupt fire from a rain tip sensor when it starts raining that tells it to take readings more frequently when it's actually raining.

            Boots33B Offline
            Boots33B Offline
            Boots33
            Hero Member
            wrote on last edited by
            #6

            @CrankyCoder Averaging the readings may not give very good results when using ultrasonic sensors. You will be better to try newpings built in median filter. I have used it in this water tank level and have found it to be ok for my tank.

            CrankyCoderC 1 Reply Last reply
            0
            • gohanG Offline
              gohanG Offline
              gohan
              Mod
              wrote on last edited by
              #7

              There was a project that used a waterproof sensor in a round water tank and it seemed quite accurate in the measurements

              1 Reply Last reply
              0
              • Boots33B Boots33

                @CrankyCoder Averaging the readings may not give very good results when using ultrasonic sensors. You will be better to try newpings built in median filter. I have used it in this water tank level and have found it to be ok for my tank.

                CrankyCoderC Offline
                CrankyCoderC Offline
                CrankyCoder
                wrote on last edited by
                #8

                @Boots33 I have an updated version of the firmware that will remove my "smoothing" stuff in favor of the newping's built in stuff. Looks like one of the versions of your code you are polling every 15 seconds. That still your interval? As soon as I update my firmware I will post back if the built in median stuff works better :)

                Home Automation Tinkerer
                www.CrankyCoder.net

                Controller: HomeAssistant in Kubernetes
                Gateway: MQTTClientGateway
                MySensors: 2.3

                Boots33B 1 Reply Last reply
                0
                • bjacobseB Offline
                  bjacobseB Offline
                  bjacobse
                  wrote on last edited by
                  #9

                  I have at some point also been using a ping with sr-hc04, I dont have the actual code here, but as I remember, I ping until i get 3 results in a row which are identical. Instead of ping 3 times and make an average.

                  CrankyCoderC 1 Reply Last reply
                  0
                  • bjacobseB bjacobse

                    I have at some point also been using a ping with sr-hc04, I dont have the actual code here, but as I remember, I ping until i get 3 results in a row which are identical. Instead of ping 3 times and make an average.

                    CrankyCoderC Offline
                    CrankyCoderC Offline
                    CrankyCoder
                    wrote on last edited by
                    #10

                    @bjacobse interesting approach and seems totally valid. Ill have to play with that idea too

                    Home Automation Tinkerer
                    www.CrankyCoder.net

                    Controller: HomeAssistant in Kubernetes
                    Gateway: MQTTClientGateway
                    MySensors: 2.3

                    1 Reply Last reply
                    0
                    • CrankyCoderC CrankyCoder

                      @Boots33 I have an updated version of the firmware that will remove my "smoothing" stuff in favor of the newping's built in stuff. Looks like one of the versions of your code you are polling every 15 seconds. That still your interval? As soon as I update my firmware I will post back if the built in median stuff works better :)

                      Boots33B Offline
                      Boots33B Offline
                      Boots33
                      Hero Member
                      wrote on last edited by
                      #11

                      @CrankyCoder said in Rain Barrel Sensor:

                      Looks like one of the versions of your code you are polling every 15 seconds. That still your interval?

                      Yes I poll every 15 seconds and update only if there is a change, then every 15min i poll and post the results regardless of he result. This keeps the node showing as live in domoticz. I also only use the percentage as the trigger for a level change, this allows for a bit of variation before a change is recorded.

                      You can see in the graph for the last 24hrs that it remains static.

                      0_1494447984160_Screenshot (12).jpg

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


                      21

                      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