HomeKit
ESP8266 HomeKit Battery Status with an 18650 Cell
A proof of concept: an ESP8266 that measures an 18650 cell through a voltage divider and reports a low battery to Apple Home.
- ESP8266
- HomeKit
- 3 min read
A battery-powered sensor tells HomeKit when its battery is nearly empty. This project shows the building block for that: a 18650 lithium cell, a charger, a regulator and a divider that lets an ESP8266 measure the cell voltage, plus the code that reports a low battery to the Home app.
It is the battery version of the ESP8266 HomeKit Temperature and Humidity Sensor, which uses the same battery task. It is a proof of concept, built as a test setup on a breadboard.
The parts
| Part | What it does |
|---|---|
| 18650 cell, 3400 mAh, 3.7 V | The battery |
| TP4056 board | A charger board with a USB connector, for charging the cell |
| MCP1700 | A low dropout regulator that makes the supply of the module from the battery voltage |
| ESP-12 module | The ESP8266 with the HomeKit firmware |
| 32 kΩ and 10 kΩ resistors | A voltage divider that brings the battery voltage within the range of the ADC |
| 100 µF and 100 nF capacitors | Smoothing on the supply |
| FTDI adapter, RESET and PROGRAM buttons | For programming the module |
The MCP1700 regulator
The MCP1700 from Microchip is a low dropout regulator made for battery devices. From its datasheet (checked on 26 September 2026):
| Property | Value |
|---|---|
| Input voltage | 2.3 V to 6.0 V, which fits a single lithium cell |
| Output voltages | 1.2, 1.8, 2.5, 3.0, 3.3 and 5.0 V as standard options |
| Output current | 250 mA for output voltages of 2.5 V and higher |
| Own current use | 1.6 µA typical, so it hardly drains the battery |
| Dropout | 178 mV typical at 250 mA, for the 2.8 V version |
| Capacitors | Stable with a 1 µF ceramic capacitor on the output, and 1 µF on the input is enough for most uses |
A lithium cell gives 4.2 V when full and less as it empties. The regulator keeps the supply of the module steady until the cell voltage comes close to the output voltage.
Measuring the battery
The ADC input of the ESP8266 measures 0 to 1 V, and a full cell gives 4.2 V. A voltage divider scales the battery voltage down. The output is Vout = Rbottom / (Rbottom + Rtop) × Vin.

With 32 kΩ on top and 10 kΩ at the bottom, the divider divides the battery voltage by 4.2 ((32 + 10) / 10), so 4.2 V on the cell is 1 V on the ADC. That is the factor 4.2 in the code below.
The code
The repository holds one file, battery.c. Every 3 seconds it reads the ADC, converts the reading to the battery voltage and tells HomeKit whether the battery is low. The threshold is 3.9 V.
void battery_low_task(void *_args) {
while (1) {
battery_value = sdk_system_adc_read();
printf ("ADC voltage is %.3fn", 1.0 / 1024 * sdk_system_adc_read() * 4.2);
vTaskDelay(3000 / portTICK_PERIOD_MS);
if (1.0 / 1024 * battery_value * 4.2 < 3.900) {
printf ("Battery value is low.n");
low_battery_value = 1;
}
else {
printf ("Battery value is not low.n");
}
homekit_characteristic_notify(&status_low_battery, HOMEKIT_UINT8(low_battery_value));
vTaskDelay(3000 / portTICK_PERIOD_MS);
}
}
The task is started with battery_low_init(), and the status_low_battery characteristic is added to the service of the accessory, as in the ESP8266 HomeKit Temperature and Humidity Sensor.
In the Home app
When the battery is low, HomeKit shows a notification. The screenshots show a temperature and humidity sensor with the message Battery Low.

Good to know
- There is no release for this repository, because the battery task is meant to be added to a firmware of your own. The project is a proof of concept.
- Once the code has reported a low battery, it does not report a good battery again until the module restarts: the value is only ever set to 1.
- The HomeKit Accessory Protocol specification the firmware follows is the non-commercial version, for accessories you build yourself and do not distribute or sell.
- The repository is under the MIT licence.
The project is in the ESP8266-HomeKit-Battery-Status repository on GitHub.
More HomeKit
Keep building.
Switches, sensors, plugs and blinds: more accessories that you build yourself and add to the Home app.
All HomeKit

