Using Digilent Pmod MAXSonar with Arduino DueFollow project
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
|1||Analog Output (AN)|
|2||Receive Data (RX)|
|3||Transmit Data (TX)|
|4||Pulse-Width Modulation (PWM)|
|6||3.3V/5V Power Supply (Vcc)|
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.
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
- Pmod Vcc to Arduino Due 3V3
- Pmod GND to Arduino Due GND.
- Pmod AN to Arduino Due A0 (for analog mode)
- Pmod PW to Arduino Due D2 (for pulse width measurement)
- Pmod RX and TX pins to Serial3 (pins 14 and 15) for UART communication
Measurement results are displayed in the Serial Monitor