Lab 5 – Obstacle Avoidance

This lab will have the vehicle deviate from a set course to avoid obstacles found by sonar detectors. There are two main hardware components:

Obstacle sensor:
XL MaxSonar Elcano has three models available: 1200, 1210, and 1220. They differ in the angle of coverage. These sonar detectors will respond to any object in their field, which has a depth of about 25 feet (7.5 m). The range is less for skinny things: 12 feet (4 m) for an object 0.25 inch (6 mm) in diameter. Range will also decrease if running on 3.3V instead of 5V. For larger objects at 5V, the width of the field is about 45° for 1200, 40° for 1210, and 25° for 1220. There are three methods for sending an object range signal:

  1. An analog signal proportional to the range.
  2. A signal whose pulse width is proportional to range.
  3. A serial signal.

Students have found the pulse width signal to be the most reliable. Mounting boards are provided for the sonars. They can be built in various ways; the standard version has a sensor pointing forward, two others at 30° off center (front left and front right), and two others facing sideways. The board could also be built with rear pointing sensors that replace the sideways sonars. The signal to the mounting board has 8 lines: 5 for analog signals from each sensor, 1 for power (either 5V or 3.3V), ground, and chaining. The chaining signal is meant to strobe each sensor in turn, so that they do not interfere with each other. This feature does not appear to behave as documented.

Steering feedback:
AS5043 magnetic angle encoder This device is connected to C2 by either a Synchronous Serial Interface (SSI) or an analog signal. SSI is essentially the same as Serial Peripheral Interface (SPI). To receive data from the sensor over SSI, bring Chip Select (CSN) low. While it is low, each pulse on the Clock (CLK) will cause a bit to be transmitted in serial over Data Out (DO, or master-in,slave-out, MISO, in SPI terminology). There are 16 bits: 10 data bits, 5 status bits, and an even parity bit. The magnet is strong; keep it away from credit cards, etc.

There was an 8 pin female socket on the board, and 2 pins attached to a 9V battery connector. These have been replaced with a 10 pin angled male connector. The signals are:

  1. 9V: VIN from Arduino
  2. Gnd: Gnd from Arduino
  3. Vout_ext: Op Amp output.
  4. Gnd
  5. * Vdd3V3: Output; do not load externally.
  6. Vdd5V: Positive supply; 3.0 to 5.5V
  7. Clk: Clock of SSI
  8. DO: Serial Data Output (MISO).
  9. Csn: Chip Select, active low
  10. * Prog: Data In (MOSI); connect to ground if unused.

Connecting cable is female to male.

Connection to Arduino Micro
Connection to Arduino Micro


We need the steering angle sensor, since otherwise we don’t know which way the wheels are pointing. We know what steering angle we requested, but there are several factors that make that number inaccurate. There could be mechanical delay in implementing the request. The servo has a fixed slew rate (e.g. 1 inch/second). Mechanical systems often are driven by a ball screw that has hysteresis. If you move the screw in one direction, it responds as expected. When you move it in the other direction, there is a certain amount of slop (backlash) before the threads engage and start the motion. For this lab, we check to see if the path in front of the vehicle is clear; if so, keep going as commanded. If there is an obstacle, turn left or right to avoid it. If there is not any clear path, stop.


(7/2/14) – Obstacle detection has been demonstrated using three sonars (forward and side-facing). The chaining feature does not appear to work. The steering angle sensor and magnet have been physically mounted on the trike, and electrically connected to Arduino. Software is under development.

Open Source Autonomy