Arduino Distance Sensor
Sensing the proximity of objects can be achieved effectively using ultrasonic echo techniques. Transmitting pulses of ultrasonic sound and measuring the time it takes the echo to return does present us with some interesting challenges however.
The sound can bounce off more than one object at different distances or the pulse is scattered. Sometimes the receiver doesn’t even hear the echo. Luckily these problems can be overcome and a useful instrument built using an HC-SR04 ultrasonic transceiver and a little clever software running on an Arduino.
Hi I’m Steve Garratt from homediyelectronics.com and I want to show you what I’ve been doing with an ultrasonic distance sensor and an Arduino and an LCD/Keypad shield.
Here’s the ultrasonic module that I’ve been using. It’s an HC-SR04 module. Simple connections on the back. Four connections – ground, power, trigger and echo. That’s all there is to it. It’s easy to drive. Not so easy to make sense of the results however.
And this is what I want to talk to you about today.
All the details for building this including all the software; you can find it on http://homediyelectronics.com
Here’s my Arduino distance sensor. It uses an HC-SR04 ultrasonic range finder module and an LCD/Keypad shield to display the results.
Now, when I started to look at ultrasonic range finding I started off by looking at every individual distance that it gave me and I soon found that that was very difficult to actually make sense of because the sensor sometimes has trouble locking on to any individual object.
What we are looking at here is the sensor looking at a small object at about 120 cm away with the wall behind it. You can see at the moment that most of the time it’s looking at the wall which is about two meters away but occasionally it picks up the object.
Now the ultrasonic sensor is a very simple one. All it does is it sends out a 40kHz burst of pulses and measures the distance or measures the time it takes for the echo to come back to the sensor.
So it can only measure one echo at a time and depending on which one is the dominant echo, sometimes it picks the first one and sometimes it picks the second one.
Now what I’ve done here is added some persistence to the readings and displayed them on the LCD. What that gives us I think, is a display that is much easier to make sense of what’s going on. It’s pretty easy to see here that we’ve got an object in the foreground with something rather large behind it. Rather like a radar screen.
Well that’s how it works anyway. You can see all the details for this on the website at homediyelectronics.com