100-Day Battery Life Achievement
100-Day Battery Life Achievement
Overview
Section titled “Overview”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
Prerequisites
Section titled “Prerequisites”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
Key Concepts
Section titled “Key Concepts”The 100-Day Target
Section titled “The 100-Day Target”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 │└────────────────────────────────┘Optimization Layers
Section titled “Optimization Layers”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 sleepLayer 3: Fast WiFi + MQTT ──── Under 5 seconds active per pressLayer 4: Battery Capacity ──── 350 mAh LiPo batteryLayer 1: Hardware Selection
Section titled “Layer 1: Hardware Selection”| Component | Choice | Why |
|---|---|---|
| Board | XIAO ESP32-C3 | Deep sleep: ~5 µA (vs. typical ESP32 at ~10 µA) |
| Voltage regulator | Onboard XIAO regulator | ~2 µA quiescent current |
| Battery | 350 mAh LiPo | Good balance of size and capacity |
| Button | Tactile switch with internal pull-up | No external resistors needed |
Layer 2: Deep Sleep Configuration
Section titled “Layer 2: Deep Sleep Configuration”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}Layer 3: Minimized Active Window
Section titled “Layer 3: Minimized Active Window”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}Layer 4: Battery Selection
Section titled “Layer 4: Battery Selection”| Capacity | Achievable Life (2 presses/day) | Physical Size | Weight |
|---|---|---|---|
| 150 mAh | ~500 days | 25×12×5 mm | ~5 g |
| 300 mAh | ~1,000 days | 30×20×5 mm | ~8 g |
| 350 mAh | ~1,180 days | 35×20×6 mm | ~9 g |
| 500 mAh | ~1,685 days | 35×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.
Complete Firmware Example
Section titled “Complete Firmware Example”#include <WiFi.h>#include <PubSubClient.h>
// Pin configurationconst int BUTTON_PIN = 2;const int BATTERY_ADC = 1;
// WiFi credentialsconst char* SSID = "FactoryWiFi";const char* PASS = "password";
// MQTT configurationconst 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 usedVerification
Section titled “Verification”- 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)
Real-World Testing
Section titled “Real-World Testing”To verify battery life without waiting 100 days:
// Accelerated test mode: press every 10 minutesvoid 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 Duration | Presses | Voltage Drop | Estimated Life |
|---|---|---|---|
| 24 hours | 144 | ~0.1V | ~200+ days |
| 7 days | 1,008 | ~0.5V | ~150+ days |
| 30 days | 4,320 | ~1.0V | ~100+ days |
Communication with Buyers
Section titled “Communication with Buyers”Key Talking Points
Section titled “Key Talking Points”| Question | Answer |
|---|---|
| ”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.” |
Summary
Section titled “Summary”- 100-day battery life is achievable with the XIAO ESP32-C3 and proper optimization
- Four optimization layers: Hardware → Sleep → Active speed → Battery capacity
- 350 mAh battery provides 3x margin over the 100-day target
- Total active time under 5 seconds is critical to energy savings
- Real-world verification via accelerated testing confirms calculations
References
Section titled “References”Target Audience: Alibaba.com IoT Pre-sales Engineers
Status: ✅ Completed