Free library · Guide
Small solar power for ESP32 projects
A couple of palm-sized solar panels, one 18650 battery and a handful of cheap parts are enough to keep an ESP32 running off-grid. The same circuit works for an ESP8266 or any other board that runs on 3.3V.
This guide covers the four building blocks, then adds an optional battery gauge you can read in MicroPython.
How it fits together
The idea is simple: the sun charges the battery during the day, and the battery runs the board day and night.
- Solar panels make about 5–6V in full sun.
- TP4056 charger feeds that energy into the battery safely and stops when it's full.
- 18650 lithium cell stores the energy. It sits at 4.2V when full, around 3.7V for most of its life, and is flat near 3.0V.
- LDO regulator trims the battery voltage down to a steady 3.3V for the board.
Parts list
| Part | Job |
|---|---|
| ESP32 or ESP8266 board | Runs your project |
| 1–2 mini solar panels (5–6V, about 1.2W each) | Power source |
| 18650 Li-ion cell + holder | Energy storage |
| TP4056 charger module (6-pad version with protection) | Safe charging |
| MCP1700-3302E LDO regulator (or HT7333-A) | Steady 3.3V supply |
| 100µF electrolytic + 100nF ceramic capacitor | Smooths the regulator output |
| 2 × 100kΩ resistors (optional) | Battery gauge |
Not sure which charger suits your build? Choosing a charger for a small solar node compares the TP4056 with five alternatives.
Wiring, step by step
Step 1: Solar panels
One panel works, but two charge the battery faster. Join them in parallel: positive to positive, negative to negative. The voltage stays the same and the current roughly doubles. In direct sun, a multimeter across the leads should read about 5–6V.
Step 2: Charger and battery
- Panel positive → IN+, panel negative → IN−
- Battery positive → B+, battery negative → B−
- Take power for the rest of the circuit from OUT+ and OUT−
The red LED shows the battery is charging; blue means it's full. The protected TP4056 also cuts off if the battery is over-charged, over-drained or wired backwards.
Step 3: 3.3V regulator
Why an LDO? A lithium cell spends most of its life between about 3.6V and 4.0V, only a little above 3.3V. Common regulators like the AMS1117 need around 1V of headroom, so they stop working while the battery still has plenty left. A low-dropout (LDO) regulator keeps going with only about 0.2V of headroom. The MCP1700 also uses almost no power itself, which matters when the board spends most of its time asleep.
Wiring:
- TP4056 OUT+ → regulator VIN
- TP4056 OUT− → regulator GND
- Regulator VOUT → ESP32 3V3 pin, and GND → ESP32 GND
- Both capacitors go between VOUT and GND. The electrolytic is polarised: the side with the stripe goes to GND.
Check VOUT reads 3.3V on a multimeter before connecting the board. The ESP8266 wires up exactly the same way.
The MCP1700 tops out at 250mA. Wi-Fi bursts on an ESP32 can briefly go higher, which is fine for projects that wake, send and sleep. If you see random resets (brownouts), swap in a higher-current LDO such as the AP2112K-3.3 (600mA).
When USB is plugged in, the board's own regulator also drives the 3V3 pin. Unplug the solar 3.3V wire (or pull the battery) while you're connected over USB so the two supplies don't fight.
Step 4 (optional): Battery gauge
It's handy for the project to know how full the battery is. The battery can reach 4.2V, but an ESP32 pin must stay below 3.3V, so two equal resistors halve the voltage first:
- Battery OUT+ → 100kΩ → midpoint → 100kΩ → GND
- Midpoint → GPIO33. Any ADC1 pin works (GPIO32–39); avoid the ADC2 pins, which can't be read while Wi-Fi is on.
A full battery then shows about 2.1V at the pin, and the code simply doubles what it reads.
Many guides use 27kΩ and 100kΩ to scale 4.2V to exactly 3.3V. That works, but the ESP32's ADC reads less accurately near the top of its range, so equal resistors are both simpler and more accurate. The divider draws about 21µA all the time, which is small enough for most projects.
ESP8266: the only analog pin is A0. Many boards (Wemos D1 mini, NodeMCU) already have a divider on A0, so check your board's A0 range before adding one.
MicroPython code (ESP32, Thonny)
This reads the battery, prints the result, then deep-sleeps for 10 minutes. On waking, the ESP32 restarts and runs main.py from the top again.
# Solar ESP32 battery check - MicroPython for Thonny
from machine import ADC, Pin, deepsleep
import time
time.sleep(5) # 5 s window to press Stop in Thonny before sleep
FULL = 4.2 # volts, fully charged
EMPTY = 3.4 # volts, below this the LDO can't hold 3.3 V
adc = ADC(Pin(33))
adc.atten(ADC.ATTN_11DB) # full input range
def battery_volts(samples=10):
total = 0
for _ in range(samples):
total += adc.read_uv() # calibrated microvolts
time.sleep_ms(5)
pin_v = total / samples / 1_000_000
return pin_v * 2 # two equal resistors halve the voltage
def battery_percent(v):
pct = (v - EMPTY) / (FULL - EMPTY) * 100
return max(0, min(100, round(pct)))
v = battery_volts()
print("Battery: {:.2f} V ({}%)".format(v, battery_percent(v)))
# ... your project's work goes here ...
deepsleep(10 * 60 * 1000) # sleep 10 minutes, then start again
Notes:
- The percentage is a rough guide. A lithium cell's voltage doesn't fall in a straight line, so it will hover in the middle for a long time and drop faster near empty.
- Deep sleep drops the USB connection, so Thonny will lose the board. The 5-second pause at the top gives you time to press Stop and get back in.
read_uv()needs a reasonably recent MicroPython build (1.19 or later).
Tips for small solar projects
- Sleep as much as possible. Deep sleep is what makes a small panel enough. A board that's awake and on Wi-Fi all the time will drain the battery faster than the panels can refill it.
- Face the panels north (in Australia) and tilt them toward the sun.
- Keep the battery out of direct heat. A sealed box in full summer sun gets very hot; shade the electronics and let only the panels see the sun.
Want to check the panel and battery size for your own project before you buy? Try the free solar sizer.