hc sr04 sensor get stuck at zero.

Issue #3 resolved
mehmet zahit baş created an issue

The sensor get stuck at zero when aimed too far away or too close. It keeps listening in the echo pin for a pulse it will not get.

Comments (6)

  1. Tim Eckel repo owner

    This is not an issue with NewPing. It's with a batch of defective sensors that's been going around. A properly working sensor doesn't get stuck when pointed out of range.

  2. mehmet zahit baş reporter

    I understand. Thank you for your fast reply. Your library is amazing. It has made my work a lot easier. Keep up the good work.

  3. Tim Eckel repo owner

    If you have a sensor that gets stuck like that, my suggestion is to only change the echo mode if the distance is zero. Something like this:

    if (cm==0) {
      pinMode(echoPin, OUTPUT);
      digitalWrite(echoPin, LOW);
      pinMode(echoPin, INPUT);
    }
    

    You may also need some type of delay in that IF statement. Doing this in the library wouldn't be ideal. So, if you do have a defective sensor that gets stuck at 0 adding something like this after each ping is probably the best solution (other than getting another sensor).

  4. Log in to comment