Medir una batería de 12 V sin que el divisor la descargue, y una alarma de batería baja que parpadea con el sol
Traducido del English por IA ·
Dos problemas relacionados en nuestras estaciones de humedad del suelo (finca, 9 estaciones, cada una con una batería de plomo-ácido de 12 V 7 Ah y un panel de 10 W, ESP32 enviando a Hermetry cada 15 minutos).Hardware: mido la batería con un divisor, 100k sobre 22k, conectado a GPIO35. El divisor está siempre conectado, así que consume unos 0,1 mA, las 24 horas. No es mucho, pero en una semana gris de noviembre las estaciones ya se quedan sin batería, y cada poco cuenta. Quiero desconectar el divisor entre lecturas. En internet veo dos esquemas: uno con un único MOSFET de canal N en la parte inferior del divisor, y otro con un canal P en la parte superior controlado por un pequeño canal N. ¿Cuál es el correcto y por qué el segundo necesita dos transistores?Hermetry: tengo una regla de alarma de batería baja, battery_v < 11.8. Cada mañana soleada se activa y se desactiva tres o cuatro veces mientras el panel empieza a cargar. La gente ya empieza a ignorarla.
Two connected problems on our soil moisture stations (farm, 9 stations, each with a 12 V 7 Ah lead-acid battery and a 10 W panel, ESP32 sending to Hermetry every 15 minutes).
Hardware: I measure the battery with a divider, 100k over 22k, into GPIO35. The divider is always connected, so it draws about 0.1 mA, 24/7. Not huge, but in a dull week in November the stations already go flat, and every little bit counts. I want to switch the divider off between readings. I see two schematics online: one with a single N-channel MOSFET on the bottom of the divider, and one with a P-channel on top driven by a small N-channel. Which one, and why does the second need two transistors?
Hermetry: I have a low-battery alarm rule, battery_v < 11.8. Every sunny morning it fires and clears three or four times while the panel starts charging. People have started ignoring it.
Traducido del English por IA ·
¿Cuáles son los valores reales del divisor en su placa y qué lectura da el ADC del ESP32 a 12,6 V?
What are the actual divider values on your board, and what’s the ESP32’s ADC reading at 12.6 V?
Traducido del English por IA ·
100k arriba, 22k abajo. A 12,6 V obtengo unos 2,27 V en el pin, valor bruto alrededor de 2700.
100k top, 22k bottom. At 12.6 V I get about 2.27 V on the pin, raw around 2700.
Traducido del English por IA ·
Por el lado de Hermetry, comprueba que battery_v se envía como número. Ya he visto que se enviaba como texto «11.9V» y entonces nada funciona.
On the Hermetry side, check battery_v is sent as a number. I’ve seen it go out as «11.9V» text before and then nothing works.
Traducido del English por IA ·
El único canal N de abajo es más sencillo, yo simplemente haría eso.
The single N-channel on the bottom is simpler, I’d just do that.
Traducido del English por IA ·
Tengo el problema de la alarma intermitente con una batería de SAI en nuestro hotel, siguiendo este hilo.
I have the flapping alarm problem with a UPS battery at our hotel, following this.
Traducido del English por IA ·
¿Podría enviar el valor de la batería solo una vez por hora? Así no parpadeará tanto.
Could you only send the battery value once an hour? Then it can’t flap as much.
Traducido del English por IA ·
Aisha, el MOSFET único de lado bajo tiene una trampa con la que yo mismo me he topado. Cuando está apagado, la parte inferior del divisor queda flotando, y la resistencia superior lleva el pin ADC a los 12 V completos a través de 100k. Eso supera el límite de 3,3 V del ESP32; el diodo de protección del pin lo recorta y la corriente se filtra al riel de 3,3 V. Así que ahorras la corriente del divisor, pero fuerzas el pin.La versión con dos transistores conmuta la parte superior: un canal P (AO3401 o similar) entre la batería y el divisor, con la puerta llevada a la batería mediante 100k, de modo que está apagado por defecto. Un canal N pequeño (2N7000) controlado por un GPIO baja esa puerta para encenderlo. Necesitas el canal N porque un GPIO de 3,3 V no puede bajar con suficiente fuerza la puerta de un canal P que está a 12 V para apagarlo. Con la parte superior apagada, todo el divisor queda a 0 V, incluido el pin ADC.En el firmware: encender, esperar unos 10 ms, tomar 16 lecturas y promediarlas, apagar. Usa la lectura calibrada (analogReadMilliVolts) y envía battery_v como número con dos decimales.Para el parpadeo: la tensión de una batería de plomo-ácido salta cuando empieza la carga, así que un umbral simple siempre rebotará. Dale a la regla histéresis para que solo se libere bien por encima del umbral, y dos severidades:
{
"type": "battery_low",
"title": "{{device.name}}: battery {{value}} V",
"severities": [
{ "severity": "MAJOR", "condition": { "key": "battery_v", "op": "<", "value": 11.5 } },
{ "severity": "MINOR", "condition": { "key": "battery_v", "op": "<", "value": 11.8 } }
],
"hysteresis": 0.4,
"debounce": { "mode": "count", "raise": 2, "clear": 2 },
"notify": { "recipients": [ { "kind": "email", "email": "field-team@example.com" } ], "minSeverity": "MINOR" },
"enabled": true
}
Se activa por debajo de 11,8 y solo se desactiva en 12,2 o más, con dos lecturas seguidas. La idea de Kevin ocultaría el problema, no lo solucionaría. La histéresis y el debounce se explican en esta página.
Aisha, the single low-side MOSFET has a catch I’ve been bitten by. When it’s off, the bottom of the divider floats, and the top resistor pulls the ADC pin up to the full 12 V through 100k. That’s above the ESP32’s 3.3 V limit; the pin’s protection diode clamps it and current leaks into the 3.3 V rail. So you save the divider current and stress the pin instead.
The two-transistor version switches the top: a P-channel (AO3401 or similar) between the battery and the divider, gate pulled up to the battery with 100k so it’s off by default. A small N-channel (2N7000) driven by a GPIO pulls that gate down to switch it on. You need the N-channel because a 3.3 V GPIO can’t pull the gate of a P-channel sitting at 12 V high enough to turn it off. With the top switched off, the whole divider sits at 0 V, the ADC pin too.
In the firmware: switch on, wait about 10 ms, take 16 readings and average them, switch off. Use the calibrated reading (analogReadMilliVolts) and send battery_v as a number with two decimals.
For the flapping: a lead-acid battery’s voltage jumps when charging starts, so a plain threshold will always bounce. Give the rule hysteresis so it only clears well above the threshold, and two severities:
{
"type": "battery_low",
"title": "{{device.name}}: battery {{value}} V",
"severities": [
{ "severity": "MAJOR", "condition": { "key": "battery_v", "op": "<", "value": 11.5 } },
{ "severity": "MINOR", "condition": { "key": "battery_v", "op": "<", "value": 11.8 } }
],
"hysteresis": 0.4,
"debounce": { "mode": "count", "raise": 2, "clear": 2 },
"notify": { "recipients": [ { "kind": "email", "email": "field-team@example.com" } ], "minSeverity": "MINOR" },
"enabled": true
}
It opens below 11.8 and clears only at 12.2 or above, two readings in a row. Kevin’s idea would hide the problem, not fix it. Hysteresis and debounce are explained on this page.
Traducido del English por IA ·
Monté la versión P+N en una estación para probar: la corriente de la batería en reposo bajó unos 0,1 mA, y la lectura es la misma que antes con una diferencia de 0,02 V. Cambié la regla a la de arriba. Ya son dos mañanas soleadas sin parpadeos. El destinatario del correo estaba en una dirección personal, y aproveché para cambiarlo al buzón del equipo.
Built the P+N version on one station to test: battery current in sleep dropped by about 0.1 mA, and the reading is the same as before within 0.02 V. Changed the rule to the one above. Two sunny mornings now, no flapping. I’d had the e-mail recipient on a personal address, moved it to the team mailbox while I was at it.
- 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.

