Tag Archives: hc-sr04

Ultrasonic Sensor HC-SR04 as a ROS Range publisher

I’ve taken a HC-SR04 like shown below and connected it to the CubieTruck as a rosserial publisher.



Instead a of a simple  std_msgs::String str_msg;  I’ve implemented a  sensor_msgs::Range range_msg; which after starting the arduino in ros with rosrun rosserial_python serial_node.py /dev/ttyACM0 shows up in  rostopic echo /ultrasound like this:

So with that, its possible to visualize everything using rqt_plot:


which is pretty nice for my first arduino micro ros project and less than an two hours of work 🙂

For further information see here


Arduino Micro and ultrasonic sensor HC-SR04

This is my very first arduino application. But its simple and amazing.

You will need 4 female to female jumper wires and [amazon &title=HC-SR04&text=HC-SR04] ultrasonic sensor, a microusb cable and in the end you’ll be able to measure distances with this little device.

Just wire it like shown below:


I used pins 7 (orange echo) and 8 (yellow trigger) for data pins, 5V(red) and ground(black).

I have taken some code from this page. The result you can see in the screenshot below, its a amount of cm written in the serial console:

Screenshot - 13.05.2014 - 17:37:28