HC-SR04 always shows 0 or a huge number

  • HC-SR04

Why it happens

  • TRIG and ECHO are swapped.
  • Nothing is in range, or the object is soft or slanted.
  • The sensor isn't getting 5 V.

How to fix it

  1. Match TRIG and ECHO to the pin numbers in the code.
  2. Point it at a flat wall 20 to 100 cm away.
  3. Connect VCC to 5V, not 3.3V, on an Uno.
  4. Stay beyond 2 cm: nearer than that it can't hear.
  5. Add delay(60); between pings.

It worked if: Move a book nearer and farther: the number follows.

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.