Using an Ultrasonic Distance Sensor With Arduino
In this tutorial we will be looking at how to use an Ultrasonic Sensor to measure distance using an Arduino. This type of sensor emits a burst of ultrasonic sound and then waits to hear the echo. These sensors are generally inexpensive, fairly accurate, and not affected by lighting conditions like infrared based systems. We will be looking at three sensors, these are all code compatible but require subtle changes in the wiring due to differing pinouts.
A Few Considerations:
Before we jump into getting this sensor hooked up there are a few points to consider when using it in a project.
• If there is any chance of these coming in contact with water, the weatherproof version must be used.
• The further an object is away, the larger it needs to be to have reliable detection.
How It Works:
The sensor itself takes care of most of the heavy lifting and as a result, there is one input (Trigger) and one output (Echo). When the trigger is set high, an ultrasonic burst is sent and the circuit internal to the sensor starts watching for a response. When the response is received, the echo pin is immediately triggered high. We can simply time how long it takes from trigger to echo and divide by two. Since sound travels at a reasonably consistent speed, the distance is easy to obtain.
If you have any questions, or need further clarification please post in the comments section below; this way future users of this tutorial can see the questions and answers!