Distance sensor messure strange values



  • Hi there ,
    I have built a distance sensor to measure the level of my rainwater tank. I built it with an Arduino Nano. I use an Arduino Nano as a serial gateway as well.
    The communication between the two work well. The values in my controler (FHEM) are visible.
    The main problem is strange values, I get.
    The values jump between 0 and 400, even if the distance changes to the sensor head.

    I attache a out put from the serial console.
    Don't worry about the fail. The sensor has currently no contact to it's gateway. But this is no the reason for the stange behaviour.

    Ping: 386 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:386
    Ping: 390 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:390
    Ping: 391 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:391
    Ping: 393 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:393
    send: 100-100-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    Ping: 0 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:0
    Ping: 0 cm
    Ping: 34 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:34
    Ping: 395 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:395
    Ping: 398 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:398
    Ping: 393 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:393
    Ping: 393 cm
    Ping: 0 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:0
    Ping: 0 cm
    Ping: 250 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:250
    send: 100-100-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    Ping: 0 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:0
    Ping: 0 cm
    Ping: 34 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:34
    Ping: 395 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:395
    Ping: 390 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:390
    Ping: 395 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:395
    Ping: 396 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:396
    Ping: 394 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:394
    send: 100-100-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    Ping: 0 cm
    send: 100-100-0-0 s=1,c=1,t=13,pt=2,l=2,st=fail:0



  • Oh, I forgot to mention that I use a DYP-ME007Y Ultrasonic Sensor Module.

    Th


  • Contest Winner

    @crazy_penguin

    post your code... let's see what kind of hysteresis you are using and how frequently you are measuring.

    it's hard to see from the values without knowing the timing of the program you are using



  • Hi BulldogLowell,

    sorry for the delay I was over 2 weeks on vacation. but now I am back.

    I using the code from the distance sensore example (http://www.mysensors.org/build/distance).

    #include <SPI.h>
    #include <MySensor.h>  
    #include <NewPing.h>
    
    #define CHILD_ID 1
    #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
    
    MySensor gw;
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    MyMessage msg(CHILD_ID, V_DISTANCE);
    int lastDist;
    boolean metric = true; 
    
    void setup()  
    { 
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Distance Sensor", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID, S_DISTANCE);
      boolean metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {     
      int dist = metric?sonar.ping_cm():sonar.ping_in();
      Serial.print("Ping: ");
      Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
      Serial.println(metric?" cm":" in");
    
      if (dist != lastDist) {
          gw.send(msg.set(dist));
          lastDist = dist;
      }
    
      gw.sleep(SLEEP_TIME);
    }
    
    

  • Hero Member

    @crazy_penguin is it battery powered?



  • No.
    It is powerd with a 5V and 2A powersupply.


  • Hero Member

    @crazy_penguin you can see all the failed transmissions. it might have to do with using the nrf and sensor at the same time? can you try it without the mysensor part? just clean arduino sketch?



  • Hi Moshe Livne,

    I disconnect the radio device and keep the US-sensor connected and use the following code.

    #include <NewPing.h>
    
    #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE 500 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    
    void setup() {
      Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    }
    
    void loop() {
      delay(500);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
      unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
      Serial.print("Ping: ");
      Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
      Serial.println("cm");
    }
    

    I got the following results:

    Ping: 306cm
    Ping: 0cm
    Ping: 308cm
    Ping: 0cm
    Ping: 308cm
    Ping: 0cm
    Ping: 308cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm
    Ping: 0cm
    Ping: 307cm



  • Hi all,

    I am really wondering whats going wrong here. I made some changes to the code and now I get this result:

    Ping: cm
    Ping: 0cm
    Ping: 0cm
    Ping: 0cm
    Ping: 2cm
    Ping: 0cm
    Ping: 0cm
    Ping: 0cm
    Ping: 1cm
    Ping: 0cm
    Ping: 0cm
    Ping: 0cm
    Ping: 0cm
    Ping: 0cm
    Ping: 0cm
    Ping: 16cm
    Ping: 0cm
    Ping: 0cm
    Ping: 0cm

    The distance between sensor and wall is about 75cm.

    I took back any chagnes I made. Without any effect.
    I try now use the NewPing version 1.6 library. No effect.

    Current code:

    #include <NewPing.h>
    
    #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE 500 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    
    void setup() {
      Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    }
    
    void loop() {
      delay(2000);                    // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
      Serial.print("Ping: ");
      Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
      Serial.println("cm");
    }
    

    I there any way to check I the hardware is bad or may have some defects?

    Front.jpg
    Rear.jpg


  • Hero Member

    @crazy_penguin can you please try to point the sensor straight at the wall (not down) and clear anything from the sides? you might get echoes. but this is a bit far fetched. mine is this one http://www.aliexpress.com/item/Free-shipping-1pcs-Ultrasonic-Module-HC-SR04-Distance-Measuring-Transducer-Sensor-for-Arduino-Samples-Best-prices/1967936408.html?aff_platform=aaf&aff_trace_key=34543821268212384&sk=bUBEAqbMv%3A&cpt=1435219216767
    it works reasonably reliably



  • @Moshe Livne I order the HC-SR04 Module as well to make sure where the problem is.
    I also order aother Arduino Nano.


  • Admin

    @crazy_penguin

    Your module (on the pictures) looks really strange. What type is it?



  • @hek DYP-ME007Y


  • Admin



  • @hek Thanks. I will check out this and will tell you the result.



  • OK. this threat (http://forum.arduino.cc/index.php?topic=153700.0) is very usefull. I will try out some hints and tell you my result.

    Thank to all for now.



  • Hi there,
    it's me again.

    I tried some things which read in the arduino froum (http://forum.arduino.cc/index.php?topic=153700.0) without any good result.
    I also get a new sensor and there is still no change of it's behaviour.

    I read in the forum that it could be a sensor that uses RX/TX to send its information.
    Does any one know something about that?


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 10
  • 24
  • 3
  • 4

35
Online

11.2k
Users

11.1k
Topics

112.5k
Posts