NewPing - newest version used with JSNSR04T V2.0 shows instable values

Issue #51 closed
Former user created an issue

First of all thank you very much for the NewPing.h. It has significantely improved the measurements to real values!!!!

But testing on the monitor shows drops to "0" and then back again to normal. Same behavior is encountert if using these lines to do the ultrasonic code. Forums state, that 10 microseconds are the issue and you need to change to 20. And really that works fine!

digitalWrite(Trig, HIGH); delayMicroseconds(20); // Multiple forum, proofing to set dealy to 20 microsec digitalWrite(Trig, LOW);

Can you let me know please, if you are using 10 or 20 inside NewPing.h?

Thank you for your answer and eventually a new library version.

Manfred

Comments (7)

  1. Tim Eckel repo owner

    “Forums state” is not supporting documentation. Give actual links.

    The bug would be with your sensor firmware, as all distance sensors should trigger with a max of 10 microseconds.

  2. rinie

    i’ve the same problem,

    For me is the next solution a good one::

    if (afstand>20) {lcd.print(365 - afstand );lcd.print(", kuub: ");
    }
    }

    so if the unit saYS 0️⃣ it will be ignored, maybe it 'll help you!

  3. Matias Vidal

    I had the same problem, I could not use the library. If I trigger for 10 microseconds i got unstable results

    I ended triggering the sensor manually and now works ok:

    int getDistance()
    {
      digitalWrite(TRIGGER_PIN, LOW);
      wait(20);
     // Trigger the sensor by setting the trigPin high for 20 microseconds:
      digitalWrite(TRIGGER_PIN, HIGH);
      delayMicroseconds(20);
      digitalWrite(TRIGGER_PIN, LOW);
    
      // Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
      long duration = pulseIn(ECHO_PIN, HIGH);
    
      // Calculate the distance:
      return (int)(duration*0.034/2) ;
    
    }
    

  4. Juergen Opschroef

    Hello, I can confirm the behaviour. It would be good if the trigger time could be initialised using the constructor.

    Cheers

    Juergen

  5. Ralf Lehmann

    Hi, I found the same and think that with 30 micro seconds it is even more stable.

    Unfortunately it triggers the wotchdog from time to time on an esp32. I know that it is currently not released for esp32 but I like the library and it works. I searched the internet and currently the following code is working on an esp32 “without” watchdog resets and with 30 micros trigger impulse.

    This is in NewPing.cpp. The watchdog code is from an ESP32 forum

    #if defined ESP_PLATFORM
    #include "soc/timer_group_struct.h"
    #include "soc/timer_group_reg.h"
    void feedTheDog(){
      // feed dog 0
      TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE; // write enable
      TIMERG0.wdt_feed=1;                       // feed dog
      TIMERG0.wdt_wprotect=0;                   // write protect
      // feed dog 1
      TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE; // write enable
      TIMERG1.wdt_feed=1;                       // feed dog
      TIMERG1.wdt_wprotect=0;                   // write protect
    }
    #endif
    
    // this is the trigger code snippet
        delayMicroseconds(10);            // Wait long enough for the sensor to realize the trigger pin is high. Sensor specs say to wait 10uS.
        feedTheDog();
        delayMicroseconds(10); 
        feedTheDog();
        delayMicroseconds(10);
    

    Cheers Ralf

  6. Log in to comment