Hello! Please can anyone help me with a perfect library for my ultrasonic sensor and some sample codes? I want to calculate the distance between the sensor and the bottom of a container and take some actions based on my result
Hello, Temmy
I’m not sure what type of ultrasonic sensor you use.
Usually, the module comes with trigger pin and echo pin. Some modules use only output pin. Some use I2C protocol to communicate with microcontroller. So, the library depends on what model of your sensor.
Anyway, I assume you use HC-SR04 ultrasonic sensor and Arduino IDE to write your code. In Arduino IDE, Go to sketch->include library-> manage libraries.
There are many libraries that can give the type of output you want. cm., mm., or even in JSON format.
For myself, I used “NewPing” once and find it works very well.
Hope it helps
Yes it’s the HC-SR04, thanks alot I’ll use the newping library, where can I download it?
This is a link to the website directly ->
https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
If you use Arduino IDE you can go to
sketch -> include library -> manage libraries -> filter for ultrasonic sensor
scroll down a little bit you will see “NewPing” by Tim Eckel
choose the latest version and click install
Thanks alot for the help, really grateful