About johnmycroft

Nov. 18, 2015
Full Profile »

Tell us about yourself!

Complete Your Profile
  • johnmycroft commented on appleman123987's instructable Hc-sr04 Ultrasonic Distance Sensor10 months ago
    Hc-sr04 Ultrasonic Distance Sensor

    Thanks for the info here, especially NewPing - much easier to understand than the original library. I do have a problem though when the sensor is out of range, as do a number of my students, using both the old library and NewPing. Most of the time (maybe 80% of the time), I correctly get a distance of 0 cm as per the example NewPing code but 20% of the time with nothing going on or getting in the way, the sketch reports a distance of 4cm and then returns to 0 cm on the next ping. I've tried changing Arduino pins and various delays to no avail. Any idea what causes this behavior? I don't have anything except the SR04 in my circuit (no LED). I also set my serial monitor speed to 9600 in case it was swamping the Arduino.void loop() {int uS = sonar.ping(); Serial.print("Ping: "); Serial.print(uS / US_ROUNDTRIP_CM); Serial.println("cm");delay(550);}

    View Instructable »