Introduction: Super Simple Sonar on Arduino Pro-mini 5v With HC-SR04 Sonar Module

The objective was to just get one of the cheap HC-SR04 sonar modules up and running but with a single wire. If you have used these, generally it requires two wires. One for the trigger and one for the echo. So I wanted to find some library that could handle them better than the examples provided and a wiring diagram or example that actually worked.

This was just a proof , which would form part of a bigger project but first just a building block with no frills that is easy to get going.

Step 1: The Code

So I am going to use the newping library - http://playground.arduino.cc/Code/NewPing

This provides a nice level of sophistication that allows faster pings, and also handles the times when the echo isnt found and stops the library from timing out.

You just need to download it from https://bitbucket.org/teckel12/arduino-new-ping/d...

and save it locally. I'm using the v1.8

Then go into the Arduino IDE and go Sketch -> Include Library -> Add .ZIP library and load the zip file that you have just loaded and the library is now ready to use.

I wanted to use just one pin for trigger and echo and chose Pin 12 and this is the code I used.

Step 2: Wiring It Up

So this is very simple, the HC-SR04 has 4 pins and we are using an Arduino Pro-mini 5v

Arduino -- HC-SRO4

Gnd ---------- Gnd

Vcc ----------- Vcc

Echo ---------- Pin 12

Trigger -------- Pin 12

Basically, I just put a jumper link that connects the Echo and Trigger together

Step 3: In Operation

So with it all running, the first thing is the serial monitor will print "Ready" then a series of range measurements in cm will be displayed.

One added feature is that when the target in front of the sonar is below 8cm, then the onboard light comes on to show something is near.