Super Simple Sonar on Arduino Pro-mini 5v With HC-SR04 Sonar Module
by Ajaxjones in Circuits > Arduino
6420 Views, 41 Favorites, 0 Comments
Super Simple Sonar on Arduino Pro-mini 5v With HC-SR04 Sonar Module
![IMG_0904.JPG](/proxy/?url=https://content.instructables.com/FZR/F23H/ITKJ97Q9/FZRF23HITKJ97Q9.jpg&filename=IMG_0904.JPG)
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.
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.
Downloads
Wiring It Up
![IMG_0905.JPG](/proxy/?url=https://content.instructables.com/FZW/RHJT/ITKJ97QE/FZWRHJTITKJ97QE.jpg&filename=IMG_0905.JPG)
![IMG_0906.JPG](/proxy/?url=https://content.instructables.com/FCJ/X5EJ/ITKJ97RR/FCJX5EJITKJ97RR.jpg&filename=IMG_0906.JPG)
![IMG_0907.JPG](/proxy/?url=https://content.instructables.com/FSU/LE1E/ITKJ97P1/FSULE1EITKJ97P1.jpg&filename=IMG_0907.JPG)
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
In Operation
![Simple sonar](/proxy/?url=https://content.instructables.com/FK2/6PKS/ITKJ98FY/FK26PKSITKJ98FY.jpg&filename=Simple sonar)
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.