Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.
The divider that drains the battery you are measuring
It looks trivial: two resistors and an ADC pin. The trap is the current through the divider. A 12 V pack across 100 kΩ + 22 kΩ pulls about 100 µA all day, which on a 3000 mAh cell is a few months of life before the ESP32 has even woken up once.
Doing it properly
Choose the ratio so that the highest voltage stays below about 3.1 V at the pin: for a 4S LiFePO4 pack charged to 14.6 V, 100 kΩ over 22 kΩ gives roughly 2.6 V. Add 100 nF at the pin to steady the reading. The ESP32 ADC is not linear near the ends, so calibrate against a multimeter at two voltages, or use the factory-calibrated millivolt function.
To save power, feed the divider through a small MOSFET that is switched on only for the measurement.
A non-isolated divider shares ground with the battery. If the ESP32 is powered from a different source, connect the grounds deliberately.
Never let the pin see more than 3.3 V, even for a moment. A zener or a series resistor protects against surprises.
Runs the cabinet fan only as fast as the temperature needs, reports overheating and warns if the fan stops, so the inverter and the battery stay cool and quiet.
Comments
No comments yet. Share your experience or ask a question.