Parts

JSN-SR04T waterproof ultrasonic sensor

A waterproof ultrasonic ranger: a sealed probe on a cable, 20 cm to 6 m, read like an HC-SR04 or as serial frames.

This part has a page of its own, with a note on using it and a circuit to try: the part page.

The JSN-SR04T is a small control board and, on a long cable, one sealed probe in a rubber boot. The probe sends the 40 kHz burst and hears the echo with the same transducer, which is what lets it live in a water tank, a sump or a car bumper. It is also why the module is deaf for the first 20 cm: the transducer is still ringing from its own burst. The model follows the JSN-SR04T-3.0 datasheet. Aliases: waterproof ultrasonic sensor, JSN-SR04T-2.0, SR04T.

Pins

Pin What it does
5V Supply, 3.0 V to 5.5 V. A 3.3 V board runs it too.
TRIG Input. In pulse mode, high for 10 us or more fires a ping; in serial-command mode it is the module's RX.
ECHO Push-pull output. In pulse mode, high for the round trip; in the serial modes it is the module's TX, idling high.
GND Ground.

Properties

mode: what the mode pad on the board is set to.

mode On the board What it does
pulse Mode pad open (the default) HC-SR04 style: trigger on TRIG, time the pulse on ECHO.
serial-auto M1 shorted, or 47k on the pad Measures every 100 ms and sends a frame on ECHO.
serial-command M2 shorted, or 120k on the pad Measures once for each 0x55 byte sent to TRIG, then sends a frame.

A frame is four bytes at 9600 baud, 8N1: 0xFF, the distance's high byte, its low byte, and the low eight bits of the sum of the first three. The distance is in millimeters. The datasheet's own example is FF 07 A1 A7, 1953 mm.

temperature: the air in degrees Celsius, 20 by default. The echo travels at 331.3 + 0.606 T meters a second, as on the HC-SR04.

The target distance is not a property. It is set on the slider, 0 to 6.5 m.

While it runs

Drag the slider on the part to move the target. Nearer than 20 cm the readout says "blind zone"; past 6 m nothing comes back.

What the model gets right

  • Pulse mode is the HC-SR04's: a 10 us trigger, then ECHO high for the round trip, 58 us a centimeter at 20 °C. With no echo ECHO falls by itself after 40 ms, as the datasheet says. NewPing.h and plain pulseIn() both work.
  • The blind zone. Nothing is heard until the probe stops ringing, the time sound takes to go 20 cm and back. A target nearer than that reads as the edge of the blind zone, about 20 cm, never nearer. A sketch has to treat 20 to 25 cm as "too close", not as a distance; ESPHome's driver throws away anything under 25 cm for this reason.
  • The serial frames, their checksum, the 100 ms period of serial-auto and the 60 ms least gap between 0x55 commands of serial-command.
  • The module's arithmetic. The board works out millimeters at the datasheet's 348 m/s, about 28 °C, so in 20 °C air a wall a meter away reads 1013 mm in the serial modes. That is the module, not the model.

What it does not model

  • No sound is simulated: the slider is one number, not a tank to bounce sound around. The 75 degree beam, echoes off the tank's walls, foam, ripples and condensation on the probe are not modeled, and a reading has no jitter.
  • In the blind zone real boards read 20 cm or nonsense; the model gives the steady 20 cm edge, not the nonsense.
  • The delay from the trigger to ECHO rising is not in the datasheet; the model uses the HC-SR04's 460 us.
  • With nothing in range the serial modes send no frame; the datasheet does not say what a real board sends then.
  • The PWM-automatic, low-power and switch modes (200k, 360k and 470k on the mode pad) are not modeled.
  • Older 1.0 and 2.0 boards (mode resistor R27) are often reported to need a longer trigger, about 20 us. This is the 3.0 board, which takes 10 us.

Common mistakes

Mounting the probe too close to the highest water. Anything inside 20 cm reads about 20 cm, so a tank filled right up to the probe looks two thirds full. Mount the probe at least 25 cm above the highest the water can get.

Reading ECHO with Serial in pulse mode, or timing pulses in a serial mode. The mode pad decides which one the board speaks; set mode to match the sketch.

See it in action

The JSN-SR04T water tank level template reads the water from a tank lid with NewPing.h and prints how full it is. Open it at /templates.