Reference
Last revision 2025/12/16
The article serves as a comprehensive reference for the URM_UART communication protocol, outlining command formats and instructions for measuring distance and temperature, setting baudrate and detecting range, and modifying sensor addresses, aiming to enhance understanding and implementation of ultrasonic sensor operations.
Library
Please download the Library First
Communication Protocol Description
Default Information:
- Default Baudrate: 19200,8,N,1
- Default Address: 0x11
- Communication Command Format
Communication Commands and Returns frame Format:
| Header | Address | Length | Cmd | Data | SUM |
|---|---|---|---|---|---|
| 55 | AA | 11 | N | 01 | Data1~DataN |
PS: The sum byte value is the sum of all the byte value before. Just keep one byte from the total sum value.
Measure Distance
You could send a measure command to the Ultrasonic module. It will measure the distance, and send the value back through UART port.
For example:
Send Command: 0x55 0xAA 0x11 0x00 0x02 0x12
Instruction:
- Header----------------0x55
- Header----------------0xAA
- Address---------------0x11
- Length-----------------0x00
- Read Distance-------0x02
- Check Sum-----------0x12
Return Command:0x55 0xAA 0x11 0x02 0x02 0x12 0x34 0x5A
High 8-bit: 0x12;
Low 8-bit: 0x34
So the distance value is “0x1234”, which convert to decimal is 4660mm.
“0x5A” is low 8-bit of the check sum.
Measure Temperature
You could send a measure command to the Ultrasonic module. It will measure the temperature, and send the value back through UART port.
For example:
Send Command: 0x55 0xAA 0x11 0x00 0x03 0x13
Instruction:
- Header-----------------------0x55
- Header-----------------------0xAA
- Address-----------------------0x11
- Length------------------------0x00
- Read Temperature----------0x03
- Check Sum-------------------0x13
Return Command:0x55 0xAA 0x11 0x02 0x03 0x00 0xFF 0x14
High 8-bit: 0x00;
Low 8-bit: 0xFF
The output value will be “0x00FF”, which convert to decimal is 255. As the real temperature is 10% of the output value, so it is 25.5℃.
NOTE:
The measuring range is -10~70℃, it is a 16-signed integer. Negative digits are stored in two's complement' as in bitwise complement(~2). The method is judging whether BIT15 is “1”. If it is “1”, it means it is a negative number, the data will be inverted, and “1” should be added to the result.
Further information: https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitwisenot/
Set Address Command
The module default address is “0x11”. And the broadcast address is “0xAB”. If you don’t know the current address, but you want to set its address, you could use broadcast address to set the target address.
For example:
Send Command: 0x55 0xAA 0xAB 0x01 0x55 0x11 0x11
Instruction:
- Header-----------------------0x55
- Header-----------------------0xAA
- Broadcast Address---------0xAB
- Length------------------------0x01
- Address Setting CMD-----0x55
- Target Address---------------0x11
- Check Sum--------------------0x11
Return Command:0x55 0xAA 0x11 0x01 0x55 0xCC 0x32
The address of each device can be changed when multiple devices are connected. The new address must be between “0x11” and “0x80”. If you change it successfully, the module will return “0xCC”. If you fail, it will return “0xEE”.
Set the Detecting Range of the Ultrasonic Module
You could set the detecting range through UART interface. The proper range will increase sonar frequency and improve its accuracy.
For example:
If the module address is “0x11”, the range limit is 3840mm
Send Command: 0x55 0xAA 0x11 0x02 0x04 0x0F 0x00 0x25 //3840=0xF00
Instruction:
- Header-----------------------0x55
- Header-----------------------0xAA
- Address-----------------------0x11
- Length------------------------0x02
- Set Value CMD--------------0x04
- High 8-bit---------------------0x0F
- Low 8-bit----------------------0x00
- Check Sum--------------------0x25
Return Command: 0x55 0xAA 0x11 0x00 0x04 0xCC 0xE0
If you change it successfully, the module will return “0xCC”. If you fail, it will return “0xEE”.
Note: the default setting is the maximum value.
Read the Detecting Range of the Ultrasonic Module
You could read the detecting range through UART interface.
For example:
If the module address is “0x11”.
Send Command: 0x55 0xAA 0x11 0x00 0x05 0x15
Instruction:
- Header-----------------------0x55
- Header-----------------------0xAA
- Address-----------------------0x11t
- Length------------------------0x00
- Read value CMD-----------0x05
- Check Sum-------------------0x15
Return Command:0x55 0xAA 0x11 0x02 0x05 0x0F 0x00 0x26
So the return value is “0x0F00”, which convert to decimal is 3840mm
The unit of the distance is “mm”.
Set the UART Baudrate of the Ultrasonic Module
You could set communication baudrate of the ultrasonic module through UART interface.
For example:
If the module address is “0x11”.
Send Command: 0x55 0xAA 0x11 0x01 0x08 0x05 0x1E //set baudrate to 19200BPS
Instruction:
- Header-----------------------0x55
- Header-----------------------0xAA
- Address----------------------0x11
- Length------------------------0x01
- Baudrate Setting CMD----0x08
- Target baudrate-------------0x05
- Check Sum--------------------0x1E
Return Command:0x55 0xAA 0x11 0x01 0x08 0xCC 0xE4
If you change it successfully, the module will return “0xCC”. If you fail, it will return “0xEE”.
Baudrate List:
| Command | Description |
|---|---|
| 55 AA 11 01 08 00 19 | Set baudrate to 1200BPS |
| 55 AA 11 01 08 01 1A | Set baudrate to 2400BPS |
| 55 AA 11 01 08 02 1B | Set baudrate to 4800BPS |
| 55 AA 11 01 08 03 1C | Set baudrate to 9600BPS |
| 55 AA 11 01 08 04 1D | Set baudrate to 14400BPS |
| 55 AA 11 01 08 05 1E | Set baudrate to 19200BPS |
| 55 AA 11 01 08 06 1F | Set baudrate to 28800BPS |
| 55 AA 11 01 08 07 20 | Set baudrate to 38400BPS |
| 55 AA 11 01 08 08 21 | Set baudrate to 57600BPS |
| 55 AA 11 01 08 09 22 | Set baudrate to 115200BPS |
| 55 AA 11 01 08 0A 23 | Set baudrate to 128000BPS |
| 55 AA 11 01 08 0B 24 | Set baudrate to 256000BPS |
API Description
URM_UART urm(Serial);: Select the Serial port for communication with Urm_UART sensor.void onTimeOut(): Runs if no reply from Urm_UART for the customized duration.void onRequestDistance(byte theAddress, int theDistance): Runs when distance reply is received;theDistanceis in mm.void onRequestTemperature(byte theAddress, float theTemperature): Runs when temperature reply is received;theTemperatureis in °C.void onRequestMaxDistance(byte theAddress, int theMaxDistance): Runs when max distance reply is received;theMaxDistanceis in mm.void onSetMaxDistance(byte theAddress, boolean isOperationSuccess): Runs after setting max distance;isOperationSuccessindicates success.void onSetBaudrate(byte theAddress, boolean isOperationSuccess): Runs after setting baudrate;isOperationSuccessindicates success.void onSetAddress(byte theAddress, boolean isOperationSuccess): Runs after setting address;isOperationSuccessindicates success.void onWrongStack(): Runs if wrong command is received.void commandProcess(): Processes the received states and calls corresponding callback functions.void setup(): Initializes the URM_UART sensor with default baudrate.void loop(): CallscommandProcess()and sends distance request every 1 second.urm.begin(DefaultBaudrate): Initializes the URM_UART sensor with the specified baudrate.urm.requestDistance(DefaultAddress): Sends distance request to the sensor with default address.urm.requestTemperature(DefaultAddress): Sends temperature request to the sensor with default address.urm.requestMaxDistance(DefaultAddress): Sends max distance request to the sensor with default address.urm.setAddress(DefaultAddress): Sets the sensor address.urm.setBaudrate(DefaultAddress, DefaultBaudrate): Sets the sensor baudrate.urm.setMaxDistance(DefaultAddress, DefaultMaxDistance): Sets the sensor max distance.
Principle
Ultrasonic sensors emit ultrasonic pulses, and by measuring the time of ultrasonic pulse reaches the object and back to the transducer, the distance of sensor from the target object is calculated. They are widely used in detecting displacement, thickness, distance, water level, material level and transparent objects.
Other Supplementary Information
document
Was this article helpful?
