My HC-SR04 has an issue

I am a 14 year old and it is the first time for me on the arduino forum I am new to arduino and got a HC-SR04 for a school project. it worked fine and showed the correct distance on an I2c 16*2 display , but the second time i tested it , it showed the distance as 4cm or 5cm even if there was nothing kept in front of it. The correct distance is shown when the object is closer than 5 cm(approx). Please help me out

Sujan

Arduino library - enjoyneering/HCSR04

Features:

  • Read distance from 4cm to 250mm**
  • Compensate speed of sound according to the ambient temperature
  • Pass distance thought median filter
  • Set maximum distance to speed up measurement

**Library returns 38000 if OUT OF RANGE

Sujan17: I am a 14 year old and it is the first time for me on the arduino forum I am new to arduino and got a HC-SR04 for a school project. it worked fine and showed the correct distance on an I2c 16*2 display , but the second time i tested it , it showed the distance as 4cm or 5cm even if there was nothing kept in front of it. The correct distance is shown when the object is closer than 5 cm(approx). Please help me out

Sujan

Sounds like something went wrong. Since I can't see the code or the wiring or any part of your setup, there's no hope of me ever guessing what it was.

When you go to the doctor it is not smart to forget to bring the patient. Same here. If you want help to fix your project then you have to show us the project you want help with. That's just common sense right there.

Try newping library

Sujan17: Please help me out.

Spares, and spare parts can sometimes save a lot of time. Sometimes. If for some reason your sensor module has failed (hardware issue developed, which can actually happen), then using another module of the same kind can often tell you whether or not you had a hardware failure. Sometimes, even the replacement module might be faulty, so a third spare module could also be tested.

It could be that your original sensor has no problem, and something has simply changed with your circuit (wiring issue, something was moved/altered), or your code was altered. It all depends on what changed since the last time it 'worked'.

Advising on other libraries does not make sense (to me) if the original worked and now stopped working.