DIGITALI2CUARTONEWIREbeginner

Ultrasonic Distance Sensor

Distance by echo timing, on an RCWL-9616 that runs from 3 to 5 V and speaks GPIO, I2C, UART or 1-Wire, chosen by two solder jumpers. No divider on a 3.3 V board. Soft and angled surfaces are where it quietly lies to you.

Comes in this kit — not sold separately

Specifications

Sensing elementRCWL-9616 ranging chip with a 16 mm, 40 kHz transmitter and receiver (Huayu HY40A16T12-1 and HY40A16R12-1)
Supply voltage3 to 5 V, printed 3-5V over the VCC hole. No regulator, so the signals run at whatever you feed it
Supply current2 to 3 mA typical at 5 V; the listing rates it at 15 mA. The power LED adds under a milliamp
InterfacesGPIO, I2C, UART and 1-Wire, chosen by two solder jumpers, J1 and J2. Both open, as shipped, is GPIO
Pins to wire4 in GPIO, I2C and UART; 3 in 1-Wire, where TRIG carries everything and ECHO is unused
I2C address0x57 in the supported library, with nothing on the board to change it
UART9600 baud in the supported library
Range2 cm to about 3 m; 4 m in ideal conditions
RANGE jumperOpen as shipped. The chip maker's note gives 3 to 5 m typical with it open and 5 to 6 m bridged, for its own transducers; not measured on this board
AccuracyAbout ±1 cm under a metre, resolving about 0.3 cm
Beam angle70 ± 5 degrees wide at -6 dB for each transducer (datasheet); narrower for a small or soft target
Measurement cycle50 ms in GPIO mode, 100 ms on a bus
Operating temperature-25 to 60 °C, the transducers' rating
Header4-pin right-angle male, 2.54 mm pitch, on the chip side: GND, 3-5V, ECHO/SDA/TX, TRIG/SCL/RX, with GND on the square pad
Board46.4 × 22.4 mm, two round mounting holes 32 mm apart. The transducers stand 12 mm off the front

What it is

A 40 kHz burst goes out, bounces off whatever is in front of the board, and comes back. The time between is proportional to distance: halve it, multiply by the speed of sound, and you have centimetres.

What makes this board different from the sensor it is named after is the chip doing that work. An RCWL-9616 runs from 3 V to 5 V and can hand you the result four different ways, where the classic HC-SR04 is a 5 V part with one interface. The board prints its own supply range over the VCC hole: 3-5V.

There is no regulator and no level shifter here. VCC goes straight to the chip, and both signal pins are chip pins brought out to the header, so the logic level is whatever you feed the supply. On an ESP32 that means the 3V3 rail and four plain wires — no divider.

Drag to turn it
The TK50. The transducers are on one face; the chip, the mode jumpers and the hole names are on the other. Turn it over for the back.

The four modes

Two solder jumpers on the left edge of the back, J1 and J2, decide which protocol the sensor speaks. Both arrive open, which is GPIO: trigger and echo, the way an HC-SR04 works.

ModeJ1J2ECHO becomesTRIG becomes
GPIOopenopenEcho pulseTrigger
I2CshortopenSDASCL
UARTopenshortTXRX
1-WireshortshortunusedData

The table is printed on the board itself. J2 is the upper pad.

A third jumper, printed RANGE, sits at the right. It shorts out a 2.2 kΩ resistor between the chip and one transducer, and it ships open. The chip maker's note puts the typical maximum at 3 to 5 m with the resistor and 5 to 6 m without it, for its own transducers; nobody has measured this board either way.

The back of the TK50: a MODE J1 J2 table at the top left with rows GPIO cross cross, I2C tick cross, UART cross tick and 1WIRE tick tick; two solder jumpers labelled J2 above J1 on the left edge; a boxed TK50 ULTRASONIC DISTANCE SENSOR; a sixteen-pin chip at the top right; a jumper labelled RANGE at the right; and a right-angle header along the bottom labelled GND, 3-5V, ECHO/SDA/TX and TRIG/SCL/RX, GND on the square pad.
The back: the mode table, J1 and J2, RANGE, and the four holes by name.

Pinout

Left to right on the back, pins pointing down. GND is the square pad.

PrintedGPIOI2CUART1-Wire
GNDGroundGroundGroundGround
3-5V (VCC)3–5 V3–5 V3–5 V3–5 V
ECHO/SDA/TXEchoSDATXnot used
TRIG/SCL/RXTriggerSCLRXData

Wiring

Four wires. GND to GND, VCC to 3V3 on a 3.3 V board or 5V on an Uno, and the two signals to any two pins. The four pads you can see on the front are the same header holes from the other side, so the order reads backwards there.

Example

