Arduino Distance Sensor How to Build
How to build an Arduino Distance Sensor
Contactless distance finders or proximity detectors are used extensively for applications such as robotics, parking sensors, hand driers and motion detectors.
Ultrasonic sensors are an inexpensive solution to the problem but making sense of the data requires a little help from a microcontroller.
When I first hooked up an HC-SR04 ultrasonic echo module to my Arduino Uno board I thought that it would be easy to program the system to deliver a nice solid distance reading. This is what all the simple examples would have you believe after all. In practice things are not quite as straightforward.
The theory of operation is simple. Just provide a short trigger pulse to initiate the 40kHz sound pulse and measure the time for the echo signal to return. Distance is proportional to the echo time. What could go wrong?
Well sometimes the sound echo isn't detected and the pulse on the echo pin stays high for longer than it should. More often than not there are objects in front of the sensor at different distances. This results in the sensor flipping between two or more readings making it difficult to see what is going on.
The Arduino is a powerful and inexpensive computer that you can use to control and analyze signals from the sensor to provide the results that you want.
The purpose of this project is to demonstrate how you can turn a simple ultrasonic sensor into a sophisticated object detector using a clever software algorithm coded in a short Arduino sketch.
The great thing about this project is that you only need four inexpensive components:
Add a few wires and you are good to go.
You may need to do a minimal amount of soldering to attach the connecting wires to the LCD module but that's it. All the action happens in software which is just how I like it.
Notice that the pins on the LCD/KBD module are mapped differently to the Arduino.
You can solder your HC-SR04 onto a small copper strip but I used a small mini solderless breadboard. I may make this more permanent at some point in the future with a small piece of copper strip board.
At some point I will be thinking about putting this whole project into a nice convenient box but right now I haven't finished adding features to it.
I want to add more display modes and ultimately provide some motion detection software so that it can be used to switch on lights, alert you to people at the door or even trigger a water gun to stop cats pooing in the yard.
I shall also be adding support for the keypad on the LCD/Keypad shield. This will allow you to change between display modes, set parameters like range and sensitivity and even change the whole operating mode of the device.
As you can see. I don't have time to put it into an enclosure yet.
You can either solder the connecting wires directly onto the connections on the LCD board or you can solder some connector strips onto the board like I have.
I should have used some Arduino stackable headers for this job but I didn't have any to hand. What I did have was some dual inline IC sockets so I got out my craft knife and sliced one row off the connector. It works just as well.
The LCD/Keypad shield stacks nicely onto the Arduino and I used 4 connecting hook up wires to connect between the headers on the shield to the mini breadboard with the ultrasonic sensor on it. It's all a bit flimsy but it's manageable and it's not difficult to get a working system together. It will have to do until I can get the case sorted out.
if anyone is interested in finding a suitable enclosure and would like to write up the assembly details I would be happy to consider publishing them here for everyone to see.
|Now subscribe to our newsletter and don't miss a thing|