URM14-RS485 Ultrasound sensor problem with Arduino IDE

userHead Nazim.Berrichi 2024-03-02 02:16:23 255 Views9 Replies



I used the code on the DFRobot website and had the same setup ( , and the sensor is connected to a power supply which gives me 12.5 V. 

I am getting the following error:

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

avrdude done. Thank you.

I have linked the full error message, the serial monitor output, the parameters used, and the setup I have. What could cause this problem?


2024-03-06 17:08:09

Ops, I apologize for looking at the wrong sensor. If you are using the URM14. Things get a little more complicated.


This is because the URM14 sample code uses the ArduinoModbus library inside. But this library forces HardwareSerial at the bottom and also your print calls HardwareSerial, so this library is not very compatible on Arduino MEGA.

So currently there are two ways to help you to solve this problem quickly:
1. Check the communication protocol of URM14 and write your own Arduino code that uses Serial1 to interact with URM14.
2. or you can just buy Arduino Leonardo. because Leonardo is responsible for print serial port which is different from hard serial port.
So you can use DFRobot sample code directly.

userHeadPic Yeez_B
Alexandre.Robichaud wrote:

I've gathered all the necessary equipment for the DFRobot's URM14 sensor as indicated in their sample code. Despite this, I consistently face a timeout error when I invoke the holdingRegisterWrite() or requestFrom() methods from the ModbusRTUClient class, even when addressing the default Public address 0x00. Would you be able to assist me, M. Yeez_B? Below are the code snippets and the corresponding output from the serial monitor that I am working with.

    This code tests the address modification function of the URM14 ultrasonic sensor
    @ author : [email protected]
    @ data   : 11.08.2020
    @ version: 1.0
    RX(TTL-RS485转接板) -> TX1/D1 (Arduino Leonardo)  TX(TTL-RS485转接板)-> RX1/D0 (Arduino Leonardo)
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>

#define   PUBLIC_ADDR               ((uint16_t)0x00)
#define   SLAVE_ADDR                ((uint16_t)0x14)

#define   TEMP_CPT_SEL_BIT          ((uint16_t)0x01)
#define   TEMP_CPT_ENABLE_BIT       ((uint16_t)0x01 << 1)
#define   MEASURE_MODE_BIT          ((uint16_t)0x01 << 2)
#define   MEASURE_TRIG_BIT          ((uint16_t)0x01 << 3)

typedef enum{ 
 /*2*/eAddr, //The Module Address Register, used for setting the sensor's address on the network, can be read and written to.
 /*3*/eComBaudrate,//Serial Parameter Control Registers configure communication parameters like baud rate and parity
 /*5*/eDistance, //The Distance Register stores the measurement result from the sensor.
 /*6*/eInternalTempreture,//Onboard Temperature Data Register provides the internal temperature
 /*7*/eExternTempreture,//The External Temperature Compensation Data Register allows for temperature compensation to improve accuracy.
 /*8*/eControl,//The Control Register, which controls measurement triggering and operating modes.
 /*9*/eNoise //Electrical Noise Level Register indicates the noise level affecting measurements.
}eRegIndex_t;//Sensor register index

*@brief Read data from holding register of client
*@param addr : Address of Client
*@param reg: Reg index
*@return data if execute successfully, false oxffff.
uint16_t readData(uint16_t addr, eRegIndex_t reg)
 uint16_t data;
 if (!ModbusRTUClient.requestFrom(addr, HOLDING_REGISTERS, reg, 1)){
   Serial.print("failed to read registers! ");
   data = 0xffff;
   data =;
 return data;

*@brief write data to holding register of client 
*@param addr : Address of Client
*@param reg: Reg index
*@param data: The data to be written
*@return 1 if execute successfully, false 0.

uint16_t writeData(uint16_t addr, eRegIndex_t reg, uint16_t data)
 if (!ModbusRTUClient.holdingRegisterWrite(addr, reg, data)){
   Serial.print("Failed to write coil! ");
   return 0;
   return 1;

float  dist;
volatile uint16_t cr = 0;

void setup() {
volatile uint16_t newAddr, res;

void loop() {
 //newAddr = 0x14;
 //res = writeData(PUBLIC_ADDR, eAddr, newAddr);//Writes the new address value to the register
 //if (res)Serial.println("finally I can write");
 //Serial.print("The device address has been modified as ");
 //Serial.println(".please reset the device!");
 //while (1);
 cr |= MEASURE_TRIG_BIT;//Set trig bit = 8 to trigger a measurement. 
 writeData(PUBLIC_ADDR, eControl, cr); //Write the value to the control register and trigger a ranging ONCE
 delay(31);//Delay of 300ms(minimum delay should be greater than 30ms) is to wait for the completion of ranging
 dist = (float)readData(PUBLIC_ADDR, eDistance) / 10;//Read distance register, one LSB is 0.1mm
 Serial.print("distance = ");
 Serial.print(dist, 1);


And the Serial monitor : 

Failed to write coil! Connection timed out
failed to read registers! Connection timed out
distance = 6553.5mm 

2024-03-11 02:56:24
Yeez_B wrote:

Right, this one is that the sample code is not compatible with MEGA.
You can only replace the controller (Leonardo) or modify the code yourself.

2024-03-11 17:08:35
Nazim.Berrichi wrote:

Hello, thank you for your response. We have indeed been using the arduino leonardo, with the shield directly on it, and still getting the same error. 



2024-03-12 01:29:50
Alexandre.Robichaud wrote:

I have the Arduino Leonardo. As previously mentioned, I have gathered all the necessary equipment. Could you please provide a more detailed answer on the matter?

2024-03-15 11:17:02
Yeez_B wrote:

If you get the same situation with Leonardo with the same wire connection. It should be a hardware failure of this URM14, you can seek after-sales service like the merchant you purchased it from.
BTW, is there some slight noise when the URM14 is powered? Usually the probe will make a slight "click" sound.

2024-03-18 16:09:07
Alexandre.Robichaud wrote:

No, there is no noticeable noise when the device is powered by a 9V source. However, it does become somewhat warm after being used for a short period. This could reinforce the notion that we may have a defective sensor. I have contacted technical support and am currently awaiting a response. I purchased the product directly from the DFRobot website.

2024-03-20 11:08:48
6 Replies
2024-03-06 06:37:15

Thank you for your response! 


I actually have the URM14, not the URM15 so I tried the wiring you were recommending but the sensor was powered by a power supply (12V) instead of the shield. 


I also changed all the ‘’Serial'' instances by ‘’Serial1'' (is that what you meant?). I no longer have uploading issue. 


However, the serial monitor is showcasing white squares instead of the distance. My baud rate is 9600 on the serial monitor, and it is the same in the void setup() function. Any idea on how to approach this?


Here is my code (wont let me copy paste it all): 

userHeadPic Nazim.Berrichi
2024-03-04 09:46:35

Since the RS485 shield is to convert RX0, TX1 to the 485 level so the best compatibility to this shield is using the Arduino leonardo then you could stack the shield and Arduino then connect to the URM15.



If you are using the Arduino MEGA or UNO, we suggest you to wire the Arduino and shield separately with jumper wire like the following image:

Then you need to change the serial port in the code that communicates with URM15 to Serial1.

userHeadPic Yeez_B