ESP32: solar + 18650 battery for perpetual projects
Add a small solar panel to your 18650 battery setup for perpetual operation. The math for sizing the panel and the protection circuit you actually need.
Adding a small solar panel to your 18650 battery setup turns a project that runs for weeks into one that runs forever. The math is simple: a small solar panel (1-5W) provides more energy per day than most ESP32 projects use.
This tutorial covers the wiring, the panel sizing math, and the charge controller setup that prevents the panel from overcharging the battery.
What you need
- 18650 cell (genuine Samsung/LG/Panasonic/Sony, 2500-3500 mAh)
- TP4056 charge controller with protection (the version with DW01)
- Small solar panel (5-6V, 1-5W; about $5-15)
- Schottky diode (1N5817 or similar; 1A rated)
- LDO regulator (ME6211 or HT7333, 3.3V output, low quiescent current)
- Capacitors: 100uF and 10uF electrolytic, 100nF ceramic
The basic wiring
Solar panel + -- TP4056 IN+ (5V)
Solar panel - -- TP4056 IN- (GND)
TP4056 OUT+ -- LDO IN (3.7-4.2V battery voltage)
TP4056 OUT- -- LDO GND
LDO OUT -- ESP32 3.3V
LDO GND -- ESP32 GND
Without the diode (added in the next section), this works for sunny days but fails at night when the battery drains backwards through the panel.
The reverse current problem
Solar panels generate electricity whenever light hits them. At night, they are still generating: just not enough to charge the battery. The panel becomes a path for the battery to discharge.
A Schottky diode in series with the panel blocks this reverse current:
Solar panel + -- diode cathode (stripe side)
-- TP4056 IN+
The diode drops about 0.3V (Schottky) or 0.7V (silicon). The TP4056’s input range is 4.5-5.5V, so a Schottky diode works without losing much charge current.
The 1N5817 is the standard Schottky diode for this (1A, low forward drop). Most small solar panels (under 5W) work fine with it.
The panel sizing math
For an ESP32 sensor project that uses 50 mAh per day (about 2 mA average current):
- Battery capacity: 2500 mAh
- Days of battery life without solar: 50 days
- Solar needed to replenish 50 mAh/day: depends on sun hours
In a typical location with 4 sun-hours per day, a 1W solar panel provides about 200 mAh per day (after conversion losses). That is 4x the consumption, which is the right margin.
For the same project in winter (1-2 sun-hours per day), a 2W panel is the right pick.
For projects in low-light (inside a window), a 5W panel is needed to overcome the 50-70% light loss through glass.
The TP4056 solar charge controller
The TP4056 charges the 18650 from the solar panel through the same CC/CV profile as USB charging. It works fine for solar as long as the panel output voltage is in the 4.5-5.5V range.
The TP4056’s charge LED indicates charging status:
- Off: not charging (no input, or input below 4.5V)
- Red: charging
- Green: charge complete
For solar projects, the LED is a useful diagnostic: if it never turns red during the day, the panel is not delivering enough voltage.
Deep sleep + solar
The combination of deep sleep + solar is the right pattern for perpetual sensor nodes:
void loop() {
// Take a sensor reading
float reading = readSensor();
// Publish it
publishMqtt(reading);
// Sleep for 5 minutes
esp_sleep_enable_timer_wakeup(5 * 60 * 1000000ULL);
esp_deep_sleep_start();
}
With 5-minute deep sleep, the ESP32 wakes 288 times per day. Each wake consumes about 50 mA for 5 seconds (publishing). The average current is about 1 mA, or 24 mAh per day. A 1W solar panel in 4 sun-hours provides enough.
The low battery protection
The TP4056 with the DW01 protection chip cuts off the battery at 2.5V to prevent over-discharge. This protects the cell but means your project will stop working in low-sun conditions.
For mission-critical projects, add a battery voltage monitor and warn the user:
float batteryVoltage = analogRead(BATT_PIN) * 2.0 * 3.3 / 4095.0;
if (batteryVoltage < 3.3) {
// Battery low, skip this wake cycle to save power
esp_sleep_enable_timer_wakeup(60 * 60 * 1000000ULL); // sleep for an hour
esp_deep_sleep_start();
return;
}
The voltage divider (R1 + R2) halves the battery voltage so the ADC can read it (see the 18650 tutorial for the wiring).
Solar + temperature
The 18650 cell’s capacity drops at low temperatures. Below 0°C, you lose about 30% capacity. For outdoor projects in cold climates, mount the battery in an insulated enclosure or add a small heating resistor.
The enclosure
Outdoor solar projects need an enclosure:
- IP65 or better (rain-proof)
- Transparent top (for the solar panel) or external solar panel
- Ventilation hole with Gore-Tex membrane (for pressure equalization)
- Cable glands for any external sensors
A standard electrical junction box with a clear lid works for many projects. For permanent installations, use a metal NEMA enclosure.
Common projects
- Garden sensors. Soil moisture, temperature, light. Perpetual operation through spring/summer/fall.
- Remote weather stations. Solar + battery + temperature + humidity
- pressure.
- Trail cameras. Solar + battery + ESP32-CAM. The ESP32-CAM can run on solar for years with motion-triggered captures.
- Asset trackers. GPS + solar + ESP32. Reports position once per hour.
What you learned
- A small solar panel (1-5W) makes most ESP32 projects perpetual.
- The Schottky diode prevents reverse current drain at night.
- The TP4056 charges the battery from the solar panel.
- Deep sleep + solar is the right pattern for sensor nodes.
When something breaks
- Battery dies in a few days. Solar panel not charging (check voltage), or current consumption is higher than expected (check deep sleep current).
- Battery swells or vents. Counterfeit cell, or overcharging. Get a genuine cell and verify TP4056 charge voltage (4.2V).
- Panel voltage drops at peak sun. Panel is shaded, or the diode is in backwards.
- TP4056 LED never lights. Panel voltage too low (under 4.5V), or panel wiring is wrong.
What to build next
- The 18650 + TP4056 tutorial covers the basic battery setup without solar.
- The deep sleep tutorial shows the code patterns for low-power ESP32.
- The book ESP32 Solar Projects covers outdoor enclosures, panel sizing for various climates, and remote monitoring.