Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

ESP32 Battery Power & Longevity Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to power an ESP32 project from a battery and get the longest possible runtime. You’ll learn the best battery types, how to connect them safely, and how to use the ESP32’s low-power modes to stretch every milliamp-hour. We’ll cover both simple and advanced techniques, from choosing the right regulator to writing power-efficient code.

What You'll Need

  • ESP32 development board (e.g., ESP32 DevKit, NodeMCU-32S) or bare ESP32 module
  • Battery: 18650 Li-ion cell, LiPo pouch cell, or 2x AA alkaline batteries
  • Battery holder or connector (e.g., JST PH 2.0 for LiPo)
  • Low-dropout regulator (LDO) like AMS1117-3.3 or a buck converter (e.g., MP1584) if using >5V input
  • Capacitors: 10µF and 0.1µF ceramic (for decoupling)
  • Breadboard and jumper wires (for prototyping)
  • Multimeter (to measure current draw)
  • USB-to-UART programmer (if using bare ESP32)
  • Optional: TP4056 charging module for Li-ion/LiPo

Step-by-Step

  1. Choose the right battery. For most projects, a single 3.7V Li-ion or LiPo cell is ideal because the ESP32’s operating range (2.2V–3.6V) overlaps the battery’s voltage curve (3.0V–4.2V). If you use 2x AA alkaline (3.0V total), the ESP32 will work but only until the batteries drop below ~2.2V, which happens quickly under load. Avoid 9V batteries—they waste energy as heat in the regulator.
  2. Add a voltage regulator (if needed). The ESP32’s onboard regulator (usually AMS1117) can handle 3.7V Li-ion directly, but it has a dropout voltage of ~1V, so the ESP32 will shut down when the battery hits ~3.3V, wasting ~30% of the battery’s capacity. For longer runtime, use an external low-dropout regulator (e.g., MCP1700 with 0.4V dropout) or a buck converter if you insist on higher voltage batteries. Connect the battery to the regulator input, and the regulator output to the ESP32’s 3.3V pin (not the 5V pin).
  3. Connect the battery properly. If using a Li-ion/LiPo, connect the positive (red) wire to the regulator input or the ESP32’s VBAT pin (if available), and the negative (black) to the common ground. Always use a protection circuit (most LiPo cells have one built-in) to prevent over-discharge. For AA batteries, use a holder and connect to the 3.3V pin via a diode (e.g., 1N5817) to drop the voltage slightly and prevent reverse current.
  4. Enable deep sleep in your code. The single biggest power saver is putting the ESP32 into deep sleep when idle. Use esp_sleep_enable_timer_wakeup(time_in_microseconds) and esp_deep_sleep_start(). During deep sleep, the ESP32 draws about 10µA (with RTC memory on) instead of 50–100mA when active. Wake up with a timer or an external GPIO (e.g., a button or sensor).
  5. Use modem sleep for Wi-Fi. If you need to keep Wi-Fi connected but want to save power, use modem sleep. Set WiFi.setSleep(true) (default in most libraries) to let the radio sleep between beacons. This cuts Wi-Fi current from ~100mA to ~20mA average.
  6. Optimize your active time. Do all your sensor reads, calculations, and Wi-Fi transmissions in a burst, then go back to sleep. For example, read a temperature sensor every 10 minutes, transmit for 1 second, then sleep. This “duty cycle” approach can extend battery life from hours to months.
  7. Turn off unused peripherals. Disable the ADC, touch sensors, and Bluetooth if not needed. Use adc_power_off() and btStop(). Also, set GPIO pins to low or input mode to avoid floating inputs that waste current.
  8. Measure your current draw. Use a multimeter in series with the battery to measure current in active and sleep modes. This tells you if your optimizations are working. In deep sleep, you should see <10mA (ideally <100µA). If you see more, check for power-hungry components like LEDs (add a resistor or remove them) or voltage regulators with high quiescent current.
  9. Add a battery level monitor. Use the ESP32’s ADC to read the battery voltage through a voltage divider (e.g., 100kΩ + 100kΩ) to avoid draining the battery. Calibrate the ADC using the internal reference. This lets you warn the user before the battery dies.
  10. Consider a solar panel or energy harvesting. For long-term outdoor projects, add a small solar panel and a charge controller (e.g., CN3065) to trickle-charge the battery during the day. This can make the project self-sustaining.

