Distance
Interfacing JSN SR04T Distance with Raspberry Pi
What is the JSN SR04T?
JSN SR04T practical reference
A sealed, probe-style ultrasonic sensor built for liquid-level sensing and outdoor robotics where the open-faced HC-SR04 won't survive. Unlike the exposed dual-transducer face of an HC-SR04, the JSN-SR04T's transducer is embedded in a waterproof probe connected to the driver board by a cable, letting it be mounted through a tank lid or exposed to rain and moisture while the electronics stay protected — making it the standard choice for DIY water tank level monitors and outdoor obstacle-avoidance robots.
Key specifications
- Sensor type: Waterproof probe-style ultrasonic ranging sensor with separate driver board
- Operating voltage: 5 V DC (some variants accept 3.3-5.5V)
- Operating current: ~8 mA typical, ~30 mA during ranging pulse
- Measuring range: 20cm to 600cm (varies slightly by revision, some rated to 450cm)
- Blind zone: ~20-25cm minimum detection distance — objects closer than this are not reliably detected
- Probe design: Waterproof transducer housed in a sealed metal/plastic probe on a cable, separate from the driver PCB
- Interface: Trigger/Echo pulse mode (HC-SR04-compatible timing) on most revisions; some variants also support UART mode
- Beam angle: Narrower than the HC-SR04, which helps reduce false echoes in a tank but also means careful aiming
Pinout and connection notes
Code and wiring are largely identical to a standard HC-SR04 in pulse mode, but the 20-25cm minimum blind zone is significantly larger, so mount the probe with enough clearance from the closest expected surface (e.g. the bottom of an empty tank). Because the transducer sits inside a probe, some condensation or splashing near the tip is fine, but the driver PCB itself should still be kept dry and away from direct water exposure.
- VCC: Power, 5V DC (check your specific revision for 3.3V tolerance)
- Trig: Trigger input — send a short pulse to start a ranging cycle
- Echo: Echo output — pulse width proportional to round-trip time
- GND: Ground
Integration checklist
- Confirm the exact part number and breakout-board revision.
- Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
- Check controller pin assignments and bus address or interface mode against the example code.
- Power up with external loads disconnected, then test signals before full integration.
- If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.
Troubleshooting and reproducibility
Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.
Setting Up JSN SR04T with Raspberry Pi
Library
RPi.GPIO
Usually preinstalled on Raspberry Pi OS; otherwise: sudo apt install python3-rpi.gpio
Wiring
| Component pin | Raspberry Pi pin | Note |
|---|---|---|
| VCC | 5V (physical pin 2) | |
| Trig | GPIO23 (physical pin 16) | |
| Echo | GPIO24 (physical pin 18, through a divider) | Echo swings to 5V — Pi GPIOs are not 5V-tolerant, so a divider (e.g. 1kΩ/2kΩ) here is mandatory, not optional |
| GND | GND |
Swipe sideways to see every column →
- The voltage divider on Echo is mandatory — this is one of the more common ways people damage a Pi GPIO with an ultrasonic sensor, since Pi pins aren't 5V-tolerant.
- Same blind-zone and waterproofing caveats as the other boards.
- Software timing in Python is less precise than a microcontroller's; if you need tighter accuracy, consider offloading the pulse timing to a cheap microcontroller and reading the result over serial instead.
Related Components
GP2Y0A21
Analog IR distance sensor for obstacle detection at 10-80cm range — reliable and well-documented.
HC-SR04
The most reliable ultrasonic distance sensor — measure 2cm to 4m with just two GPIO pins.
US 100
HC-SR04 alternative with temperature compensation and optional UART mode for better consistency.
VL53L0X
A tiny laser time-of-flight ranger that measures distance in millimetres over I²C, accurate to a few percent and far narrower than ultrasonic.
Related Guides & Projects
Raspberry Pi Pico W and Pico 2 W: Install MicroPython with Thonny or UF2
Hold BOOTSEL, drag the correct UF2 file, open the REPL and blink the onboard LED. Includes the Pico vs Pico W vs Pico 2 W firmware differences and what to do when the drive does not appear.
Raspberry Pi Pico W Web Server in MicroPython: Control an LED and Read a Sensor
Connect the Pico W to WiFi, serve a responsive control page, switch an LED and display the onboard temperature or an external sensor, with timeouts and reconnect handling.
Raspberry Pi Pico Oscilloscope with MicroPython
Convert a Raspberry Pi Pico into a basic 500 kSPS oscilloscope using its 12-bit ADC and MicroPython. Displays waveforms on an SSD1306 OLED or streams samples over USB serial to a Python plotter on your PC.
Self-Hosted Nextcloud NAS on Raspberry Pi 4
Build a private, durable Nextcloud NAS on a Raspberry Pi 4 -- SSD boot instead of a failure-prone SD card, Docker Compose with Redis caching, Tailscale for remote access with zero ports forwarded, and an automated backup strategy that actually runs.