Build Your Own
Ultrasonic Rangefinder

Part A

While there are plenty of Ultrasonic Rangefinder Modules available on the market, few if any provide a “full range” image of the echo complex, only providing the range to the closest target. Moreover, most lack a true analog representation of the return echo, i.e. echo range and amplitude. The following project provides all the above, can be modified to meet the user’s exact needs, and is relatively inexpensive.

Part A of this project will have you building both the analog and digital parts of the rangefinder and program the controllers to have a fully functional ranger. While the true analog data and echo complex returns will be available to the user, this Part A will only deal with ranging to the closest object and display it via a VT100 terminal emulator (Windows XP). Part B will demonstrate the representation of the full target complex.

Use the Quick Start below for a fast immersion into the project, or read the How It Works PDF (skip to page 8 ) for in-depth details of the project.

Quick Start:

Parts List:

(1) Arduino
(1) Kemani or Amani 64 CPLD Kit
(1) Maxbotix-UT Ultrasonic Transducer
(2) OpAmp Modules BOB-09816 or build your own: schematic
(2) 0.1uF Ceramic Capacitors
(1) 4.7k Resistor
(1) Breadboard

Project Code:

Arduino: ArdRanger
Kemani/Amani64: SonicTX


Kemani/Analog Front End

System Block Diagram


1. Construct the circuit seen in the Kemani/Analog Front End Schematic.

      Instead of using the BOB-09816 OpAmp breakout modules, you may construct your own gain stages. The BOB-09816 (schematic) are simple non-inverting operation amplifier gain stages, with a dc bias at half Vcc.
      If you are using an Amani64 instead of the Kemani, you only need to build the analog portion of the circuit and connect the transmit line (pin 41 on the Kemani) to an Amani Dock of choice, as well as the receive line (Kemani pin 21).

2. Connect the TX_TRIGGER line to Arduino pin 4. Connect RANGE_PWM to Arduino pin 9. Connect the GND line of the breadboard to the GND connection on the Arduino. (Ppower, GND)

      If you are using an Amani64 instead of the Kemani, simply seat the Amani on the Arduino. Define your Amani TX_TRIGGER and RANGE_PWM pins to match the Arduino signals. Amani pin 33 = Arduino pin 4, Amani pin 29.

3. Connect an external DC power source to power jack J6 of your Kemani or Amani64.

      Technically you may power your Kemani or Amani64 from you Arduino. If you choose this option I highly advise that you do not rely on USB power alone as you are driving an analog stage. The Kemani, being a 5V core device can be powered from the 5V port of the Arduino. The Amani64 receives Arduino power via the JP2 setting.

4. Load SonicTX.pof into the Kemani/Amani CPLD via the JTAG ISP of choice.

5. Connect your Arduino to your computer via USB.

6. Upload the ArdRanger code to your Arduino. Do not start the Serial Monitor.

7. Load the VT100 Terminal Emulator. Select the COM Port your Arduino uses. Select 9600bps. Initiate serial connection. Observe the Range Values in the Arduino Ultrasonic Ranger window. They will most likely not reflect an accurate measurement as the gain stages must be adjusted.

      If using Windows XP, use the HyperTerminal application found in Start > All Programs > Accessories > Communications.

      Initiate the connection by pressing the “Call” icon or selecting “Call” from the Call Menu.

8. We will now calibrate the analog section to detect your ceiling.

    A. Start in a room with a standard ceiling that is flat and is up to 10 feet above your workbench. Estimate the range from your sensor to the ceiling.

    B. Adjust the potentiometers of the OpAmp modules all the way clockwise, which sets minimum gain.

    C. Observe the range readout to be 34 feet, 10 inches. (10.65 meters). This indicates nothing is being detected.

        This reflects the maximum detection range of the timing circuitry aboard the Kemani and does not necessarily represent the detection range of the analog circuit.

    D. Begin adjusting the gain of the first stage by adjusting the potentiometer counter-clockwise. Most likely you will rotate it to its full limit without detecting your ceiling.

        Typically we do not crank the gain to “patent pending” in amplifiers as this typically puts the amplifier into compression. In later examples we will operate the amplifiers in their linear regions.

    E. Slowly adjust the second gain stage potentiometer counter-clockwise and keep an eye on the range readout. Stop adjustment when you first see the range values change to your estimated value.

        Most likely the values will switch back and forth between your ceiling range and 34’ 10”. This is due to the amplified echo return amplitude is just now rising above the noise-floor.

    F. Continue increasing the gain until your estimate ceiling range becomes a solid, regular reading.

    G. Test the range dynamics of your sensor by waving your hand between the sensor and the ceiling. The minimum detection range of this system is 1 foot 2 inches. (0.36 meters)

        The minimum detection range is set by the Kemani/Amani code as it blanks the receiver during the transmit pulse and transmit artifacts.

    H. If you increase the gain too high, you will begin to see range “rabbits” and eventually the ranger will default to the minimum range setting. Reduce the gain until satisfactory.

        The “rabbits” are false return readings that most likely are triggered by the noise floor having been amplified over the detection threshold.

        The unit settles at the minimum-range reading as the gain drives the amplifier into compression thus spurious signals and noise trips the detection threshold immediately after the range timer starts.

9. Calibrate the metric accuracy of the rangefinder. In the Arduino code, you will find a constant defined as RANGE_BIAS. Adjusting this value adjusts the range offset typically caused by circuit timing delays. Place a detectable object a measured distance from the sensor and adjust the RANGE_BIAS constant to calibrate the range reading to the correct value.

      RANGE_BIAS is measured in microseconds. Sound, traveling 343.2m/s, takes 74 microseconds to travel one inch. Be sure to account for round trip flight.

      In order to make changes to the Arduino code and upload them, the serial connection to the VT100 emulator must be disconnected via the “disconnect” command.

10. If gain adjustments fail to create solid, constant range readings, try adjusting INTEGRATION_FACTOR in the Arduino code between 1 and 10.

      INTEGRATION_FACTOR in this case simply averages the range readings. The usefulness of this constant will be seen in later examples as it will be used to integrate amplitude readings and increase the signal to noise ratio.

11. Experiment, tweak, have fun!

How It Works: PDF Document (Contains the Quick Start Instructions)