Posts | Comments

Planet Arduino

Archive for the ‘ultrasonic distance sensor’ Category

Infrared certainly has its uses, but if you’re trying to locate objects, ultrasonic detection is far superior. It’s contact-less, undetectable to the human ear, and it isn’t affected by smoke, dust, ambient light, or Silly String.

If you have one ultrasonic sensor and a microcontroller, you can detect plenty of useful things, like the water level in a rain barrel or the distance traveled by a tablet along a rail. If you have two sensors and a microcontroller, you can pinpoint any object within a defined range using trigonometry.

[lingib]’s dual sensor echo locator uses two HY-SRF05s, but the cheap and plentiful HC-SR04s will work, too. Both sensors are arranged for maximum beam overlap and wired up to an Arduino Uno. One sensor’s emitter is blocked with masking tape, so all it does is listen.

When the system registers the object, it shows up as a red dot on a grid inside a Processing sketch along with a bunch of details like the object’s coordinates, its distance from each sensor, and the area of the triangle formed by the two sensors and the object. [lingib] reports that the system is quite accurate and will work for much larger playgrounds than the 1 meter square in the demo after the break.

Don’t want to detect objects? Ultrasonic sensors are cheap enough to hack into other things, like this one-way data communications module.

Thanks for the tip, [Setvir].

Rain barrels are a great way to go green, as long as your neighborhood doesn’t frown upon them. [NikonUser]’s barrel sits up high enough that he has to climb up on an old BBQ and half-dangle from the pipe to check the water level, all the while at the risk of encountering Australian spiders.

Arachnophobia, it turns out, is a great motivator. At first, [NikonUser] dreamed up a solar-powered IoT doodad that would check the level and report the result on a web page. He battled the Feature Creep and decided to build a handheld device that pings the water level with an ultrasonic sensor and displays it on a 7-segment.

Everything is contained in a water-resistant box and driven by an Arduino Pro. The box is mounted on a piece of scrap lumber that lays across the top of the barrel. This allows the HC-SR04’s eyes to peer over the edge and send pings toward the bottom. It also helps to keep the readings consistent and the electronics from taking a swim.

Operation is simple: [NikonUser] reaches up, sets the plank across the barrel, and pushes the momentary. This activates the Arduino, which prompts the HC-SR04 to take several readings. The code averages these readings, does a little math, and displays the percentage of water remaining in the barrel.

Interested in harvesting rain water, but not sure what to do with it? You can use it for laundry, pour it in the toilet tank instead of flushing, or make an automated watering system for your garden.

“It’s only software!” A sentence that strikes terror in the heart of an embedded systems software developer. That sentence is often uttered when the software person finds a bug in the hardware and others assume it’s going to be easier for fix in software rather than spin a new hardware revision. No wonder software is always late.

[Clint Stevenson] is his own hardware and software guy, as are most of us. He wanted to use the less expensive HC-SR04 ultrasonic rangefinder in a prototype. Longer term he wanted to have the choice of either a Parallax PING or MaxBotix ultrasonic sensor for their better performance outdoors. His hardware hack of the SR04 made this a software problem which he also managed to solve!

[Clint] was working with the Arduino library, based on the Parallax PING, which uses a single pin for trigger and echo. The HC-SR04 uses separate pins. Originally he modified the Arduino library to accept the two pin approach. But with his long term goal in mind, he also modified the HC-SR04 sensor by removing the on-board pull-up resistor and adding a new one on the connector side to combine the signals. That gave him an SR04 that worked with the single-pin based library.

We’ve seen Parallax PING projects for sensing water depth and to generate music. These could be hacked to use the HC-SR04 using [Clint’s] techniques.

[Arduino and HC-SR04 photo from

Filed under: Arduino Hacks, Holiday Hacks, software hacks


[Klaus] wanted some sort of aid for parking his car, and after running across a $4 ultrasonic sensor, decided to build his own speaking distance sensor (.de, Google Translation).

Inside [Klaus]‘ device is an Arduino Uno, an HC-SR04 ultrasonic distance sensor, and an Adafruit Wave Shield. Originally, this parking/distance sensor used a small TFT to display the distance to an object, but after a few revisions, [Klaus] redesigned the device to speak the current distance, courtesy of an SD card and a soothing female voice.

Right now, the voice is set up to speak the distance from an object to the sensor from 10 cm to 1 m in 5cm increments. This isn’t the limit of the sensor, though, and the device can be easily reconfigured to sense a distance up to four meters.

The board doesn’t have an amplifier or speaker, but with the addition of a small amplifier, [Klaus]‘ device is loud enough to be heard in even the noisiest environments.

Video demo below.

Filed under: Arduino Hacks

  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook