Introduction
If you want to measure distances in outdoor environments or water-related projects, the ESP32 JSN-SR04T waterproof ultrasonic sensor is an excellent solution. Unlike the standard HC-SR04, which struggles in wet or dusty conditions, the JSN-SR04T is fully waterproof and built for rugged use.
In this guide, we’ll walk step by step through wiring the sensor with the ESP32, writing Arduino code to read distances, and exploring practical applications like water-level monitoring. By the end, you’ll be able to confidently integrate the JSN-SR04T with your ESP32 projects.
What is the JSN-SR04T Ultrasonic Sensor?
The JSN-SR04T is a waterproof version of the popular ultrasonic distance sensor. It works by sending an ultrasonic pulse and measuring the time it takes for the echo to return. From this, it calculates the distance to an object.

Key Features:
Feature | Value |
---|---|
Operating Voltage | 5V |
Measuring Range | 20cm – 600cm |
Accuracy | ±3mm |
Interface | Trigger + Echo pins |
Waterproof | Yes (sensor head) |
Compared to the HC-SR04, the JSN-SR04T is designed for outdoor and liquid environments, making it suitable for tank water-level monitoring, parking sensors, and automation projects.
For deeper technical details, you can check the official JSN-SR04T datasheet (PDF).
Working Principle of JSN-SR04T
The JSN-SR04T works similarly to the HC-SR04:
- Trigger Pulse: The ESP32 sends a 10µs HIGH pulse to the sensor’s TRIG pin.
- Ultrasonic Wave Emission: The transducer emits an ultrasonic wave.
- Echo Detection: If an object is in range, the wave reflects back and is captured by the sensor.
- Time Measurement: The time between sending and receiving is measured.
- Distance Calculation: The sensor calculates the distance using the formula:
The division by 2 is because the sound wave travels to the object and back.
Why Use ESP32 with JSN-SR04T?
The ESP32 is a powerful Wi-Fi + Bluetooth microcontroller, making it ideal for IoT projects. Pairing it with the JSN-SR04T allows you to:
- Build wireless water-level monitoring systems
- Use it in IoT dashboards for distance data logging
- Create smart automation projects that respond to distance
👉 If you’re new to ESP32, check our beginner’s guide on using OLED with ESP32 for display integration.
Components Required
To follow this tutorial, you’ll need:
- ESP32 development board
- JSN-SR04T waterproof ultrasonic sensor
- Jumper wires
- Breadboard (optional)
Circuit Diagram – ESP32 and JSN-SR04T
The JSN-SR04T uses a Trigger and Echo pin, just like the HC-SR04.
Connections:
JSN-SR04T Pin | ESP32 Pin |
---|---|
VCC | 5V |
GND | GND |
TRIG | GPIO 5 |
ECHO | GPIO 18 |

⚠️ Important Note: The ECHO pin outputs 5V. Since ESP32 GPIOs are 3.3V tolerant, use a voltage divider (two resistors, e.g., 1kΩ + 2kΩ) to step down the signal.
Arduino Code for ESP32 JSN-SR04T
Here’s a simple sketch to read distance values:
#define TRIG_PIN 5
#define ECHO_PIN 18
long duration;
float distance;
void setup() {
Serial.begin(115200);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
// Clear trigger
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
// Send 10us pulse
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read echo time
duration = pulseIn(ECHO_PIN, HIGH);
// Calculate distance (speed of sound = 343 m/s)
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000);
}
This will print the measured distance to the Serial Monitor. Example:

Common Issues and Fixes
- No readings: Double-check wiring, especially the voltage divider on the Echo pin.
- Unstable readings: Add a delay and average multiple measurements.
- ESP32 resetting: Power the JSN-SR04T from a stable 5V source, not from USB if servo/motors are also powered.
Applications of ESP32 JSN-SR04T Waterproof Ultrasonic Sensor
Here are some real-world use cases:
- Water level monitoring in tanks
- Smart parking assistance systems
- Outdoor weather-resistant distance sensors
- Robotics for rugged environments
Real-World Example: IoT-Based Water Tank Monitoring
Want to see this in action? Check out our full guide on the IoT-Based Water Tank Monitoring System using JSN-SR04T and ESP8266. It walks through:
- How the JSN-SR04T is mounted at the top of a water tank.
- Distance readings are converted into tank fill levels.
- Real-time monitoring via a web dashboard and pump automation.
This is a fantastic real-world demo of how the JSN-SR04T waterproof ultrasonic sensor works in a water tank monitoring system. While the project is built with ESP8266, the same concept can be easily adapted for ESP32 to take advantage of its higher processing power and built-in features.
Conclusion
Using the ESP32 JSN-SR04T waterproof ultrasonic sensor is one of the most reliable ways to measure distances in outdoor or liquid environments. With its simple wiring, easy Arduino code, and waterproof design, it’s a great alternative to the HC-SR04 for demanding projects.
Whether you’re building a DIY water-level monitor, a parking sensor, or just experimenting, this sensor paired with the ESP32 makes your projects smarter and more robust.