Skip to main content

Using Digilent Pmod MAXSonar with Arduino Due

This project demonstrates how to use Pmod MAXSonar, an acoustic range finder, with Arduino Due in three different measuring modes.

Parts list

Qty Product Part number
1 Digilent Pmod MAXSONAR Maxbotix Range Finder Expansion Board 240-071 134-6439
1 Arduino, Due Development Board 769-7412

The Pmod MAXSonar is an ultrasonic range finder. It is powered by MaxBotix® LV-MaxSonar®-EZ1™ and able to measure distances in the range of 6 - 255 inch (15 - 648 cm) with precision of 1 inch (2.54 cm) for every 50 milliseconds.

Interface with Pmod MAXSonar

The Pmod MAXSONAR communicates with the Arduino via the UART protocol, analog output, and PWM timing. The UART protocol is configured with a baud rate of 9600, 8 bits, no parity, and a single stop bit. The module can be powered by 3.3V or 5V. Here is the pinout table

Pin Signal
1 Analog Output (AN)
2 Receive Data (RX)
3 Transmit Data (TX)
4 Pulse-Width Modulation (PWM)
5 Ground (GND)
6 3.3V/5V Power Supply (Vcc)

Timing Description

Pmod MAXSonar requires 250 milliseconds to power up and then will perform a self-calibration if the  (RX) pin is left at floating or logic level high voltage. The calibration will take 49 ms, and after an additional 100 ms of waiting time, the module will be able to take measurement readings every 49 milliseconds.

Each 49millisecond period starts by the RX being high or open, after which the Pmod MAXSonar sends the transmit burst, after which the pulse width pin (PW) is set high. When an object is detected, the PW pin is pulled low. The PW pin is high for up to 37.5 millisecond if no object is detected. The remainder of the 49 millisecond time (less 4.7 millisecond) is spent adjusting the analog voltage to the correct level. When a long distance is measured immediately after a short distance reading, the analog voltage may not
reach the exact level within one read cycle. During the last 4.7 millisecond, the serial data is sent.

pmodmaxsonar_timingdiagram1_b922dcc4a94082a4fbc16e26fe8f63d08b65b342.png

Capture Distance through TX, AN or PW pin

When the RX pin is left floating or held at a logic level high voltage, 5 bytes will be sent out over the TX pin beginning with the capital ASCII character 'R', three ASCII digits representing the detected distance, and a carriage return character (ASCII character 13).

An analog signal representative of the measured distance of the object in front of the Pmod MAXSONAR may also be read. The output has nine bits of resolution. With a power supply at 3.3V, each inch is equivalent to ~6.4 mV. Users that are measuring the incoming analog signal with a popular 10-bit ADC will have to divide their measured value by 2 before calculating the reported distance.

The Pmod MAXSONAR also provides distance data through a pulse-width modulation signal. Every 147 uS that the pin is measured at a logic level high voltage state is equivalent to 1 inch away. If the signal is measured to be high for 2.205 milliseconds, then the detected object is 15 inches away from the front of the Pmod MAXSONAR. The maximum measured pulse time of 37.5 milliseconds indicates that there is no object within 255 inches of the Pmod.

Connecting to Arduino Due

  1. Pmod Vcc  to Arduino Due 3V3
  2. Pmod GND to Arduino Due  GND.
  3. Pmod AN to Arduino Due A0 (for analog mode)
  4. Pmod PW to Arduino Due D2 (for pulse width measurement)
  5. Pmod RX and TX pins to Serial3 (pins 14 and 15) for UART communication

Measurement results are displayed in the Serial Monitor

result_647a999e87619668404be30ca63f729e2c98babe.png

awong has not written a bio yet…
DesignSpark Electrical Logolinkedin