Wrong distance on ultrasonic sensor

I’m using an ultrasonic sensor (MD7052) to measure a water tank, but for some reason I’m not getting the correct measurement. I’m using this code https://www.maxbotix.com/documents/Arduino%20Codes/XL-MaxSonars/XL_MaxSonar_PW.ino, and I have the cable setup using pin 2 and connect to D0.

When I place a card board on top of the sensor it was suppose to display 0cm but its displaying 30cm and sometimes 25cm.

Any one has any idea on what do I need to change so I can get the correct measurement?

Thanks

Have you tried measuring other fixed distances? I think this sensor has a 20 cm minimum distance (though it seems it can sometimes read distances smaller than that). I don’t think putting a cardboard directly on the sensor is the best way to test it.

2 Likes

Ric, yes thank you for the quick reply. I just saw on the data sheet the 20cm minimum distance. I tested on the tank and its reading fine.

Thanks for the help.

1 Like