Power ESP32/ESP8266 with Solar Panels (includes battery level monitoring)

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.

Power ESP32 ESP8266 with Solar Panels includes battery level monitoring

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.

Parts Required

To power the ESP32 or ESP8266 with solar panels, we’ll use the following parts:

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.

ESP32 Solar Powered Circuit Schematic Diagram Overview
  1. The solar panels output between 5V to 6V with direct sun.
  2. The solar panels charge the lithium battery through the TP4056 battery charger module. This module is responsible for charging the battery and prevent overcharging.
  3. The lithium battery outputs 4.2V when fully charged.
  4. You need to use a low dropout voltage regulator circuit (MCP1700-3302E) to get 3.3V from the battery output.
  5. The output from the voltage regulator will power the ESP32 through the 3.3V pin.

Solar Panels

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.

Power ESP32 ESP8266 Solar Panels

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.

Power ESP32 ESP8266 Solar Panels Circuit

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.

Power ESP32 ESP8266 Solar Panels Multimeter Measurements

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.

TP4056 lithium battery charger module

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

TP4056 lithium battery charger module connected to solar panels

Then, connect the battery holder positive terminal to the B+ pad, and the battery holder negative terminal to the B- pad.

TP4056 lithium battery charger module connected to solar panels and lithium battery

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

lithium battery multimeter output voltage

To power the ESP32 through its 3.3V pin, we need a voltage regulator circuit to get 3.3V from the battery output.

Voltage Regulator

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.

MCP1700-3302E LDO Low-dropout Voltage Regulator

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.

HT7333-A LDO Low-dropout Voltage Regulator

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.

MCP1700 Datasheet LDO Low-dropout Voltage Regulator

Here’s the MCP1700-3302E pinout: GND, VIN and VOUT pins.

MCP1700-3320E pinout 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.

ESP32 ESP8266 Solar Panels and voltage regulator circuit

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.

ESP32 ESP8266 Solar Panels and voltage regulator circuit multimeter measurements

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.

Power ESP32 with Solar Panels circuit schematic

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.

Power ESP8266 with Solar Panels circuit schematic

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.

Battery Voltage Level Monitoring Circuit Schematic

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.

Final circuit Power ESP32 with Solar Panels battery level monitoring

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

analogRead(33);

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:

Final circuit Power ES8266 with Solar Panels battery level monitoring

With the ESP8266 to read the analog value use:

analogRead(0);

Wrapping Up

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:

If you want to learn more about ESP32, make sure you check our dedicated ESP32 course: Learn ESP32 with Arduino IDE.

Thanks for reading.


Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