GPIO mode, no library. Note the timeout on pulseIn: without it a missing echo blocks the sketch for a full second and then reads as zero centimetres.

ultrasonic_sensor.ino
#define TRIG 9
#define ECHO 10

void setup() {
  Serial.begin(115200);
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  digitalWrite(TRIG, LOW);
}

void loop() {
  // The supported library holds TRIG high for 500 us, so this does too.
  // Every HC-SR04 example uses 10 us.
  digitalWrite(TRIG, HIGH); delayMicroseconds(500);
  digitalWrite(TRIG, LOW);

  // Time out at ~4 m of round trip. Without a limit, a missing echo blocks
  // for a full second and then reads as a valid measurement of nothing.
  long us = pulseIn(ECHO, HIGH, 25000UL);

  if (us == 0) {
    Serial.println("no echo");        // absorbed, angled away, or out of range
  } else {
    Serial.print((us / 2.0) * 0.0343, 1);   // cm at about 20 C
    Serial.println(" cm");
  }

  delay(100);   // A measurement cycle is 50 ms. Let the last burst die away.
}
View on GitHub · blocks/tk50-ultrasonic-sensor/arduino/ultrasonic_sensor/ultrasonic_sensor.ino @ v1.13

Over a bus

In I2C or UART mode the chip does the timing and the arithmetic, and hands back three bytes holding the distance in micrometres, most significant byte first. Divide by 10 000 for centimetres.

The command is one byte — 0x01 over I2C at address 0x57, or 0xA0 over UART at 9600 baud — then a wait of about 150 ms, then three bytes back. There is no register map and no status flag. Those numbers are the supported library's, written for the RCWL-9610A on the earlier board; the RCWL-9616's maker names the same four modes on the same pins.

Where to start

The handbook below takes the part from the first reading to the four modes and what it can honestly see. If you only read one page, make it the honest range: the 4 m on the box and the 2–3 m you should design to are both true, and the difference is what surfaces do to 40 kHz sound.

When it doesn’t work

The listing says HC-SR04. Is this an HC-SR04?
Not electrically. The chip is an RCWL-9616, which runs from 3 V and speaks four protocols where an HC-SR04 needs 5 V and speaks one. In GPIO mode it has the same four pins doing the same jobs, so an HC-SR04 sketch is a starting point — but the wiring advice written for an HC-SR04 does not apply, starting with the voltage divider.
Do I need a voltage divider on the ECHO line for an ESP32?
No. There is no regulator and no level shifter on this board, so the signal pins answer at whatever you feed VCC. Power it from the 3V3 rail and ECHO comes back at 3.3 V, straight into the pin. Powering it from 5V on a 3.3 V board is what would create the problem.
It reads zero, or a huge number, at random.
No echo came back. Soft or angled surfaces do this, and so does anything closer than 2 cm. Treat a timeout as 'unknown' rather than as a distance, and take the median of three readings.
Can I put two of them on one I2C bus?
No. The address is 0x57 and there is no pad or register to change it, so two sensors answer at once and neither reading survives. Give each sensor a pair of GPIO pins, or one pin each in 1-Wire mode.
Readings are consistently a few per cent out.
Temperature. The speed of sound changes about 0.6 m/s per degree, so a reading calibrated at 20 °C is out by roughly 3 % at 5 °C. Correct for it if the accuracy matters.
Which pin is the data wire in 1-Wire mode?
TRIG, not ECHO. The single wire carries the trigger out and the answer back on the pin marked TRIG/SCL/RX, and the ECHO pin is unused. This is the most common way to wire this board wrong.
What does the RANGE jumper do?
It shorts out a 2.2 kΩ resistor between the chip and one transducer. It ships open. The chip maker's note says bridging it takes a typical maximum from 3 to 5 m up to 5 to 6 m with its own transducers; nobody has measured that on this board, so leave it open unless you need the reach and can test it.

The TK50 ultrasonic handbook

11 articles · about 55 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

Sound, and the time it takes

2 articles

What the sensor actually measures, and why the part in this box is not the HC-SR04 its own listing is named after.

What is in the box

2 articles

Five identical boards, four pins, and the twelve lines that get a distance out of the first one.

Two bridges choose the protocol

2 articles

The table printed on the back of the board, what the J1 and J2 pads are actually wired to, the third jumper marked RANGE, and why the same two pins change name four times.

Asking over a bus

2 articles

One byte out, three bytes back, and the surprise that they are micrometres. Then which of the four modes a given project actually wants.

What it can honestly see

3 articles

The blind zone, the range worth designing to, the degrees per second of drift nobody mentions, and what to check when every reading is zero.

Edit this page — content/modules/ultrasonic-sensor.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Ultrasonic Distance Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →