This tutorial shows step-by-step how to power the ESP32 development board with solar panels, a 18650 lithium battery and the TP4056 battery charger module. The circuit we’ll build is also compatible with the ESP8266 or any microcontroller that is powered at 3.3V.
When you power your ESP32 with solar panels, it may be useful to use its deep sleep capabilities to save power. Learn everything you need to know about deep sleep with the ESP32 with our guide: ESP32 Deep Sleep with Arduino IDE and Wake Up Sources.
To power the ESP32 or ESP8266 with solar panels, we’ll use the following parts:
- ESP32 or ESP8266(read ESP32 vs ESP8266)
- 2x Mini Solar Panel (5/6V 1.2W)
- Lithium Li-ion battery 18650
- Battery holder
- Battery charger (optional)
- TP4056 Lithium Battery Charger Module
- Voltage regulator:
- Optional – voltage divider for battery monitor:
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
ESP32 Solar Powered – Circuit Overview
The following diagram shows how the circuit to power the ESP32 with solar panels works.
- The solar panels output between 5V to 6V with direct sun.
- The solar panels charge the lithium battery through the TP4056 battery charger module. This module is responsible for charging the battery and prevent overcharging.
- The lithium battery outputs 4.2V when fully charged.
- You need to use a low dropout voltage regulator circuit (MCP1700-3302E) to get 3.3V from the battery output.
- The output from the voltage regulator will power the ESP32 through the 3.3V pin.
The solar panels we’re using have an output voltage up to between 5V to 6V. If you want your battery to charge faster, you can use several solar panels in parallel. In this example we’re using two mini solar panels as shown in the following figure.
To wire solar panels in parallel solder the (+) terminal of one solar panel to the (+) terminal of the other solar panel. Do the same for the (-) terminals. It may help taking a look at the following figure.
When wiring solar panels in parallel you’ll get the same output voltage, and double the current (for identical solar panels). As you can see in the following figure, the solar panels output approximately 6V.
In the picture above, we’re using the ANENG AN8002 multimeter, read our review here: ANENG AN8002 Multimeter Review – Best Low Cost Multimeter?
TP4056 Charger Module
The TP4056 lithium battery charger module comes with circuit protection and prevents battery over-voltage and reverse polarity connection.
The TP4056 module lights up a red LED when it’s charging the battery and lights up a blue LED when the battery is fully charged.
Wire the solar panels to the TP4056 lithium battery charger module as shown in the schematic diagram below. Connect the positive terminals to the pad marked with IN+ and the negative terminals to the pad marked with IN-.
Then, connect the battery holder positive terminal to the B+ pad, and the battery holder negative terminal to the B- pad.
The OUT+ and OUT- are the battery outputs. These lithium batteries output up to 4.2V when fully charged (although they have 3.7V marked in the label).
To power the ESP32 through its 3.3V pin, we need a voltage regulator circuit to get 3.3V from the battery output.
Using a typical linear voltage regulator to drop the voltage from 4.2V to 3.3V isn’t a good idea, because as the battery discharges to, for example 3.7V, your voltage regulator would stop working, because it has a high cutoff voltage.
To drop the voltage efficiently with batteries, you need to use a low-dropout regulator, or LDO for short, that can regulate the output voltage.
After researching LDOs, the MCP1700-3302E is the best for what we want to do. There is also a good alternative like the HT7333-A.
Any LDO that has similar specifications to these two are also good alternatives. Your LDO should have similar specs when it comes to output voltage, quiescent current, output current and a low dropout voltage. Take a look at the datasheet below.
Here’s the MCP1700-3320E pinout: GND, VIN and VOUT pins.
The LDOs should have a ceramic capacitor and an electrolytic capacitor connected in parallel to GND and Vout to smooth the voltage peaks. Here we’re using a 100uF electrolytic capacitor, and a 100nF ceramic capacitor.
Follow the next schematic diagram to add the voltage regulator circuit to the previous setup.
Warning: electrolytic capacitors have polarity! The lead with the white/gray strip should be connected to GND.
The Vout pin of the voltage regulator should output 3.3V. That is the pin that will power the ESP32 or ESP8266.
Finally, after making sure that you’re getting the right voltage on the Vout pin of the voltage regulator, you can power the ESP32. Connect the Vout pin to the 3.3V pin of the ESP32 and GND to GND.
If you’re using an ESP8266 instead, you can follow the same circuit. Wire the output of the MCP1700-3302E to the ESP8266 3.3V pin and GND to GND.
Battery Voltage Level Monitoring Circuit
When you have your ESP32 powered with batteries or solar powered as in this case, it can be very useful to monitor the battery level. One way to do that is reading the output voltage of the battery using an analog pin of the ESP32.
However, the battery we’re using here outputs a maximum of 4.2V when fully charged, but the ESP32 GPIOs work at 3.3V. So, we need to add a voltage divider so that we’re able to read the voltage from the battery.
The voltage divider formula is as follows:
Vout = (Vin*R2)/(R1+R2)
So, if we use R1=27k Ohm, and R2=100k Ohm, we get:
Vout = (4.2*100k)/(27k + 100k) = 3.3V
So, when the battery is fully charged, the Vout outputs 3.3V that we can read with an ESP32 GPIO.
Add two resistors to your circuit as shown in the following schematic diagram.
In this case, we’re monitoring the battery level through GPIO33, but you can use any other suitable GPIO. Read our ESP32 GPIO guide to learn which GPIOs are the best to use.
Finally, to get the battery level, you can simply read the voltage on GPIO33 using the analogRead() function in your code (if you’re using Arduino IDE).
You can also use the map() function, to convert the analog values to a percentage:
float batteryLevel = map(analogRead(33), 0.0f, 4095.0f, 0, 100);
If you’re using ESP8266, it just supports analog reading on the A0 pin. So, you need to wire the circuit as follows:
With the ESP8266 to read the analog value use:
In this article we’ve shown you how to power the ESP32 or the ESP8266 with solar panels, a lithium battery and a TP4056 battery charger module. The circuit we’ve shown you can also be used to power other microcontrollers that require 3.3V to operate.
When powering the ESP32 using solar panels or batteries, it is important to save power. For that, you can use the ESP32 deep sleep capabilities.
Now, you can use this circuit to make your projects solar powered. For example, it would be interesting to modify the following projects to use solar panels:
- ESP32 Data Logging Temperature to MicroSD Card
- ESP32 Web Server with BME280 – Mini Weather Station
- Low Power Weather Station Datalogger
If you want to learn more about ESP32, make sure you check our dedicated ESP32 course: Learn ESP32 with Arduino IDE.
Thanks for reading.