Using the MaxSonar® TX Output

MaxSonar Pulse Width

Connecting The MaxSonar to a Computer

The MaxSonar® can be directly interfaced to be used with your PC, if you have a PC with a DB9 Serial connection or a USB to DB9 convertor. The DB9 connection is capable of being connected to the TX pin output on the MaxSonar® sensor. Connecting the sensor to a computer allows the user to see range readings that have already been processed to distance using RS232. Although the voltage of 0-Vcc is outside the RS232 standard, most RS232 devices have sufficient margin to read 0-Vcc serial data. If standard voltage level RS232 is desired, invert, and connect an RS232 converter such as a MAX232. When interfacing MaxSonar sensors with a computer, a power input is still required for the sensor to operate. A computer's DB9 input typically has enough margin to read the serial data output even when the sensor is powered at its minimum required voltage.
We recommend powering that the sensor is powered at 5VDC when connecting the sensor to a computer's DB9 connection. It is also recommended that the power supplied to the sensor is from a voltage regulator or any source able to provide clean stable power to the sensor.To interface the sensor with the computer, pin 5 on the DB9 connection must be connected to the GND pin on the MaxSonar® and pin 2 on the DB9 connection must be connected to Pin 5 (TX) on the MaxSonar®. Please refer to figure 1.1 below for the pin layout of DB9 serial connections. The serial (TX) output delivers asynchronous serial with an RS232 format, except voltages are 0-Vcc. The output is an ASCII capital “R”, followed by ASCII character digits representing the range. This is then followed by a return carriage. For the maximum range reported for your sensor please refer to your sensor’s data sheet.

TTL Serial

The HR-MaxSonar sensors have added TTL serial to the Pin 5 output. This allows micro-controllers that accept TTL to use our sensors. If you wish to use an LV-MaxSonar or XL-MaxSonar with a TTL compatible micro-controller, it is required to use a hardware inverter when interfacing with the micro-controller. To read more on this skip down to Troubleshooting the Serial Output

Serial Port Configuration Settings

Com Port: Determined by Hardware*
Baud 9600 Bits per Second
Data Bits: 8
Parity: 0 / none
Stop Bit: 1
Flow Control: 0 / none

For computers with a DB9 port attached to the motherboard, this port is typically assigned "ComPort 1". If an adapter such as a USB to DB9 adapter is being used, the computer operating system will assign this port a unique Com Port.

Setting up Serial Port Software

First you will want to select the proper COM port on your computer. After the COM port is selected configure the port. Set the bits per second (BAUD) to 9600. Set your data bits to 8 and your parity to none. If there is a way to set the stop bits, set the stop bit to 1. Final setting if the software has it is Flow Control. If Flow Control is available set this setting to none. In the past, HyperTerminal came standard on computers with Windows XP or older. For Windows Vista and Windows 7 users, software has to be downloaded in order to read the serial port. To download HyperTerminal click here.  We have completed basic testing to verify this software operates with our sensor.

Troubleshooting the Serial Output

One common issue when connecting a MaxSonar sensor to a computer is the baud rate, bit, or parity not set correctly. The computer configuration is: a baud rate of 9600, 8 bits, no parity, and one stop bit. Another common issue when using the serial output of the MaxSonar is inverting. The TX output needs to be inverted from RS232 to TTL to be compatible with TTL devices. To invert the signal you will need an inverter such as a MAX232. Some users may not have DB9 connection on their computer and need a USB to serial adapter. USB to serial adapters may have an auto switch that switches between TTL and RS232 which may not work properly with our sensors. To allow proper operation of our sensor with an adapter you may have to invert the serial output (with an inverter like the Max232) prior to connecting the sensor to the USB to serial adapter. Although the voltage of 0-Vcc is outside the RS232 standard, most RS232 devices have sufficient margin to read 0-Vcc serial data. If standard voltage level RS232 is desired, invert, and connect an RS232 converter such as a MAX232.

Products Related to the Article


MB1003 HRLV-MaxSonar-EZ0

MB1003 HRLV-MaxSonar-EZ0

The HRLV‑MaxSonar‑EZ0 has the widest and most sensitive beam pattern of any unit from...

Buy Now

MB1200 XL-MaxSonar-EZ0

MB1023 HRLV-MaxSonar-EZ2

The XL‑MaxSonar‑EZ0 offers the widest and most sensitive beam pattern of any indoor sensor ...

Buy Now

MB7360 HRXL-MaxSonar-WR

MB7360 HRXL-MaxSonar-WR

The weather resistant HRXL-MaxSonar-WR is a rugged, ultrasonic sensor component module...

Buy Now
Back to blog

Lets connect on your project!