Rain Barrel Sensor



  • 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.


  • Mod

    @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.



  • 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?



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



  • 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.


  • Hero Member

    @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.


  • Mod

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



  • @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 :)



  • 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.



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


  • Hero Member

    @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


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.