Example Code for Arduino-Read Distance (Cascade)

Last revision 2025/12/17

Set different address first: 0x11; 0x22; 0x33; 0x44 Leonardo GPIO Power Supply. (40mA) Default Baudrate: 119200 bps Code Description: Cascade Connection: Temperature & Distance measurement, the received data is not verified

Hardware Preparation

  • DFRduino UNO (or similar) x 1
  • URM07-UART Ultrasonic Sensor xn
  • M-M/F-M/F-F Jumper wires

Software Preparation

  • Arduino IDE Click to Download Arduino IDE from Arduino®

Wiring Diagram

URM07 Cascade Connection

Other Preparation Work

  1. With a single URM07 module, a generic device address 0xAB can be used instead if the device address is unknown.
  2. Before the power on the URM07 module is not started, set the TX port to high and lower the RX port, and maintaining more than 1s can enable the module parameters to revert to factory settings.
  3. After the factory reset, the module can not start normally to enter a normal communication state, the on-board LED light flash with 10Hz. The module starts normally when powered back on.
  4. After the module is started, the module on-board LED only lights up the indication during the process of receiving the data and processing, and the LED goes out when in the standby state.

Sample Code


// # Author: [email protected]
// # Date: 20.08.2016
// # Product Name: URM07-UART Ultrasonic Sensor
// # SKU: SEN0153
// # version number: 1.0
// # Code Description: Cascade Connection: Temperature & Distance measurement, the received data is not verified

// # Connection: Arduino LEonardo GPIO Power Supply
// # Pin VCC (URM07 V1.0) -> D3     (Arduino Leonardo)
// # Pin GND (URM07 V1.0) -> D2     (Arduino Leonardo)
// # Pin  RX (URM07 V1.0) -> TX1/D1 (Arduino Leonardo)
// # Pin  TX (URM07 V1.0) -> RX1/D0 (Arduino Leonardo)

unsigned char i=0,j=0;
unsigned int  Distance=0;
unsigned char Rx_DATA[8];
unsigned char CMD[4][6]={
                         {0x55,0xAA,0x11,0x00,0x02,0x12},
                         {0x55,0xAA,0x22,0x00,0x02,0x23},
                         {0x55,0xAA,0x33,0x00,0x02,0x34},
                         {0x55,0xAA,0x44,0x00,0x02,0x45},
                        }; //Distance Measurement Package

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);  //Ultrasonic Sensor VCC
  digitalWrite(2, LOW);   //Ultrasonic Sensor GND
  Serial1.begin(19200);  //Serial1: Ultrasonice Sensors Serial Communication Port, baudrate: 19200
  Serial.begin(19200);   //Serial: USB Serial Monitor
}

void loop() {
  for(j=0;j<4;j++)
  {
 for(i=0;i<6;i++){
    Serial1.write(CMD[j][i]);
    }
 delay(150);  //Wait returned result
 i=0;
 while (Serial1.available()){  //Read Returned Value (This demo is only for reference, no data verification)
    Rx_DATA[i++]=(Serial1.read());
    }
 Distance=((Rx_DATA[5]<<8)|Rx_DATA[6]); //Read distance value
 Serial.print("URM07-UART module[");   //print distance
 Serial.print(j);
 Serial.print("]get_Dis= ");
 Serial.print(Distance);
 Serial.println("cm");
  }
 Serial.print("\r\n\r\n");
}

Result

URM07 Cascade

Was this article helpful?

TOP