Skip to content

100-Day Battery Life Achievement

100-Day Battery Life Achievement

This section shows how the combination of hardware selection, power optimization, and efficient firmware achieves 100+ days of battery life. By the end of this section, you will be able to:

  • Explain the complete power optimization strategy
  • Configure all system parameters for maximum battery life
  • Demonstrate how each optimization contributes to the final result
  • Communicate the 100-day achievement to buyers

Before starting this section, please ensure:

  • Completed Sections 04-05 through 04-08
  • Understanding of energy consumption per press (Section 04-06)
  • Working hardware setup with XIAO + battery + button

Achieving 100 days on a single charge is a common buyer requirement for industrial IoT buttons. This target is realistic with proper optimization:

100-day target requirements:
┌────────────────────────────────┐
│ Total energy budget: │
│ 350 mAh × 80% = 280 mAh │
│ Daily budget: 2.8 mAh/day │
├────────────────────────────────┤
│ With 2 presses/day: │
│ Sleep: 0.12 mAh/day │
│ Active: 0.058 mAh × 2 = │
│ 0.116 mAh/day │
│ Total: 0.236 mAh/day │
│ Target life: 1,186 days │
└────────────────────────────────┘

The 100-day battery life is achieved through four layers of optimization:

Layer 1: Hardware Selection ──── XIAO ESP32-C3 (5 µA deep sleep)
Layer 2: Deep Sleep Logic ──── 99.9% of time in sleep
Layer 3: Fast WiFi + MQTT ──── Under 5 seconds active per press
Layer 4: Battery Capacity ──── 350 mAh LiPo battery
ComponentChoiceWhy
BoardXIAO ESP32-C3Deep sleep: ~5 µA (vs. typical ESP32 at ~10 µA)
Voltage regulatorOnboard XIAO regulator~2 µA quiescent current
Battery350 mAh LiPoGood balance of size and capacity
ButtonTactile switch with internal pull-upNo external resistors needed

The device spends nearly 100% of its time in deep sleep:

void configureDeepSleep() {
// Ensure all GPIOs are in low-leakage state
pinMode(BUTTON_PIN, INPUT_PULLUP); // Button with pull-up
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // LED off
// Disable all peripherals
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
// Configure wake source
esp_sleep_enable_ext0_wakeup(
(gpio_num_t)BUTTON_PIN,
0 // Wake on LOW (button pressed)
);
// Optional: Backup timer wake for health check
// esp_sleep_enable_timer_wakeup(24 * 3600 * 1000000ULL); // Every 24h
}

The complete active cycle (wake → WiFi → MQTT → sleep) is optimized for speed:

void optimizedPressCycle() {
unsigned long cycleStart = millis();
// 1. WiFi connect with cached BSSID (~1.5s)
fastWiFiConnect();
if (WiFi.status() != WL_CONNECTED) {
goToSleep(); // Don't waste energy on retries
return;
}
// 2. MQTT connect and publish (~1s)
fastMQTTConnect();
mqttClient.publish(TOPIC, "{\"action\":\"toggle\",\"battery\":" +
String(readBatteryVoltage()) + "}");
// 3. Immediate cleanup without unnecessary delays
mqttClient.disconnect();
WiFi.disconnect(true);
unsigned long activeMs = millis() - cycleStart;
Serial.print("Active cycle: ");
Serial.print(activeMs);
Serial.println(" ms");
goToSleep();
}
void goToSleep() {
Serial.flush();
esp_deep_sleep_start(); // Never returns
}
CapacityAchievable Life (2 presses/day)Physical SizeWeight
150 mAh~500 days25×12×5 mm~5 g
300 mAh~1,000 days30×20×5 mm~8 g
350 mAh~1,180 days35×20×6 mm~9 g
500 mAh~1,685 days35×25×5 mm~12 g

For the 100-day target, even a 150 mAh battery is sufficient. A 350 mAh battery provides a comfortable margin.

#include <WiFi.h>
#include <PubSubClient.h>
// Pin configuration
const int BUTTON_PIN = 2;
const int BATTERY_ADC = 1;
// WiFi credentials
const char* SSID = "FactoryWiFi";
const char* PASS = "password";
// MQTT configuration
const char* BROKER = "192.168.1.100";
const int PORT = 1883;
const char* TOPIC = "factory/button/01/press";
WiFiClient wifiClient;
PubSubClient mqttClient(wifiClient);
float readBattery() {
return (analogRead(BATTERY_ADC) / 4095.0) * 3.3 * 2;
}
void fastWiFiConnect() {
WiFi.mode(WIFI_STA);
WiFi.setSleep(false);
WiFi.begin(SSID, PASS);
unsigned long start = millis();
while (WiFi.status() != WL_CONNECTED &&
millis() - start < 5000) {
delay(50);
}
}
void fastMQTTConnect() {
String clientId = "BTN_" + String((uint32_t)ESP.getEfuseMac(), HEX);
mqttClient.setServer(BROKER, PORT);
mqttClient.connect(clientId.c_str());
}
void goToSleep() {
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
Serial.flush();
esp_sleep_enable_ext0_wakeup((gpio_num_t)BUTTON_PIN, 0);
esp_deep_sleep_start();
}
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("Button pressed - executing action");
// Fast cycle: WiFi → MQTT → Sleep
fastWiFiConnect();
if (WiFi.status() == WL_CONNECTED) {
fastMQTTConnect();
if (mqttClient.connected()) {
String payload = "{\"action\":\"toggle\",\"battery\":";
payload += String(readBattery());
payload += "}";
mqttClient.publish(TOPIC, payload.c_str());
mqttClient.disconnect();
}
}
goToSleep();
}
void loop() {} // Never used
  • Total active time < 5 seconds per button press
  • Deep sleep current < 10 µA (measured with multimeter)
  • Device can survive > 100 days with 350 mAh battery at 2 presses/day
  • MQTT message arrives at broker within 5 seconds of pressing
  • Battery voltage measurement is accurate (checked with multimeter)

To verify battery life without waiting 100 days:

// Accelerated test mode: press every 10 minutes
void testMode() {
for (int i = 0; i < 100; i++) {
performButtonAction(); // Normal press cycle
esp_sleep_enable_timer_wakeup(600 * 1000000ULL); // 10 min
esp_deep_sleep_start();
// After wake: the loop continues from setup()
}
Serial.println("100 press cycles completed");
Serial.println("Check battery voltage to estimate life");
}

Estimation from accelerated test:

Test DurationPressesVoltage DropEstimated Life
24 hours144~0.1V~200+ days
7 days1,008~0.5V~150+ days
30 days4,320~1.0V~100+ days
QuestionAnswer
”How long does the battery last?""Over 100 days at 2 presses per day, typically 2-3 months on a 350mAh battery."
"What affects battery life?""Usage frequency, WiFi signal strength, and battery quality."
"How do I know when to charge?""Each button press reports its battery voltage — you get a warning before it dies."
"Is 100 days guaranteed?""Under normal factory conditions with good WiFi coverage, yes. Extreme temperatures or poor WiFi may reduce it.”
  1. 100-day battery life is achievable with the XIAO ESP32-C3 and proper optimization
  2. Four optimization layers: Hardware → Sleep → Active speed → Battery capacity
  3. 350 mAh battery provides 3x margin over the 100-day target
  4. Total active time under 5 seconds is critical to energy savings
  5. Real-world verification via accelerated testing confirms calculations

Target Audience: Alibaba.com IoT Pre-sales Engineers
Status: ✅ Completed