JSN-SR04T Waterproof Ultrasonic Distance Sensor
The JSN-SR04T is a waterproof ultrasonic distance sensor ideal for outdoor and industrial applications. With a measuring range of up to 6 meters and a durable build, it is perfect for detecting objects in harsh conditions. It operates using Trigger and Echo signals and is compatible with microcontrollers like Arduino and ESP32.

On this page
JSN-SR04T pinout
The JSN-SR04T has 4 pins using the trigger/echo mechanism for ultrasonic distance measurement.
| Pin | Type | Description | Notes |
|---|---|---|---|
| VCC | Power | Power supply input (5V). Requires stable 5V power. | Use regulated 5V supply for accurate measurements. |
| GND | Power | Ground connection. Connect to system ground. | |
| Trigger (TRIG) | Input | Trigger input. Send 10µs HIGH pulse to initiate measurement. | Connect to GPIO output pin. |
| Echo | Output | Echo output. Pulse width represents distance (58µs per cm). | Connect to GPIO input. Use voltage divider for 3.3V systems. |
Measurement range: 25cm to 600cm (6 meters)
Resolution: 0.5cm
Accuracy: ±1cm
Waterproof design (IP67 rated probe)
Operating frequency: 40kHz ultrasonic
Trigger: 10µs pulse initiates measurement
Wiring the JSN-SR04T to ESP32
To interface the JSN-SR04T with an ESP32, connect VCC to 5V, GND to ground, Trigger to GPIO 5, and Echo to GPIO 18 (through voltage divider for 3.3V protection).
| JSN-SR04T pin | ESP32 pin | Purpose |
|---|---|---|
| VCC | 5V | Power supply (5V). Use stable regulated power. |
| GND | GND | Ground connection. |
| Trigger | GPIO 5 | Trigger input. Send 10µs HIGH pulse to start measurement. |
| Echo | GPIO 18 | Echo output. Use voltage divider (1kΩ + 2kΩ) for 3.3V protection. |
WARNING: Echo pin outputs 5V - use voltage divider for ESP32 (3.3V)
Voltage divider: Echo → 1kΩ → GPIO18 → 2kΩ → GND
Trigger timing: Send 10µs HIGH pulse to initiate measurement
Distance calculation: Distance (cm) = Pulse duration (µs) / 58
Or: Distance (cm) = Pulse duration (µs) × 0.034 / 2
Waterproof probe: IP67 rated for outdoor use
Cable length: typically 2.5 meters between control board and probe
Use NewPing or Ultrasonic library for Arduino/ESP32
Measurement cycle: minimum 60ms between readings
Best accuracy: perpendicular flat surfaces, avoid soft materials
JSN-SR04T code examples
JSN-SR04T Arduino example
Copy#define TRIG_PIN 5
#define ECHO_PIN 18
void setup() {
Serial.begin(115200);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.println("JSN-SR04T Distance Sensor Example");
}
void loop() {
long duration;
float distance;
// Trigger the sensor
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read the Echo pin
duration = pulseIn(ECHO_PIN, HIGH);
// Calculate distance in cm
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}This Arduino sketch demonstrates how to use the JSN-SR04T sensor for distance measurement. The TRIG_PIN and ECHO_PIN are defined to connect the sensor to GPIO pins 9 and 10, respectively. The setup() function initializes these pins and configures the Serial Monitor. In the loop(), a 10 µs pulse is sent to the Trigger pin to start measurement, and the duration of the Echo pin’s HIGH state is measured using the pulseIn() function. The distance is calculated using the formula duration * 0.034 / 2, which converts the time into distance in centimeters.
JSN-SR04T ESP-IDF example
Copy#include <stdio.h>
#include "esp_rom_sys.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#define TRIG_PIN GPIO_NUM_5
#define ECHO_PIN GPIO_NUM_18
void app_main() {
gpio_set_direction(TRIG_PIN, GPIO_MODE_OUTPUT);
gpio_set_direction(ECHO_PIN, GPIO_MODE_INPUT);
while (1) {
// Send trigger pulse
gpio_set_level(TRIG_PIN, 0);
esp_rom_delay_us(2);
gpio_set_level(TRIG_PIN, 1);
esp_rom_delay_us(10);
gpio_set_level(TRIG_PIN, 0);
// Measure echo pulse width
uint64_t start_time = esp_timer_get_time();
while (!gpio_get_level(ECHO_PIN)); // Wait for HIGH
uint64_t echo_start = esp_timer_get_time();
while (gpio_get_level(ECHO_PIN)); // Wait for LOW
uint64_t echo_end = esp_timer_get_time();
uint64_t duration = echo_end - echo_start;
float distance = (duration * 0.034) / 2;
printf("Distance: %.2f cm\n", distance);
vTaskDelay(pdMS_TO_TICKS(500));
}
}This ESP-IDF code configures GPIO pins for the Trigger and Echo of the JSN-SR04T sensor. The gpio_set_level() function sends a 10 µs pulse to the Trigger pin. The time taken for the Echo pin to go HIGH and then LOW is measured using esp_timer_get_time(), which provides timestamps in microseconds. The distance is calculated based on the formula (duration * 0.034) / 2. The program continuously measures and prints the distance in centimeters every 500 ms.
JSN-SR04T ESPHome example
Copysensor:
- platform: ultrasonic
trigger_pin: GPIO5
echo_pin: GPIO18
name: "JSN-SR04T Distance"
update_interval: 500ms
accuracy_decimals: 1
timeout: 2.0mThe ESPHome configuration uses the ultrasonic platform to interface with the JSN-SR04T sensor. The trigger_pin and echo_pin specify the GPIO pins connected to the sensor. The name assigns a user-friendly identifier (‘JSN-SR04T Distance’) for use in platforms like Home Assistant. The update_interval of 500 ms specifies how often distance measurements are taken, while accuracy_decimals ensures measurements are displayed to one decimal place. The timeout prevents errors in case of no response within the specified time.
JSN-SR04T PlatformIO example
Copy[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200#include <Arduino.h>
#define TRIG_PIN 5
#define ECHO_PIN 18
void setup() {
Serial.begin(115200);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.println("JSN-SR04T Distance Sensor Example");
}
void loop() {
long duration;
float distance;
// Trigger the sensor
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read the Echo pin
duration = pulseIn(ECHO_PIN, HIGH);
// Calculate distance in cm
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}The PlatformIO code is identical to the Arduino example, making it compatible with ESP32 boards configured via the PlatformIO environment. It uses TRIG_PIN and ECHO_PIN for sensor operation. A short 10 µs pulse triggers the measurement, and the pulse duration is read on the Echo pin using the pulseIn() function. The calculated distance is printed to the Serial Monitor every 500 ms.
JSN-SR04T MicroPython example
Copyfrom machine import Pin, time_pulse_us
from time import sleep
# Define pins for Trigger and Echo
TRIG_PIN = 5
ECHO_PIN = 18
# Initialize Trigger and Echo pins
trig = Pin(TRIG_PIN, Pin.OUT)
echo = Pin(ECHO_PIN, Pin.IN)
def measure_distance():
# Send a 10 µs pulse to the Trigger pin
trig.low()
sleep(0.000002) # 2 µs
trig.high()
sleep(0.00001) # 10 µs
trig.low()
# Measure the duration of the Echo pulse
duration = time_pulse_us(echo, 1, 30000) # Timeout after 30 ms (no response)
# Calculate distance in cm (speed of sound = 343 m/s)
distance = (duration * 0.0343) / 2
return distance
print("JSN-SR04T Distance Sensor Example")
while True:
distance = measure_distance()
if distance > 0:
print("Distance: {:.2f} cm".format(distance))
else:
print("Out of range or no object detected.")
sleep(0.5)This MicroPython script interfaces with the JSN-SR04T sensor using Trigger and Echo pins. The Trigger pin sends a 10 µs pulse to initiate the measurement, while the Echo pin receives a pulse whose width corresponds to the distance measured. The time_pulse_us() function measures the duration of the Echo pulse in microseconds, with a timeout of 30 ms to prevent infinite waiting. The distance is calculated using the formula (duration * 0.0343) / 2, where 0.0343 cm/µs is the speed of sound. The script continuously measures and prints the distance to the console every 500 ms. If no response is detected, it prints an ‘Out of range’ message.
JSN-SR04T specifications
About the JSN-SR04T
The JSN-SR04T takes the HC-SR04’s familiar trigger/echo protocol and moves the actual transducer into a small waterproof probe on the end of a cable (commonly around 2.5 meters), so the control board can sit inside an enclosure while only the sealed probe faces rain, condensation, or a wash-down. Left in its default configuration it behaves exactly like a HC-SR04: a 10 microsecond TRIG pulse in, a proportional ECHO pulse out, the same timing code, the same 5V-to-3.3V voltage divider needed on ECHO for a safe ESP32 connection. Because the probe is larger and less sensitive up close than the HC-SR04’s exposed transducers, its blind zone is noticeably wider too - commonly cited at roughly 20 to 25 cm, versus about 2 cm for the plain HC-SR04.
Less commonly used but built into the hardware: a mode-select resistor (populated at a pad marked R27 on 2.0-series boards, or dedicated solder pads on 3.0-series boards) can switch the module out of trigger/echo mode entirely. Adding a 47 kOhm resistor puts it into a continuous serial mode, where it free-runs and streams a reading over its own output roughly every 100 ms with no trigger needed; a 120 kOhm resistor instead puts it into a command-polled mode that only reports when the host sends a specific query byte. Most boards ship configured for classic trigger/echo, which is what the wiring on this page assumes.
Specced range runs from the blind zone out to about 600 cm, well beyond the HC-SR04’s 400 cm ceiling, which is the other reason to reach for this part over the plain HC-SR04 even indoors. If a project can tolerate a tighter blind zone and a simpler always-on UART stream instead of trigger/echo timing, the waterproof A02YYUW is worth comparing against it directly.
JSN-SR04T troubleshooting
Sensor Returns Constant or Erroneous Readings
›
Issue: The JSN-SR04T sensor provides constant or incorrect distance measurements, regardless of the actual distance to the target.
Possible causes include incorrect wiring, insufficient power supply, or improper sensor configuration.
Solution: Ensure that the sensor is connected to a stable 5V power source, as it requires 5V for proper operation. Verify that the TRIG and ECHO pins are correctly connected to the appropriate GPIO pins on the microcontroller. Confirm that the sensor is properly initialized in your code, and that the trigger pulse duration is set correctly; some users have found that a 15-microsecond trigger pulse can improve reliability.
Inconsistent or Fluctuating Distance Measurements
›
Issue: The sensor outputs distance readings that vary significantly, even when the target distance remains constant.
Possible causes include environmental factors such as temperature variations, soft or angled target surfaces, or electrical noise.
Solution: Position the sensor perpendicular to a hard, flat target surface to ensure accurate reflections. Be aware that temperature changes can affect the speed of sound; consider implementing temperature compensation if precise measurements are required. Implement averaging of multiple readings in your code to mitigate occasional erroneous data.
Sensor Not Detected or Unresponsive
›
Issue: The microcontroller fails to detect the JSN-SR04T sensor, or the sensor does not respond to trigger signals.
Possible causes include incorrect pin assignments in the code, lack of proper initialization, or defective sensor module.
Solution: Double-check the pin assignments in your code to ensure they match the physical connections. Confirm that the sensor is properly initialized in the setup section of your code. If the issue persists, test the sensor with a known working setup or replace it to rule out hardware failure.
Interference from Environmental Factors
›
Issue: External factors cause the sensor to produce unreliable readings.
Possible causes include high ambient noise levels, temperature variations, or obstacles in the sensor's field of view.
Solution: Operate the sensor in a controlled environment to minimize acoustic and electrical noise. Ensure that there are no unintended obstacles within the sensor's detection range that could cause false readings.
Where to buy the JSN-SR04T

Resources
Similar sensors





