Novedad: el cortafuegos de IA supervisa toda la plataforma y explica cada incidente con palabras sencillas. Vea cómo funciona

El sensor ultrasónico impermeable JSN-SR04T en una Pi 3 da 0 cm o timeouts para el depósito de agua de nuestra residencia

El sensor ultrasónico impermeable JSN-SR04T en una Pi 3 da 0 cm o timeouts para el depósito de agua de nuestra residencia

Resuelto 9 7

Traducido del English por IA ·

Hola a todos, soy estudiante, mi primer proyecto de verdad. El depósito de agua elevado de nuestra residencia se queda sin agua cada pocos días y el encargado quiere un aviso. Tengo una Raspberry Pi 3 en el techo (dentro de una caja) y un sensor ultrasónico impermeable JSN-SR04T v2.0 apuntando hacia abajo, al interior del depósito.Usé el código estándar de Python del HC-SR04 con RPi.GPIO: disparo de 10 us y luego bucles while que esperan a que el eco pase a alto y a bajo. El eco pasa por un divisor 1k/2k. Resultados: alrededor de la mitad de las lecturas son 0.0 cm, el resto son timeouts y muy raramente un valor real como 87 cm. Con un HC-SR04 en la mesa de pruebas, el mismo código funciona perfectamente.

dist: 0.0
dist: timeout
dist: timeout
dist: 87.4
dist: 0.0

Cuando funcione, quiero enviar el nivel a Hermetry y recibir una alarma cuando esté bajo.

♥ 0

Traducido del English por IA ·

Divisor en el echo, bien. ¿A qué distancia está el sensor del agua cuando el depósito está lleno?

Ground loops are my cardio.
♥ 0

Traducido del English por IA ·

El depósito está lleno ahora, quizás 15-20 cm?

♥ 0

Traducido del English por IA ·

¿Qué versión de placa aparece impresa en la tuya? La v2 y la v3 se comportan de forma diferente.

Timestamps in UTC or it didn't happen.
♥ 2

Traducido del English por IA ·

En la parte trasera dice JSN-SR04T-2.0.

♥ 0

Traducido del English por IA ·

¿Quizás añadir un time.sleep(0.5) entre lecturas? Leí que necesitan tiempo para estabilizarse.

Measure twice, poll once.
♥ 0

My pool sensor did weird stuff when there was condensation on the face, worth wiping it.

♥ 0

The JSN has a blind zone of roughly 20-25 cm. Anything closer and it either returns nonsense or nothing. HC-SR04 goes down to 2 cm, that’s why the bench test lies to you.

Modbus is just registers until it isn't.
♥ 0

Jessica nailed the main issue: at 15-20 cm you’re inside the blind zone. Mount it higher, a short PVC pipe section as a stand-off works, so full tank is at least 30 cm away.

Second issue is the Python timing. Busy-wait loops on a Pi 3 miss edges whenever the scheduler steps in. Use gpiozero with the pigpio pin factory, it timestamps edges in the daemon:

from gpiozero import DistanceSensor
from gpiozero.pins.pigpio import PiGPIOFactory
import statistics, time

s = DistanceSensor(echo=24, trigger=23, max_distance=4.5,
                   pin_factory=PiGPIOFactory())

def level_cm():
    vals = []
    for _ in range(7):
        vals.append(s.distance * 100); time.sleep(0.1)
    return statistics.median(vals)

Median of 7 throws away the odd echo off the tank wall. Then send {"distance_cm": d, "level_pct": ...} as numbers and put an alarm rule on level_pct below 20 with a debounce of 3 readings, so one bad echo doesn’t wake the warden.

Solución aceptada♥ 3

Raised it on a 20 cm pipe piece and switched to your gpiozero code. Now steady readings, 43-45 cm when full, no zeros. Alarm rule is set at level_pct < 20 with 3 readings. Warden got his first real warning yesterday at 6 am.

♥ 1
Viendo 10 entradas – de la 1 a la 10 (de un total de 10)
  • Debes estar registrado para responder a este debate.

Únete a la conversación

Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

Compartir