The HC-SR04 Ultrasonic Distance Sensor is a staple in robotics projects. This inexpensive device is capable of measuring the distance between itself and the nearest solid object from 2 to 400 centimeters. Exactly what you need to keep your bots from driving into walls!
In this article we’ll look at this sensor in depth, including ways to make it even more accurate by compensating for temperature and humidity. There’s lots of Arduino code to be has as well, so dig in!