Ultrasonic readings jump about

  • HC-SR04

Why it happens

  • Echoes from nearby things.
  • Readings too close together.
  • Noise from a motor or servo on the same 5 V.

How to fix it

  1. Leave 60 ms between readings.
  2. Take five readings and use the middle one.
  3. Lift the sensor off the table and keep its front clear.
  4. Power motors and servos separately, with the grounds joined.

It worked if: With a still wall the number changes by about a centimetre or less.

From how the part works. Explained from how the part works; not tried on a real circuit for this page.

Didn't help? Search another error or ask us.