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


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:


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!

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

        • 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?



      • 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?


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

      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.

  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.

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


  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?

  12. The MCP1700 is with its 250mA at the brink of what the ESP8266 can demand from time to time.
    Same goes for the popular HT7333.
    May I suggest the 500mA HT7833

  13. Merci pour vos tutoriels, très très biens!
    J’ai un problème avec cette alimentation. A vide j’ai bien les 3.3 V en sortie, mais dés que je branche un TTGO-T1 LoRa, elle s’écroule à 1.35 V (la pile est à 4.10 V)).
    SVP, avez vous une suggestion ?
    Merci d’avance et encore félicitations.

  14. Two 5V 1W Solar Panels seem to be not enough to charge my setup with the esp32.
    My location is southern germany.
    Thinking about adding a third solar panel.
    Any advice?

    • Hi Matt
      I’m using a single panel 6V 6W which can provide a charge current of 90mA in full sun (Paris FR suburbs) to charge a 1200mA LiPo.
      My ESP using Deepsleep takes a measure every 5 minutes. When disconnecting the panel, battery loose around 2.5mV per hour so I have around 15 days of full autonomy.
      I am now waiting for the battery to reach 3.1V before reconnecting the panel. I will be able to give a little more details on full recharge within 2 weeks.
      Happy to give more details on request.
      Best regards

      • Thanks for the info.
        I will look into my setup then.
        Two 5v 1.2W panels don’t manage to charge my battery properly.
        Only with direct sunlight it seems to charge.
        Had a cloudy sky yesterday and my sensor which takes hourly readings and uses deepsleep in between failed tonight at 11 pm…
        Might be something wrong with the panels

        • Sorry I wrote 6W but meant 0.6W => 100mA.
          You may want to monitor the status of the charging and charged indicators from the Tp4056. I removed the leds and resistors and connected the pins to GPIO with internal pull-up so I can include in my reports battery voltage and charging status.
          The sensor doesn’t received full sun before 2pm but on a bright day charging can start 1 hours before. I can have generally 2 to 3 hours of charging a day so probably equivalent to 200 (15-20% of battery capacity)
          My cycle is 14 sec active every 5 minutes.
          Have you check that your system is actually using very low power in deepsleep? Mine is around 40uA

          • My TP4056 seems to be charging continuously once it is on solar power. So even with the cloudy sky it is charging according to the LED.
            I have not checked the sleep state, right now it is not possible anymore without reworking a few solder joints ^^. Might do that if adding a third solar panel will not work. Might actually need a multimeter which is digital. With my regular analog one i won’t be able to measure the deepsleep power i am afraid

          • So i just replaced the two 5V 1W chinese panels with three german 6V 1W panels and everything works like a charm. Charges the battery to the maximum during the day, loosing roughly 6-7% over night, charging to the max again during the day.

            The reason why i want for a third panel is that i mounted it in a 15 degrees angle, that should provide better conversion rates during winter.

          • Ah “Deutsche Qualität” is the thing! 😂
            6V is better because the TP4056 need at least 4.6V at input which is available only in full sun with the 5V panels. So you have probably more hours of charging by this change.
            Organising the panels to cover larger angle is a great idea too 👍 I should do something like this too.

          • ^^ Now my sensor seems to stop working for a few hours at a time for no apparent reason. Last reading yesterday 11pm, next 8 am today, then skipped the next reading again.
            Not sure what is going on.
            I am suspecting that it might not find the bme from time to time and is then stuck in the
            if (!status) {
            Serial.println(“Could not find a valid BME280 sensor, check wiring or change I2C address!”);
            while (1);
            check. But that is just a wild guess….
            Would not explain why it suddenly starts working again after sometimes hours of not posting anything.

            Charging seems to work ok now.
            Was a really good idea to go with the 6V Panels 🙂

  15. Thank you for this project! Here are some things that I have learned:

    The NodeMCU 32-S boards (as well as ESP32 chips) ADC pins do not have a built-in divider, and inputs can be up to 3.3V. The NodeMCU 8266 does have a built-in divider on A0 only (the only ADC).
    The ESP32 ADC is not anywhere close to linear at the top of its range. So a voltage divider that puts the fully charged battery voltage of 4.2 volts, at the 3.3 ADC value is not accurate at all. https://randomnerdtutorials.com/wp-content/uploads/2019/05/ADC-non-linear-ESP32.png A voltage divider which puts the ADC value near 2 volts is better since the ADC is more or less linear in this range. This also makes the divider simpler, since you want to half the input voltage of 4.2 to 2.1 R1 and R2 can be equal.
    Larger R1 and R2 values mean less current flow, so the battery will last longer. I chose 220kOhm resistors. The constant current flow through that divider is 10 only microamps. I am not sure what the downside is to this choice, perhaps a slower response time since the divider will be much slower to change, but with a solar/battery ESP32 in sleep mode for most of its life, I don’t expect the voltage to change very quickly.

  16. Dear Sara and friends,

    First: A big “thank you” for your effort to share your projects and findings!
    I hope all is well in these strange “Corona times”…

    The ESP32 seems to be a nice device an since I am a hobby bee keeper I would like to setup a little “bee spy cam” system with the ESP32 and the camerea module. I already go the basics working, I get a stream in my browser etc.

    Now I want to extend this so it works autonomous/remotely on battery + solar charging. This tutorial seems to have all I need BUT…

    When I have the ESP32 Cam system running on 3.3V I see stripes in the picture/stream. Somewhere I read that this is related to the 3.3V operation and so I tested the setup powered with 5V. I can confirm that I don’t have problems or stripes when running on 5V.
    Or is that issue related to the camera (ID= 0x26)

    The question is: Which hardware components do I need (or change) to run the setup on 5V ?

    Some more questions…

    Suppose I want a really simple setp which only starts if there is enough irradiation. How much power (mA) does the ESP32+Cam need for running. Can I connect it directly to a 5V solar panel (or maybe it needs 2 panels in parallel to get enough power). How much overvoltage can it take, can I connect it to a 6V panel or is that too much already? Or any higher voltage panel with voltage stepdown?
    The market price of “regular” solar panels (200-300W, 34V, 7-9A) is only about 50 cent per watt, the “small” panels cost a lot more per watt.

    It seems the Wifi uses some power, so is there something like “wifi sleep” which wakes up when wifi remote access is detected? (not wake-on-lan but wake-on-wifi?)

    Bonus: Since bees only fly at daytime I want the system to go deepsleep over night
    Should this be handled via the internal clock or with a light sensor? Or bee-motion-detection ??
    This leads a a more general question: Should the logic be programmed into the ESP32 or should I just use it as a sensor and do the real (AI?) stuff on another mashine?
    (I have a raspberry running which checks some IP cameras with ‘motion’)

    Anyway, thank you for sharing and thank you for your support!

    BTW: I cannot find a paypal donate button, where is it 🙂
    Or how can we support your site?

    Best regards,

    • Hi Dieko.
      Thanks for sharing your project.
      In this example, the rechargeable batteries output 4.2V when fully charged.
      You can try powering the ESP32-CAM directly from that battery and see if it works as expected. I haven’t experimented it, so I’m not sure.
      Don’t connect the solar panels directly to the ESP32.
      If you want to power the ESP32-CAM using 5V, you can search how to power an Arduino (that works with 5V) using solar panels.

      To save battery, it is better to put the ESP32-CAM in deep sleep at night.
      It is also a good idea to integrate it with your other IP cameras using node-red.
      There are many options, you have to experiment and see which scenario works better in your case.

      To support our work, you can enroll in our premium courses: https://randomnerdtutorials.com/courses/
      You can also see our about page for another ways to support our work: https://randomnerdtutorials.com/about/

  17. Hi,
    i found the the following Information for the TP4056 on a Product Page.
    ” It is better that the charging current is 37% of the battery capacity. For example, the charging current should be 400 for the 1000mAH battery.”

    Adjust the output current from 100 to 1000ma by simply changing the fixed resistor on the circuit board.

    R1(KOhm) I(mA)
    30 50
    20 70
    10 130
    5 250
    4 300
    3 400
    2 580
    1.66 690
    1.5 780
    1.33 900
    1.2 1000

    So if you want 400 output current change R1 zu 3 kOhm e.g.
    Hope that this Info was helpful for someone.

    Ive ordered all the Parts and see what happens in Reality 🙂


Leave a Reply to barbudor 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.