{"id":50485911,"url":"https://github.com/inf0matics/esp-battery-shield","last_synced_at":"2026-06-01T22:02:52.654Z","repository":{"id":244674025,"uuid":"815916776","full_name":"inf0matics/esp-battery-shield","owner":"inf0matics","description":"This project demonstrates how to connect a 3.7V LiPo battery to the LiPo shield for the D1 and enables the ability to read the battery voltage.","archived":false,"fork":false,"pushed_at":"2024-06-16T15:16:05.000Z","size":1906,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T21:06:17.157Z","etag":null,"topics":["battery-shield","esp32"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inf0matics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-16T14:19:04.000Z","updated_at":"2024-06-16T15:16:08.000Z","dependencies_parsed_at":"2024-06-16T17:25:24.661Z","dependency_job_id":"dda05c22-503e-43c1-9018-e40a8ad3bb15","html_url":"https://github.com/inf0matics/esp-battery-shield","commit_stats":null,"previous_names":["thespielplatz/esp-battery-shield","inf0matics/esp-battery-shield"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/inf0matics/esp-battery-shield","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0matics%2Fesp-battery-shield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0matics%2Fesp-battery-shield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0matics%2Fesp-battery-shield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0matics%2Fesp-battery-shield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inf0matics","download_url":"https://codeload.github.com/inf0matics/esp-battery-shield/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0matics%2Fesp-battery-shield/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33795114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["battery-shield","esp32"],"created_at":"2026-06-01T22:02:50.669Z","updated_at":"2026-06-01T22:02:52.649Z","avatar_url":"https://github.com/inf0matics.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ESP32 - Battery Shield \n_by [#thespielplatz](https://t.me/thespielplatz)_\n\n[![MIT License Badge](docs/img/license-badge.svg)](LICENSE)\n\nThis project demonstrates how to connect a 3.7V LiPo battery to the LiPo shield for the D1 and enables the ability to read the battery voltage.\n\n## Hardware\n\n### Used Hardware\n\n* AZ-Delivery: [Battery Shield for lithium batteries for D1 Mini\n](https://www.az-delivery.de/en/products/batterie-shield-fuer-lithium-batterien-fuer-d1-mini)\n* BerryBase: [Battery / LiPo Shield für D1 Mini](https://www.berrybase.de/en/battery/lipo-shield-fuer-d1-mini)\n\n### Wireing\n\nWhen measuring higher voltages (like a battery) with the ESP32 ADC, you typically use a voltage divider to scale down the voltage to a range the ADC can handle. A voltage divider uses two resistors (R1 and R2) to scale down the input voltage.\n\n```bash\n  + Battery\n    |\n   [R1] 4.7kΩ \n    |\n    |--- ADC (ESP32 Pin 36)\n    |\n   [R2] 10.0kΩ\n    |\n   GND\n```\n\nThe formula for the output voltage $V_{Battery}$ from the voltage divider is:\n\n$V_{adc} = V_{Battery} \\times \\frac{R2}{R1 + R2}$\n\n\u003cimg src=\"docs/battery-shield-front.jpg\" height=\"250px\"\u003e \u003cimg src=\"docs/battery-shield-back.jpg\" height=\"250px\"\u003e\n\n### How to Get the Battery Percentage\n\nThe [Analog to Digital Converter (ADC)\n](https://docs.espressif.com/projects/esp-idf/en/v4.4/esp32/api-reference/peripherals/adc.html) of the ESP32 operates within a voltage range of 0V to 3.3V and has a 12-bit resolution, meaning it can represent values from 0 to 4095.\n\nTo read the analog value from the ADC pin, use the following code:\n\n```cpp\nint adcPin = 36\nfloat analogValue = analogRead(adcPin);\n```\n\nNext, convert the analog value to the pin voltage:\n\n```cpp\nfloat pinVoltage = analogValue * (3.3 / 4095.0);\n```\n\n**Reverse the Voltage Divider Calculation**\n\nWhen measuring higher voltages (like a battery) with the ESP32 ADC, you typically use a voltage divider to scale down the voltage to a range the ADC can handle. A voltage divider uses two resistors (R1 and R2) to scale down the input voltage. The formula for the output voltage $V_{Battery}$ from the voltage divider is:\n\n$V_{Battery} = V_{adc} \\times \\frac{R1 + R2}{R2}$\n\nHere's how you can apply this in code:\n\n```cpp\nfloat batteryVoltage = pinVoltage / R2 * (R1 + R2);\n```\n\nThis formula rearranges the terms to solve for $V_{Battery}$, allowing you to calculate the actual battery voltage from the measured pin voltage. For a 3.7V LiPo battery, the voltage range is 3.0V for 0% capacity and 4.2V for 100% capacity. Calculate the battery percentage as follows:\n\n```cpp\nfloat batteryVoltage = getVoltage();\nif (batteryVoltage \u003c vmin) batteryVoltage = vmin;\nif (batteryVoltage \u003e vmax) batteryVoltage = vmax;\nfloat percentage (batteryVoltage - vmin) / (vmax - vmin) * 100.0;\n```\n\nBy following these steps, you can determine the battery percentage of a 3.7V LiPo battery using the ESP32 ADC.\n\n## Additional Resources\n\n### ESP32 ADC Pins (Analog to Digital Converter)\n\n- ESP32 D1 Analog Input Pins: 0V - 3V3, 12-bit (4096 values)\n- [Tutorial](https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/)\n\n\u003e [!IMPORTANT]  \n\u003e The ADC can only measure a voltage between 0 and 3.3V. You cannot directly measure analog voltages between 0 and 5V.\n\n\u003e [!WARNING]  \n\u003e ADC2 cannot be used with enabled WiFi since it is used internally by the WiFi driver. Since there is a good chance of using WiFi on a microcontroller designed to use it, only the ADC1 and its 8 channels can be used.\n\n### Battery Shield\n\n#### Product Description\n\nThis lithium battery shield provides a means of powering your D1 mini, or D1 mini Pro from a single cell (3.7V) lithium battery via a JST PH 2mm 2Pin connector. The shield contains a DC-DC converter to step-up the batteries 3.7V to 5V supplying your D1 Mini and shields with up to 1A of power. When the battery is depleted simply plug the shield into a USB power source using a mini USB cable and it will automatically recharge the battery. Two LEDs on the shield indicate when the battery is charging and when charging has completed.\n\n- [AZ Devlivery Lipo Shield Datasheet](docs/D1%20mini%20Battery%20Shield%20DE.pdf)\n- [BerryBase Lipo Shield Datasheet](docs/Battery-LiPo-Shield-fuer-D1-Mini.pdf)\n\n#### Features\n\n- Charging Voltage: max: 10V, recommended: 5V\n- Charging Current: 500mA / 1A\n- Lithium Battery Voltage: 3.3-4.2V\n- Boost Power Supply: 5V(max: 1A)\n- Dimensions: 28.5x26x7mm\n\n#### Pins\n\n- 5V: 5V(max: 1A) Power Supply\n- GND: Ground\n\n#### Connections\n\n- XH-2.54MM (Port 1): Connection to Lithium Battery (normally 3.3-4.2V)\n- Micro USB (Port 2): Charging Port (normally 5V)\n- Blue LED lights up when charging is complete.\n- Red LED lights up during charging.\n- J1: Set the maximum charging current to 0.5A or 1A.\n\n\n## Tip Me\n\nIf you like this project, give it a star! If you love it, fork it and take it out for dinner. 🌟🍽️ And hey, why not [send some tip love?](https://thespielplatz.com/tip-jar)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finf0matics%2Fesp-battery-shield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finf0matics%2Fesp-battery-shield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finf0matics%2Fesp-battery-shield/lists"}