Exercise: Read Ultrasonic Ranger

Objective

Measure distance using a time-based process. Use the serial port for debugging.

Some processes we measure in the world involve measuring time. A sonar ranger emits a pulse of sound and measures the time it takes to reflect from an object back to the source. The distance is not itself a temporal quantity, but the dynamic process maps that distance to a time interval.

../../../_images/read-sonar.png

Steps and observations

  1. Wire the circuit on the breadboard using the HC-SR04 ultrasonic ranger. Note that this module has one digital trigger input and one digital echo output.
  2. Load and run the ReadSonar sketch.
  3. Within the Arduino IDE, open the serial monitor console and make sure it is set to 9600 baud.
  4. Observe the numbers printed in the serial monitor as you place a hard object a short distance in front of the sensor. It may take some time to find an object and orientation which yields a reliable signal.
  5. Estimate the precision of the measurement. Is the scaling correct? Is there an offset error?

Comments

This exercise is a good opportunity to learn to use an oscilloscope. The DMM excels at measuring constant voltages, but cannot show how a signal varies over time. The oscilloscope plots voltage versus time at a wide range of time scales. It includes many controls designed to help select the specific intervals of interest from a waveform, in particular, triggering each sweep at a particular voltage and slope.

Arduino Code

  1. Documentation: ReadSonar Arduino Sketch
  2. Sketch Folder: ReadSonar

Other Files

  1. EAGLE file: read-sonar.sch