Gravity: URM09 Ultrasonic Sensor(Trig) Wiki - DFRobot


This is a non-contact ultrasonic ranging sensor of high-performance from URM09 series, employing standard PH2.0-3P Gravity vertical interface. It provides an accuracy of 1% within an effective measuring range of 2~500cm(test on a flat wall). Similar to SR04 ultrasonic ranging modules in principle and using method, the ranging function of this sensor is triggered by high/low level output from the I/O ports of a host, and then the sensor converts ultrasonic flight time into a high pulse to output. The difference is that the sensor multiplexes input and output signals onto one signal port, which allows users to easily use the sensor for distance measurement only by one I/O port of a controller. Meanwhile, the adoption of advanced hardware and software design ensures excellent and reliable measuring performance. The module works well with 3.3V/5V controllers like Arduino, Raspberry Pi, etc.
With features of small size, high accuracy, plug-and-play and wide measuring range, this module is applicale to an extensive range of applications, such as, robot obstacle avoidance, car backing annunciator, doorbell, metro safety line warning, etc.


Measuring Angle

Measuring Angle

Board Overview

Board Overview

Num Label Description
1 - Ground
2 + Power Input(3.3V-5.5V)
3 D Digital IO(TRIG/ECHO multiplexing, internally pulled-down)


Hardware Connection

Connect the sensor to your Arduino mainboard with a Gravity 3Pin digital sensor cable.

Connection Diagram

Timing Diagram

URM09 Ultrasonic Sensor(Gravity Trig) uses digital IO port to trigger distance measurement, and the tringger signal and received signal shares one pin by TMD(Time Division Multiplexing):

Timing Diagram

  1. The sensor is in input mode at this time, and the host needs to be set to output mode. Send 10us high pulse trigger signal from the host, and then change the host port status to input, wait for the sensor to return signal.

  2. The output high-level time of the sensor is equal to ultrasonic flight time(longest pulse width time: 35000us).

Arduino Programming

The mainboard outputs a high-level about tens of microseconds to trigger the sensor to start ranging. Then, the sensor will output a high-level pulse proportional to the ultrasonic flight time. The distance can be easily obtained after a simple calculation by detecting high-level time.


Sample Code

       This example is the ultrasonic distance measurement of the module.

       Copyright   [DFRobot](, 2020
       Copyright   GNU Lesser General Public License

       version  V1.0
       date  29/10/2020

#define    VELOCITY_TEMP(temp)       ( ( 331.5 + 0.6 * (float)( temp ) ) * 100 / 1000000.0 ) // The ultrasonic velocity (cm/us) compensated by temperature

int16_t trigechoPin = 11;
uint16_t distance;
uint32_t pulseWidthUs;
void setup() {
void loop() {
  int16_t  dist, temp;

  digitalWrite(trigechoPin,HIGH);//Set the trig pin High
  delayMicroseconds(10);     //Delay of 10 microseconds
  digitalWrite(trigechoPin,LOW); //Set the trig pin Low

  pinMode(trigechoPin,INPUT);//Set the pin to input mode
  pulseWidthUs = pulseIn(trigechoPin,HIGH);//Detect the high level time on the echo pin, the output high level time represents the ultrasonic flight time (unit: us)

  distance = pulseWidthUs * VELOCITY_TEMP(20) / 2.0;//The distance can be calculated according to the flight time of ultrasonic wave,/
                                                    //and the ultrasonic sound speed can be compensated according to the actual ambient temperature
  Serial.print(distance, DEC);

Expected Results


Programming on MakeCode

  1. Open MakeCode online editor. Website:
  2. Load URM09_Trig Makecode Library.
  3. Program as below:


  1. Compile and burn codes into your micro:bit.
  2. Check data on serial assistant.


For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get URM09 Ultrasonic Sensor(Gravity Trig) from DFRobot Store or DFRobot Distributor.

Turn to the Top