Common Mistakes

  • Using the 5V pin with a battery—this bypasses the regulator and can damage the ESP32.
  • Forgetting to enable deep sleep—the ESP32 stays in active mode and drains the battery in hours.
  • Connecting a LiPo battery without a protection circuit—over-discharge can permanently damage the cell.
  • Using a high-dropout regulator (like AMS1117) with a 3.7V battery—you lose 30% of capacity.
  • Leaving the USB cable connected while on battery—the USB will power the board and may back-feed the battery.
  • Not adding a decoupling capacitor near the ESP32’s power pins—causes brownouts and resets.

Tips

  • Use a battery with a capacity of at least 1000mAh for any wireless project; 2000mAh+ gives more headroom.
  • In deep sleep, set unused GPIOs to GPIO_NUM_* with gpio_deep_sleep_hold_en() to keep them low.
  • Use the ESP32’s ULP (Ultra Low Power) coprocessor to wake the main CPU only when a sensor threshold is crossed—this can reduce average current to microamps.
  • If you need to log data, write to RTC memory or a small FRAM chip instead of SD card—SD cards draw ~100mA when writing.
  • Update firmware over Wi-Fi (OTA) to avoid opening the enclosure to reprogram.
  • Test your project with a fresh battery and measure the actual runtime—don’t trust theoretical calculations.

Troubleshooting

  • ESP32 resets when Wi-Fi transmits. This is a voltage drop issue. Add a 100µF capacitor across the 3.3V and GND pins, or use a battery with higher discharge rate (e.g., 18650 instead of a small LiPo).
  • Battery drains too fast in deep sleep. Check for power-hungry peripherals (LEDs, sensors) that are still powered. Also, ensure the regulator’s quiescent current is low (<10µA). Some regulators (like AMS1117) draw 5mA just sitting there—switch to a low-Iq regulator.
  • ESP32 won’t wake from deep sleep. Verify the wake-up source is correctly configured. For timer wakeup, ensure the time is in microseconds (e.g., 10 seconds = 10,000,000 µs). For GPIO wakeup, use esp_sleep_enable_ext0_wakeup(GPIO_NUM_X, level).
  • Battery voltage reads wrong. Calibrate the ADC using the internal reference or use a known voltage to scale. Also, add a small capacitor (0.1µF) on the ADC pin to stabilize readings.
  • Voltage regulator gets hot. If using a linear regulator with a 9V battery, it dissipates (9V-3.3V)*current as heat. Switch to a buck converter or use a lower voltage battery.

Frequently Asked Questions

Can I use a 3.7V LiPo battery directly without a regulator?

Yes, but only if the battery voltage stays within 3.0V–3.6V. Most LiPos start at 4.2V when full, which exceeds the ESP32’s absolute maximum of 3.6V. Use a regulator or a diode to drop the voltage, or charge the battery to only 3.6V (reduces capacity).

How long will a 2000mAh battery last with deep sleep?

If your average current is 20µA in deep sleep and 80mA for 1 second every 10 minutes, the average current is about 0.15mA. A 2000mAh battery would last roughly 13,000 hours (1.5 years). But Wi-Fi transmission spikes can reduce this.

What is the best battery for an ESP32 project?

For most projects, a single 18650 Li-ion cell (2000–3500mAh) with a protection circuit is best. It offers high capacity, low self-discharge, and can handle the ESP32’s current spikes.

Can I use a solar panel to charge the battery?

Yes, but you need a charge controller (e.g., TP4056 with solar input) to prevent overcharging. A 6V/1W panel can charge a 2000mAh battery in a day of good sunlight.

Does using Arduino IDE vs ESP-IDF affect battery life?

Not directly, but ESP-IDF gives you finer control over power management (e.g., dynamic frequency scaling, light sleep). However, the same deep sleep commands work in both.

How do I know if my battery is low?

Use the ADC to read the battery voltage through a voltage divider. For a 3.7V Li-ion, 3.3V is about 20% remaining, 3.0V is critical. Calibrate the divider to match your battery’s discharge curve.