Nouveau : le pare-feu IA surveille toute la plateforme et explique chaque incident en termes simples. Découvrez comment ça marche

Measuring a 12 V battery without the divider draining it, and a low-battery alarm that flaps in the sun

Measuring a 12 V battery without the divider draining it, and a low-battery alarm that flaps in the sun

Résolu 8 7

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.

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

What are the actual divider values on your board, and what’s the ESP32’s ADC reading at 12.6 V?

QoS 1 and a lot of patience.
♥ 0

100k top, 22k bottom. At 12.6 V I get about 2.27 V on the pin, raw around 2700.

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

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.

QoS 1 and a lot of patience.
♥ 0

The single N-channel on the bottom is simpler, I’d just do that.

♥ 1

I have the flapping alarm problem with a UPS battery at our hotel, following this.

♥ 0

Could you only send the battery value once an hour? Then it can’t flap as much.

Measure twice, poll once.
♥ 1

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.

Solution acceptée♥ 9

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.

Modbus is just registers until it isn't.
♥ 0
9 sujets de 1 à 9 (sur un total de 9)
  • Vous devez être connecté pour répondre à ce sujet.

Rejoignez la discussion

Connectez-vous pour poser et répondre à des questions, aimer les messages utiles et marquer la réponse qui a résolu votre problème. Chaque contribution rapporte des points et des niveaux.

Partager