← Free library

Free library · Guide

Small solar power for ESP32 projects

9 Nov 2026Wiring, parts list, battery gauge and MicroPython code

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.

A breadboard on a blue workbench mat with three mini solar panels wired to a TP4056 charger, a regulator and capacitors, a development board, and an 18650 cell in a holder.
The circuit on the bench: mini solar panels, TP4056 charger, LDO regulator and an 18650 cell.

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 5–6V in sun 2 in parallel TP4056 charges safely stops at full 18650 cell stores energy 3.0–4.2V LDO + caps MCP1700 steady 3.3V ESP32 into 3V3 pin runs project optional battery gauge to GPIO33
The solar power chain, with the optional battery gauge
  1. Solar panels make about 5–6V in full sun.
  2. TP4056 charger feeds that energy into the battery safely and stops when it's full.
  3. 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.
  4. LDO regulator trims the battery voltage down to a steady 3.3V for the board.

Parts list

PartJob
ESP32 or ESP8266 boardRuns your project
1–2 mini solar panels (5–6V, about 1.2W each)Power source
18650 Li-ion cell + holderEnergy 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 capacitorSmooths 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

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:

Check VOUT reads 3.3V on a multimeter before connecting the board. The ESP8266 wires up exactly the same way.

Current limit

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).

Programming with Thonny

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:

midpoint Battery OUT+ 4.2V when full R1 100kΩ R2 100kΩ GND 0V ESP32 GPIO33 2.1V when full
Battery gauge divider: 2 × 100kΩ

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.

main.py
# 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:

Tips for small solar projects

Want to check the panel and battery size for your own project before you buy? Try the free solar sizer.

#Solar#ESP32#18650#MicroPython#OffGrid