40 thoughts on “Power ESP32/ESP8266 with Solar Panels (includes battery level monitoring)”

  1. Please please please remove that link to 18650s and post one from a reputable source, most batteries won’t be over 3200mAh and those are only from name brand sources!!

      • Hi Ed.
        If you’re using an ESP8266 NodeMCU kit (as we’re using in the example) it has a built-in voltage divider. So, the input range is 0 to 3.3V.
        If you’re using an ESP8266 bare chip, the input range of the A0 is 0 to 1V.
        Regards,
        Sara

        • That is certainly true, but I was under the impression the battery voltage was measured and that can be 4.2Volt, leading to 1.3Volts on A0.
          That will not immediately kill the ESP, but make it impossible to measure battery voltage above 3.3 Volt.
          I apologize for nitpicking, but might be an option to add a 100k resistor so one has 100k/(100k+100k+220k)= 1/4.2 as voltage divider. Anyway, that’s just a suggestion

  2. Hi,
    Great article. I would like to point out one mistake (rather a minor issue).
    When working with battery, you are using map function to convert 0v to 3.3v of the voltage divider into 0 to 100%.

    The issue with batteries is that anything less than 3.4v (or something like this) is considered 0% (in case of LiPo/LiIon batteries). So 0V is a state where the battery is dead and cannot be brought back to life.

    The map function should hence map between values 3.4v and 4.2v between 0 and 100% and not 0v to 4.2v.

    • Thanks for pointing that out. I know it and that’s definitely true. It’s also not linear. At around 70% the battery is fully discharged, but it was just something that you can use to have an idea of the current level.

  3. Removing the red and blue LED would be a good idea.
    Also, can the ESP even sample voltages so close to Vcc? Shouldn’t you voltage devide first?
    And as already said, get a good cell, best would be a LiFePo4, which limited to 3.6 V can directly power the ESP32 and will be safer to handle and live longer.
    A LiFePo4 protection circuit and a 3.6V schotky diode are enough to safely handle such a system.

  4. This is not a good board to be used to power anything at the same time as charging. You will always be drawing power from the battery at the same time as trying to charge it so the incorrect charging will be applied to the battery depending on what current your circuit draws. The proper type has power path control so that the incoming 5V is fed direct to the output and the battery disconnected from the output. Once the external 5V is removed, the battery is put back into the circuit and everything works fine. These boards are not good designs for anything other than standalone battery charging.

    • Interesting – are you able to suggest a better charging circuit?

      That is, one with power path control as you suggest?

      Regards

      Chris

      • Actually, the MCP73871 solar charge IC do load sharing, not as cheap as the TP4056 modules but cheap enough at $3-4

        Linear and handle 6V PV panel max

        Chinese close of Adafruit’s older design

      • Hi Chris,

        look at boards based based on the CN3065 or the BQ24210 that adjust the charge rate based at the available input current, that will work a lot better than the TP4056. At least boards with the CN3065 are available and almost as cheap.

        Kind regards

        • If you look at Andrea Spiess video, the CN3065 is not anymore efficient than the TP4056 with a small PV panel, might be better under shaded condition?

          youtube.com/watch?v=ttyKZnVzic4

          I’ll save the money towards larger/more PV panel or battery instead.

          • Hi,

            the TP performs perfectly, on a sunny midsummer noon, no doubt. At least if Rprog is chosen correctly, so that the charge current is less than what the panel provides. In almost all other cases it will not. Any time the panel does not provide enough energy for the TP4056 to run at its programmed current rate defined by Rprog, it will work out of specs.

            Somehow there may leak some energy into the Lipo, one cannot tell. Its out of specs.

            On solar chargers, the current (e.g. Rprog on the TP) is actually defined by a micro controller that is part of the charger and the charge current is reduced if the panel provides limited power, so that voltage is maintained for the Charger to work within specs. It would be a funny project to turn a TP4056 into a solar charger (using a ATTiny13 and Rprog) to educate it in sensing input power.

            But why if there are cheap chargers that do.

            Kind regards

    • Sadly, I don’t think there’s a cheap chinese clone out there that has load sharing, this guy designed an add-on board (+low power 3.3V step down):
      hackaday.io/project/18205-tp4056-3v3-load-share-addon-board

      It’s pretty simple really, only need a mosfet to do the load sharing

      The TP4056 would be OK if the load is less than C/10 for proper termination.
      (So <100mA at the default 1A charging rate)

      • Search for MCP73871 that offers current balancing between battery and circuit. Adafruit has a board for it and you can find a clone on Chinese sites. Waiting for mine and a handful of panels to try it out.

  5. sorry if i mention it wrong, is it necessary to have a Voltage Regulator and the voltage divider circuit to made 3.3V for the ESP32? Why not just directly supply the Battery voltage to ESP32 (Vin) pin and (GND) pin, since on the broad itself already have a build in voltage regulator.

      • Hi Rui, excellent website and projects. I am really enjoying getting back into Electronics using your tutorials.

        Just so that I can be clear on this point. The input voltage (via vin or by the micro usb) has a range of 6-12 V and because you’re using a voltage lower than this range it wouldn’t work (i.e. the AMS1117 would drop below the 3.3V) so you’ve stepped it down yourself to 3.3V and by-passed the boards regulator?

        • Hi James.
          That’s right. That’s why we don’t use the VIN pin in this particular case. It wouldn’t work with 4.2V from the lithium battery.
          Regards,
          Sara

  6. Not sure about the ESP32 but the ESP8266 will already have a passive voltage divider to take 3v3 down to 1v range. Putting another divider in front of that won’t work unless you add a voltage follower to reduce the output impedance. Easier is just to use a series resistor added to the one built in, or replace the one on the board.

    • Hi Niall.
      If you’re using an ESP8266 NodeMCU kit (as we’re using in the example) it has a built-in voltage divider. So, the input range is 0 to 3.3V.
      If you’re using an ESP8266 bare chip, the input range of the A0 is 0 to 1V.
      Regards,
      Rui

      • Understood about the voltage ranges, not sure if you understood my point about cascading passive voltage dividers. Try simulating and you see it will read low.

        • Indeed.
          As there is already a divider on the board, we don’t need a full divider but only an additional serie resistor.
          On my D1 mini, the divider is 220k/100k => ratio 100/(100+220). I added a 300k resistor in serie which give now a ratio of 100/(100+220+300) and a full range of 6.2V. Probably to much 😉

  7. Hi
    Most battery charger modules come with a resistor to set the charging current to either 500mA or 1A. This is much more than what a typical small solar panel can provide.
    If you get a small solar panel with 5V 1.5W, you will have at most 300mA.
    The resistor should be changed to adapt the charging current.
    See TP4056 datasheet for more details.
    Very nice website by the way. I love it 🙂
    Best regards

  8. Hi,

    I have built a similar circuit and I suggest to put a diode ( 1N4004 or equivalent ) from the solar panel to the TP4056 board, to avoid reverse current.

    Vittorio

  9. Thanks a lot for such a useful tutorial.
    I request to give an exclusive tutorial for powering ESP32 board using 3V3 and Vin (V5) and ESP32 WROOM module using battery.
    Thanks again.

  10. Thanks a lot for the write-up! I built exactly this circuit, but the MCP1700-3302E isn’t cutting it for me. When waking from deep sleep on an ESP-WROOM-32 and turning the WiFi on, it seems the 250mA limit on the regulator is insufficient. It works _some times_, but for me it does not reliably wake up and connect successfully.

    While I don’t know enough to know what’s actually happening, it seems like maybe there’s a current spike up to ~350-400mA needed to keep things running smoothly. If anyone is trying this circuit out and things aren’t working, I’d recommend replacing the MCP1700-3302E with something with slightly higher current output (I think 500mA would be ample).

  11. Hi, in this article you use a 100uF capacitor with the voltage regulator while in your book Home Automation ESP8266 (4th edition) you use a 1000uF capacitor. Any comments?

Leave a Reply to Vittorio Calzolari Cancel reply

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.