General

JSN-SR04T ultrasonic sensor

userHead jurya.bject 2026-09-29 17:42:11 24 Views1 Replies

I am attempting to connect a waterproof JSN-SR04T ultrasonic sensor directly to the GPIO pins of my Raspberry Pi 5. Using the standard GPIO-based trigger/echo Python script, the sensor either hangs waiting for the echo signal or constantly reads maximum distance. Should I switch to the serial UART mode (mode 2) for Pi 5, or is there a specific pin configuration needed?

 https://github.com/DFRobot/DFRobot_RaspberryPi_A02YYU https://snowrider-2.io

2026-09-30 10:23:04

The hang / constant-max-distance almost always comes from the 5V echo pin going straight into a 3.3V-only Pi GPIO. The Pi can't read a 5V edge reliably (and it's risky for the GPIO), so the script either waits forever or times out to max distance.

Fix the echo level first: put a divider on ECHO — 1kΩ from ECHO to the GPIO, 2kΩ from the GPIO to GND (≈3.3V) — and confirm the sensor and Pi share a ground.

On mode 2 (serial): the 0x55 output is still 5V, so you still need that divider before Pi RX, and you also have to free Pi 5's UART — the serial console grabs UART0 by default, so disable it and enable the UART overlay. Serial removes the trigger-timing guesswork, but it doesn't remove the level-shifting requirement.

Also mind the JSN-SR04T dead zone: objects closer than ~20cm read as max/false, so test at 30–400cm.

userHeadPic Jason.Miao