Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.
Overview
This guide will walk you through configuring the GLYPH-C3 board to measure the voltage and charge percentage of a Li-ion or Li-Polymer(LiPo) battery. You will learn how to set up the board, connect the battery, and display the voltage readings on the Serial Monitor.
Voltage Measurement
Battery voltage measurement is the process of determining the electrical potential difference between the positive and negative terminals of a battery. It provides a quantitative value in volts (V), which indicates the charge level and health of the battery. The voltage range of a battery depends on its chemistry (Li-ion, LiPo, NiMH, Lead-Acid, etc.). The correct minimum (empty) and maximum (full) voltage values must be set to measure the charge percentage accurately. You need to update the Battery object with the correct min and max voltages.Monitor Battery Health – Helps determine if the battery is functioning properly and whether it needs replacement. Prevent Overcharging & Deep Discharging – Ensures the battery is used within safe voltage limits to prolong its lifespan. Estimate Remaining Charge – Provides an approximate percentage of battery capacity remaining. Optimize Performance – Ensures the battery supplies the correct voltage for efficient device operation. Safety – Prevents excessive discharge or overvoltage conditions that may cause damage or overheating.
Step 1: Hardware Required
Glyph Board
Li-ion or Li-Polymer(LiPo) battery
Step 2: Circuit Diagram
Circuit Diagram with Lithium Ion Battery:
Circuit Diagram with Lithium Polymer Battery:
Step 3: Connect the Battery
First Short the MSR Pin at the back of the Glyph C3 board
Solder the Positive and Negative leads of the battery to the leads on the back of Glyph C3 which says BAT+ and BAT-
Connect the positive terminal of the battery to the analog input pin on the board.
Connect the negative terminal of the battery to the ground pin on the board.
Step 4: Code Setup
Open Arduino IDE.
Install the Battery Sense library by going to Sketch > Include Library > Manage Libraries and searching for Battery Sense
Copy and paste the following code into the Arduino IDE:
Arduino Code
CircuitPython Code
#include <Battery.h>Battery battery(3400, 4200, A0,12); //(Battery voltage varies between 3.4V (empty) and 4.2V (full charge) in Li-ion/LiPo batteries.//To convert raw ADC readings into actual battery percentage, the system needs a reference range (3400–4200 mV).//The analog pin (A0) reads a voltage between 0V and 3.3V (scaled using a voltage divider).//ADC resolution determines measurement accuracy (12-bit means values range from 0–4095).12 indicates the ADC Resolution bits for Glyph )/** * 1 cell li-ion/li-poly battery wired to A0 before voltage booster, on demand sensing on pin 3, linear mapping function * https://github.com/rlogiacco/BatterySense#lesser-than-5v-with-voltage-booster **/void setup() { Serial.begin(115200); while (!Serial); battery.begin(3300,1.585); //(voltage divider A voltage divider is a simple electrical circuit that reduces a higher voltage to a lower voltage. It is commonly used in battery voltage measurement to ensure that the ESP32 (or any microcontroller) receives a safe voltage within its ADC (Analog-to-Digital Converter range).//1.585 → Voltage Divider Ratio//Since batteries typically output voltages higher than ESP32’s ADC limit (3.3V max), a voltage divider is used to scale it down.//If your board has a different resistor divider, this value must be changed.//How to Change for Different Batteries?//If you have a higher voltage battery (e.g., 7.4V or 12V), you need://Larger R1 to drop more voltage.//A new voltage divider ratio in the battery.begin() function.)}void loop() { //Blinks the Onboard LED to indicate that the battery is connected and being measured. digitalWrite(1, HIGH); delay(500); digitalWrite(1, LOW); delay(500); Serial.print("Battery voltage is "); Serial.print(battery.voltage()); Serial.print(" ("); Serial.print(battery.level()); Serial.println("%)");}
For GLYPH C3, connect the battery to the BAT pads and close the MSR solder jumper as described above. The percentage is a voltage estimate, not a fuel-gauge reading. Calibrate the divider with a multimeter; never connect the cell directly to A0.Follow the CircuitPython setup guide and save this example as code.py on the board.
import timeimport analogioimport microcontrollerbattery_adc = analogio.AnalogIn(microcontroller.pin.GPIO0) # GLYPH C3 A0DIVIDER_RATIO = 1.585 # Match the board's battery-sense dividerCALIBRATION = 1.0 # Adjust after comparing with a multimeterEMPTY_V = 3.4FULL_V = 4.2while True: voltage = battery_adc.value * 3.3 / 65535 * DIVIDER_RATIO * CALIBRATION percent = max(0, min(100, int((voltage - EMPTY_V) * 100 / (FULL_V - EMPTY_V)))) print("Battery: {:.2f} V (about {}%)".format(voltage, percent)) time.sleep(2)
ADC Calibration and Real-World Accuracy
One important thing to understand is that ESP32 ADC readings are not always perfectly accurate.In real hardware, ADC readings can vary slightly due to:
ADC non-linearity
Resistor tolerances
Board variations
Noise
Because of this, a calibration factor is often used to fine tune the measured voltage.Example:
const float CALIBRATION_FACTOR = 1.14;
This calibration factor compensates for ADC measurement error and helps produce more accurate battery readings.This is a very common practice in embedded systems and battery-powered devices.
Why Future Revisions May Use Dedicated Fuel Gauge ICs
While ADC-based battery measurement works well, it still depends on calibration and voltage estimation.Future revisions of the GLYPH boards may use dedicated LiPo fuel gauge ICs over I2C for:
Improved Accuracy
Better Battery Estimation
More Stable Readings
These dedicated chips are specifically designed for battery monitoring applications.Here is the sample code with ADC Calibration
Select the Board and Port Do the following settings in your Arduino IDE, Do the following settings in your Arduino IDE,
Tools > Board > esp32 > Pcbcupid GLYPH C3
For the Pcbcupid GLYPH C3 to appear under Tools > Board > esp32, the esp32 board version installed in the Arduino IDE should be greater than or equal to 3.1.0.
Tools > Port and select the port connected to your GLYPH.
Tools > USB CDC on Boot >Enabled
If USB CDC on BOOT not enabled, you won’t be seeing any serial data on Arduino IDE.
Upload the Code
Click the upload button (➡️ icon) or use the shortcut CTRL + U in Arduino IDE to upload the code to the board. Note: Ensure that the voltage applied to the analog pin does not exceed the maximum allowable voltage (usually 3.3V for the ESP32).
Step 6: Observe the Output
See the LED Light up - After soldering the battery leads to the BAT+ & BAT- terminals and connecting your Glyph board to your PC, you can see the onboard led of your Glyph board light up like this:
Open Serial Monitor
In Arduino IDE, go toTools > Serial Monitor or pressCtrl+Shift+M to open the Serial Monitor.
View Battery Readings
You should see the current battery voltage & battery charge percentage every second on the Serial Monitor.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"PCB Cupid","colors":{"primary":"#0D9373"},"favicon":"https://mintcdn.com/pcbcupid-bae3761c/4dXNuJjZhqL5zqVd/images/favicon_PCBcupid.png?fit=max\u0026auto=format\u0026n=4dXNuJjZhqL5zqVd\u0026q=85\u0026s=697c4189e0a983e1722bddbedde79f61","appearance":{"strict":true},"background":{"decoration":"gradient"},"navbar":{"links":[{"href":"https://spell.pcbcupid.com","label":"Circuit Spell"},{"href":"https://shop.pcbcupid.com","label":"Shop"},{"href":"/","label":"Learn"},{"href":"https://events.pcbcupid.com","label":"Events"},{"href":"https://forum.pcbcupid.com","label":"Forum"},{"href":"https://pcbcupid.com/articles","label":"Articles"},{"href":"https://pcbcupid.com/tools","label":"Tools"}]},"seo":{"indexing":"all"},"fonts":{"family":"Space Grotesk","weight":400},"icons":{"library":"lucide"},"styling":{"eyebrows":"breadcrumbs","latex":true},"contextual":{"options":["copy","chatgpt","claude","cursor","vscode","mcp"],"display":"toc"},"thumbnails":{"appearance":"dark"},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"pcbcupid-bae3761c","hasAudioNarration":false,"actualSubdomain":"pcbcupid-bae3761c","customDomains":["learn.pcbcupid.com"],"gitSource":{"type":"github","owner":"pcbcupid","repo":"pcbcupid-docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"feedback":{"thumbs":true,"edits":true,"issues":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6ae268427b458a5c875a9a81","clientVersion":"0.0.4177","searchFilterCounts":[{"language":"default","tag":"Documentation","count":77},{"language":"default","tag":"Modules","count":67},{"language":"default","tag":"PCB Design","count":45},{"language":"default","tag":"Examples","count":32},{"language":"default","tag":"Glyph","count":25},{"language":"default","tag":"G-Mod","count":17},{"language":"default","tag":"KiCad","count":16},{"language":"default","tag":"Basic","count":15},{"language":"default","tag":"Welcome","count":9},{"language":"default","tag":"G-Sense","count":8}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[],"googleFontsInlined":true},"customCss":[],"page":{"pagePath":"guides/battery-measurement","slug":"/guides/battery-measurement","pageMetadata":{"title":"Battery Voltage Measurement","sidebarTitle":"Battery Measurement","description":"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.","href":"/guides/battery-measurement"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,hr:`hr`,img:`img`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,OptimizedFrame,OptimizedImage,Tab,Tabs,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!OptimizedFrame)_missingMdxReference(`OptimizedFrame`,true);if(!OptimizedImage)_missingMdxReference(`OptimizedImage`,true);if(!Tab)_missingMdxReference(`Tab`,true);if(!Tabs)_missingMdxReference(`Tabs`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(OptimizedFrame,{className:`mint-w-full mint-aspect-video mint-rounded-xl`,src:`https://www.youtube.com/embed/ecOe0DA1fdo?si=HSw3gWvhcsRfmBUM`,title:`YouTube video player`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:true}),`\n`,_jsx(Heading,{level:`2`,id:`overview`,children:`Overview`}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_lithiumpolymerbattery_side.avif`,alt:`Battery_charge`})}),`\n`,_jsxs(_components.p,{children:[`This guide will walk you through configuring the `,_jsx(_components.a,{href:`https://shop.pcbcupid.com/product/gd001/`,children:`GLYPH-C3 board`}),` to measure the voltage and charge percentage of a Li-ion or Li-Polymer(LiPo) battery. You will learn how to set up the board, connect the battery, and display the voltage readings on the Serial Monitor.`]}),`\n`,_jsx(Heading,{level:`1`,id:`voltage-measurement`,children:`Voltage Measurement`}),`\n`,_jsx(_components.p,{children:`Battery voltage measurement is the process of determining the electrical potential difference between the positive and negative terminals of a battery. It provides a quantitative value in volts (V), which indicates the charge level and health of the battery. The voltage range of a battery depends on its chemistry (Li-ion, LiPo, NiMH, Lead-Acid, etc.). The correct minimum (empty) and maximum (full) voltage values must be set to measure the charge percentage accurately. You need to update the Battery object with the correct min and max voltages.`}),`\n`,_jsx(_components.p,{children:`Monitor Battery Health – Helps determine if the battery is functioning properly and whether it needs replacement. Prevent Overcharging \u0026 Deep Discharging – Ensures the battery is used within safe voltage limits to prolong its lifespan. Estimate Remaining Charge – Provides an approximate percentage of battery capacity remaining. Optimize Performance – Ensures the battery supplies the correct voltage for efficient device operation. Safety – Prevents excessive discharge or overvoltage conditions that may cause damage or overheating.`}),`\n`,_jsx(Heading,{level:`2`,id:`step-1-hardware-required`,children:`Step 1: Hardware Required`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`Glyph Board`}),`\n`,_jsx(_components.li,{children:`Li-ion or Li-Polymer(LiPo) battery`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`step-2-circuit-diagram`,children:`Step 2: Circuit Diagram`}),`\n`,_jsx(Heading,{level:`4`,id:`circuit-diagram-with-lithium-ion-battery`,children:`Circuit Diagram with Lithium Ion Battery:`}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_lithiumionbattery_cirkitdiagram.avif`,alt:`pcbcupid_liion_battery_circuitdiagram`})}),`\n`,_jsx(Heading,{level:`4`,id:`circuit-diagram-with-lithium-polymer-battery`,children:`Circuit Diagram with Lithium Polymer Battery:`}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_lithiumpolymerbattery_circuitdiagram.avif`,alt:`pcbcupid_lipolymer_battery_circuitdiagram`})}),`\n`,_jsx(Heading,{level:`2`,id:`step-3-connect-the-battery`,children:`Step 3: Connect the Battery`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`First Short the MSR Pin at the back of the Glyph C3 board`}),`\n`,_jsx(_components.li,{children:`Solder the Positive and Negative leads of the battery to the leads on the back of Glyph C3 which says BAT+ and BAT-`}),`\n`,_jsx(_components.li,{children:`Connect the positive terminal of the battery to the analog input pin on the board.`}),`\n`,_jsx(_components.li,{children:`Connect the negative terminal of the battery to the ground pin on the board.`}),`\n`]}),`\n`,_jsx(`div`,{class:`centerImg`,children:_jsx(OptimizedImage,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_msr_lithiumionbattery.avif`,alt:`pcbcupid-smowcode-window-setup`,width:`600`})}),`\n`,_jsx(`div`,{style:{textAlign:`center`},children:_jsx(OptimizedImage,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_msr_lithiumionbattery.avif`,alt:`pcbcupid-smowcode-window-setup`,width:`600`})}),`\n`,_jsx(`br`,{}),`\n`,_jsx(`br`,{}),`\n`,_jsx(Heading,{level:`2`,id:`step-4-code-setup`,children:`Step 4: Code Setup`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.strong,{children:`Open Arduino IDE.`})}),`\n`,_jsxs(_components.li,{children:[`Install the `,_jsx(_components.strong,{children:`Battery Sense`}),` library by going to `,_jsx(_components.code,{children:`Sketch > Include Library > Manage Libraries`}),` and searching for Battery Sense`]}),`\n`,_jsx(_components.li,{children:`Copy and paste the following code into the Arduino IDE:`}),`\n`]}),`\n`,_jsxs(Tabs,{children:[_jsx(Tab,{title:`Arduino Code`,id:`arduino-code`,children:_jsx(CodeBlock,{filename:``,numberOfLines:`39`,language:`cpp`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`cpp`,children:_jsxs(_components.code,{language:`cpp`,numberOfLines:`39`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \u003cBattery.h>`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:`Battery`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` battery`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3400`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`4200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:`A0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`12`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` //(Battery voltage varies between 3.4V (empty) and 4.2V (full charge) in Li-ion/LiPo batteries.`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//To convert raw ADC readings into actual battery percentage, the system needs a reference range (3400–4200 mV).`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//The analog pin (A0) reads a voltage between 0V and 3.3V (scaled using a voltage divider).`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//ADC resolution determines measurement accuracy (12-bit means values range from 0–4095).12 indicates the ADC Resolution bits for Glyph )`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`/**`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` * 1 cell li-ion/li-poly battery wired to A0 before voltage booster, on demand sensing on pin 3, linear mapping function`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` * https://github.com/rlogiacco/BatterySense#lesser-than-5v-with-voltage-booster`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` **/`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` setup`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() `})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`\tSerial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`begin`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`115200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`\twhile`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`Serial);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`\tbattery`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`begin`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3300`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1.585`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` //(voltage divider A voltage divider is a simple electrical circuit that reduces a higher voltage to a lower voltage. It is commonly used in battery voltage measurement to ensure that the ESP32 (or any microcontroller) receives a safe voltage within its ADC (Analog-to-Digital Converter range).`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//1.585 → Voltage Divider Ratio`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//Since batteries typically output voltages higher than ESP32’s ADC limit (3.3V max), a voltage divider is used to scale it down.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//If your board has a different resistor divider, this value must be changed.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//How to Change for Different Batteries?`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//If you have a higher voltage battery (e.g., 7.4V or 12V), you need:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//Larger R1 to drop more voltage.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`//A new voltage divider ratio in the battery.begin() function.)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` loop`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() `})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` //Blinks the Onboard LED to indicate that the battery is connected and being measured.`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`\tdigitalWrite`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, HIGH);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`\tdelay`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`500`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`\tdigitalWrite`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, LOW);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`\tdelay`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`500`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`\tSerial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Battery voltage is \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`\tSerial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`battery`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`voltage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`());`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`\tSerial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\" (\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`\tSerial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`battery`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`level`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`());`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`\tSerial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`println`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"%)\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})}),_jsxs(Tab,{title:`CircuitPython Code`,id:`circuitpython-code`,children:[_jsx(_components.p,{children:`For GLYPH C3, connect the battery to the BAT pads and close the MSR solder jumper as described above. The percentage is a voltage estimate, not a fuel-gauge reading. Calibrate the divider with a multimeter; never connect the cell directly to A0.`}),_jsxs(_components.p,{children:[`Follow the `,_jsx(_components.a,{href:`/documentation/welcome/prerequisites/circuitpython-setup-guide`,children:`CircuitPython setup guide`}),` and save this example as `,_jsx(_components.code,{children:`code.py`}),` on the board.`]}),_jsx(CodeBlock,{filename:``,numberOfLines:`15`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`15`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` time`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` analogio`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` microcontroller`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`battery_adc `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` analogio.AnalogIn(microcontroller.pin.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`GPIO0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# GLYPH C3 A0`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`DIVIDER_RATIO`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1.585`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Match the board's battery-sense divider`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`CALIBRATION`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1.0`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Adjust after comparing with a multimeter`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`EMPTY_V`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 3.4`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`FULL_V`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 4.2`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`while`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` voltage `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` battery_adc.value `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 3.3`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` /`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 65535`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` *`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` DIVIDER_RATIO`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` *`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` CALIBRATION`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` percent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` max`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`min`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`100`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`((voltage `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` EMPTY_V`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 100`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` /`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`FULL_V`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` EMPTY_V`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))))`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Battery: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{:.2f}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` V (about `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`%)\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.format(voltage, percent))`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` time.sleep(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`adc-calibration-and-real-world-accuracy`,children:`ADC Calibration and Real-World Accuracy`}),`\n`,_jsx(_components.p,{children:`One important thing to understand is that ESP32 ADC readings are not always perfectly accurate.`}),`\n`,_jsx(_components.p,{children:`In real hardware, ADC readings can vary slightly due to:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`ADC non-linearity`}),`\n`,_jsx(_components.li,{children:`Resistor tolerances`}),`\n`,_jsx(_components.li,{children:`Board variations`}),`\n`,_jsx(_components.li,{children:`Noise`}),`\n`]}),`\n`,_jsx(_components.p,{children:`Because of this, a calibration factor is often used to fine tune the measured voltage.`}),`\n`,_jsx(_components.p,{children:`Example:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`cpp`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`cpp`,children:_jsxs(_components.code,{language:`cpp`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` CALIBRATION_FACTOR `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1.14`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:` `}),`\n`,_jsx(_components.p,{children:`This calibration factor compensates for ADC measurement error and helps produce more accurate battery readings.`}),`\n`,_jsx(_components.p,{children:`This is a very common practice in embedded systems and battery-powered devices.`}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`3`,id:`why-future-revisions-may-use-dedicated-fuel-gauge-ics`,children:`Why Future Revisions May Use Dedicated Fuel Gauge ICs`}),`\n`,_jsx(_components.p,{children:`While ADC-based battery measurement works well, it still depends on calibration and voltage estimation.`}),`\n`,_jsx(_components.p,{children:`Future revisions of the GLYPH boards may use dedicated LiPo fuel gauge ICs over I2C for:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Improved Accuracy`}),`\n`,_jsx(_components.li,{children:`Better Battery Estimation`}),`\n`,_jsx(_components.li,{children:`More Stable Readings`}),`\n`]}),`\n`,_jsx(_components.p,{children:`These dedicated chips are specifically designed for battery monitoring applications.`}),`\n`,_jsx(_components.p,{children:`Here is the sample code with ADC Calibration`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`50`,language:`cpp`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`cpp`,children:_jsxs(_components.code,{language:`cpp`,numberOfLines:`50`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// ADC configuration`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#define`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#569CD6`},children:` BATTERY_PIN`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#569CD6`},children:` A0`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` VOLTAGE_DIVIDER_RATIO `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 2.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // 200k:200k divider`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ADC_REF_VOLTAGE `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 3.3`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // ESP32 ADC reference`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` CALIBRATION_FACTOR `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1.14`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` MIN_VOLTAGE `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 3.2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Battery empty`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` MAX_VOLTAGE `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 4.2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Battery full`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Read battery voltage and A0`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` readBatteryVoltage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`int\u0026`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` rawADC`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float\u0026`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` v_adc`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` rawADC `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` analogRead`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(BATTERY_PIN);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` v_adc `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (rawADC `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`/`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 4095.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ADC_REF_VOLTAGE `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` CALIBRATION_FACTOR;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` batteryVoltage `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` v_adc `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` VOLTAGE_DIVIDER_RATIO;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` batteryVoltage;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Map float`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` mapFloat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` x`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` in_min`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` in_max`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` out_min`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` out_max`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (x `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` in_min) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (out_max `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` out_min) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`/`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (in_max `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` in_min) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` out_min;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Battery percentage`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`int`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` calculateBatteryPercentage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`float`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` voltage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` voltage `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` constrain`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(voltage, MIN_VOLTAGE, MAX_VOLTAGE);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` percent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` mapFloat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(voltage, MIN_VOLTAGE, MAX_VOLTAGE, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`100`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)percent;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` setup`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`begin`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`115200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` analogReadResolution`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`12`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // 12-bit ADC`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` analogSetAttenuation`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(ADC_11db);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Full-scale input ~3.3V`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` pinMode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(BATTERY_PIN, INPUT);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` loop`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` rawADC;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` v_adc;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` batteryVoltage `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` readBatteryVoltage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(rawADC, v_adc);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` batteryPercent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` calculateBatteryPercentage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(batteryVoltage);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`println`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"=== Battery Monitor ===\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`printf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Raw ADC Value: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:`%d`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, rawADC);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`printf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Voltage at A0: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:`%.3f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` V`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, v_adc);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`printf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Battery Voltage: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:`%.3f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` V`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, batteryVoltage);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`printf`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Battery Percentage: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#9CDCFE`},children:`%d%%`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, batteryPercent);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`println`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` delay`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Update every 2 seconds`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`step-5-upload-the-code`,children:`Step 5: Upload the Code`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.strong,{children:`Connect the Board`})}),`\n`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Connect your GLYPH board to your computer`}),`\n`]}),`\n`,_jsxs(_components.ol,{start:`2`,children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Select the Board and Port`}),` Do the following settings in your Arduino IDE, Do the following settings in your Arduino IDE,`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.code,{children:`Tools > Board > esp32 > Pcbcupid GLYPH C3`})}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`For the `,_jsx(_components.code,{children:`Pcbcupid GLYPH C3 `}),` to appear under `,_jsx(_components.code,{children:`Tools > Board > esp32`}),`, the esp32 board version installed in the Arduino IDE should be greater than or equal to 3.1.0.`]})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`Tools > Port`}),` and select the port connected to your GLYPH.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`Tools > USB CDC on Boot >`}),` `,_jsx(_components.em,{children:_jsx(_components.strong,{children:`Enabled`})})]}),`\n`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`If `,_jsx(_components.code,{children:`USB CDC on BOOT`}),` not enabled, you won’t be seeing any serial data on Arduino IDE.`]})}),`\n`,_jsxs(_components.ol,{start:`3`,children:[`\n`,_jsx(_components.li,{children:_jsx(_components.strong,{children:`Upload the Code`})}),`\n`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Click the upload button (➡️ icon) or use the shortcut `,_jsx(_components.code,{children:`CTRL + U`}),` in Arduino IDE to upload the code to the board. `,_jsx(_components.strong,{children:`Note:`}),` Ensure that the voltage applied to the analog pin does not exceed the maximum allowable voltage (usually 3.3V for the ESP32).`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`step-6-observe-the-output`,children:`Step 6: Observe the Output`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`See the LED Light up`}),` - After soldering the battery leads to the BAT+ \u0026 BAT- terminals and connecting your Glyph board to your PC, you can see the onboard led of your Glyph board light up like this:`]}),`\n`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_lithiumion_battery.avif`,alt:`pcbcupid_bh1750adafruit`})}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_lithiumpolymerbattery-ledblink.avif`,alt:`pcbcupid_bh1750adafruit`})}),`\n`,_jsxs(_components.ol,{start:`2`,children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Open Serial Monitor`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`In Arduino IDE, go to`,_jsx(_components.code,{children:`Tools > Serial Monitor`}),` or press`,_jsx(_components.code,{children:`Ctrl+Shift+M`}),` to open the Serial Monitor.`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`View Battery Readings`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`You should see the current battery voltage \u0026 battery charge percentage every second on the Serial Monitor.`}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/battery/PCBCUPID_lithiumpolymerbattery_serialmon.avif`,alt:`Battery_charge`})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Battery Voltage Measurement","sidebarTitle":"Battery Measurement","description":"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.","href":"/guides/battery-measurement"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Overview","slug":"overview","depth":2,"children":[]},{"title":"Voltage Measurement","slug":"voltage-measurement","depth":1,"children":[]},{"title":"Step 1: Hardware Required","slug":"step-1-hardware-required","depth":2,"children":[]},{"title":"Step 2: Circuit Diagram","slug":"step-2-circuit-diagram","depth":2,"children":[{"title":"Circuit Diagram with Lithium Ion Battery:","slug":"circuit-diagram-with-lithium-ion-battery","depth":4,"children":[]},{"title":"Circuit Diagram with Lithium Polymer Battery:","slug":"circuit-diagram-with-lithium-polymer-battery","depth":4,"children":[]}]},{"title":"Step 3: Connect the Battery","slug":"step-3-connect-the-battery","depth":2,"children":[]},{"title":"Step 4: Code Setup","slug":"step-4-code-setup","depth":2,"children":[{"title":"ADC Calibration and Real-World Accuracy","slug":"adc-calibration-and-real-world-accuracy","depth":3,"children":[]},{"title":"Why Future Revisions May Use Dedicated Fuel Gauge ICs","slug":"why-future-revisions-may-use-dedicated-fuel-gauge-ics","depth":3,"children":[]}]},{"title":"Step 5: Upload the Code","slug":"step-5-upload-the-code","depth":2,"children":[]},{"title":"Step 6: Observe the Output","slug":"step-6-observe-the-output","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"dynamicCss":".mint-aspect-video {\n aspect-ratio: 16 / 9\n}\n.mint-w-full {\n width: 100%\n}\n.mint-rounded-xl {\n border-radius: 0.75rem\n}","subdomain":"pcbcupid-bae3761c","siteName":"PCB Cupid","title":"Battery Voltage Measurement - PCB Cupid","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-17T08:18:02.759Z","originalFileLocation":"guides/battery-measurement.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.\">\u003cmeta data-mint-head name=\"application-name\" content=\"PCB Cupid\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Battery Voltage Measurement - PCB Cupid\">\u003cmeta data-mint-head property=\"og:description\" content=\"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"PCB Cupid\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://learn.pcbcupid.com/guides/battery-measurement\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://pcbcupid-bae3761c.mintlify.site/_mintlify/api/og/v2?division=Basic\u0026amp;title=Battery+Voltage+Measurement\u0026amp;description=Read+battery+voltage+on+a+Glyph+ESP32+board+using+the+onboard+voltage+divider%2C+scale+the+ADC+reading%2C+and+report+state+of+charge+to+the+serial+monitor.\u0026amp;theme=2c7e3818cca0f9e7f4434aa9\u0026amp;signature=63b6b747a6009515e07644ad2e6d71d4e153f2579bb8988beedef1b955d213fc\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Battery Voltage Measurement - PCB Cupid\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://pcbcupid-bae3761c.mintlify.site/_mintlify/api/og/v2?division=Basic\u0026amp;title=Battery+Voltage+Measurement\u0026amp;description=Read+battery+voltage+on+a+Glyph+ESP32+board+using+the+onboard+voltage+divider%2C+scale+the+ADC+reading%2C+and+report+state+of+charge+to+the+serial+monitor.\u0026amp;theme=2c7e3818cca0f9e7f4434aa9\u0026amp;signature=63b6b747a6009515e07644ad2e6d71d4e153f2579bb8988beedef1b955d213fc\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"PCB Cupid\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#0D9373\">\u003clink data-mint-head rel=\"canonical\" href=\"https://learn.pcbcupid.com/guides/battery-measurement\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/guides/battery-measurement.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://learn.pcbcupid.com/#organization\",\"name\":\"PCB Cupid\",\"url\":\"https://learn.pcbcupid.com\"},{\"@type\":\"WebSite\",\"@id\":\"https://learn.pcbcupid.com#website\",\"name\":\"PCB Cupid\",\"url\":\"https://learn.pcbcupid.com\",\"publisher\":{\"@id\":\"https://learn.pcbcupid.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://learn.pcbcupid.com/guides/battery-measurement#webpage\",\"url\":\"https://learn.pcbcupid.com/guides/battery-measurement\",\"name\":\"Battery Voltage Measurement\",\"description\":\"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.\",\"dateModified\":\"2026-10-17T08:18:02.759Z\",\"isPartOf\":{\"@id\":\"https://learn.pcbcupid.com#website\"},\"breadcrumb\":{\"@id\":\"https://learn.pcbcupid.com/guides/battery-measurement#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://learn.pcbcupid.com/guides/battery-measurement#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Basic\",\"item\":\"https://learn.pcbcupid.com/guides/arduino-ide-blink-led\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Battery Voltage Measurement\",\"item\":\"https://learn.pcbcupid.com/guides/battery-measurement\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://learn.pcbcupid.com/guides/battery-measurement#article\",\"headline\":\"Battery Voltage Measurement\",\"name\":\"Battery Voltage Measurement\",\"description\":\"Read battery voltage on a Glyph ESP32 board using the onboard voltage divider, scale the ADC reading, and report state of charge to the serial monitor.\",\"url\":\"https://learn.pcbcupid.com/guides/battery-measurement\",\"mainEntityOfPage\":{\"@id\":\"https://learn.pcbcupid.com/guides/battery-measurement#webpage\"},\"dateModified\":\"2026-10-17T08:18:02.759Z\",\"publisher\":{\"@id\":\"https://learn.pcbcupid.com/#organization\"},\"isPartOf\":{\"@id\":\"https://learn.pcbcupid.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"PCB Cupid\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"PCB Cupid\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/guides/battery-measurement.md","siteName":"PCB Cupid","nav":{"global":null,"tabs":[{"tab":"Documentation","pages":[{"title":"Documentation","href":""}]},{"tab":"Examples","pages":[{"group":"Basic","pages":[{"title":"Blink LED","sidebarTitle":"Blink LED","href":"/guides/arduino-ide-blink-led"},{"description":"Read analog values from a potentiometer and drive PWM outputs on the Glyph ESP32 development board using analogRead and analogWrite in Arduino.","title":"Analog Input and Output","sidebarTitle":"Reading Analog Input","href":"/guides/reading-analoginput"},{"title":"Battery Voltage Measurement","sidebarTitle":"Battery Measurement","href":"/guides/battery-measurement"},{"description":"Run an I2C scanner sketch on a Glyph ESP32 development board to discover the 7-bit addresses of connected I2C sensors, displays, and modules.","title":"I2C Scanner","sidebarTitle":"I2C Scanner","href":"/guides/i2c-scan-test"},{"title":"BH1750 Adafruit Sensor","sidebarTitle":"BH1750 Sensor","href":"/guides/bh1750adafruit-compatibility"},{"title":"Parallel LCD Display","sidebarTitle":"Parallel LCD","href":"/guides/lcd"},{"title":"I2C LCD Display","sidebarTitle":"I2C LCD","href":"/guides/lcd-i2c"},{"title":"Rotary Encoder with Glyph ESP32-C6","sidebarTitle":"Rotary Encoder","href":"/guides/rotor-encoder-with-glyph-c6"},{"title":"Servo Motor Control with Glyph C6","sidebarTitle":"Servo Motor","href":"/guides/servo-motor-with-glyph-c6"},{"title":"Stepper Motor","sidebarTitle":"Stepper Motor","href":"/guides/stepper-motor-with-drv8833"},{"title":"OpenWeatherMap REST API","sidebarTitle":"REST API Weather","href":"/guides/temperature-monitoring-using-glyph"},{"title":"OLED Display Test","sidebarTitle":"OLED Display","href":"/guides/display-test"},{"title":"REST API Weather on SH1106 OLED","sidebarTitle":"REST API Weather with OLED","href":"/guides/temperaturemonitoring-glyph+sh1106oled"},{"title":"DHT Sensor One-Wire Communication","sidebarTitle":"DHT Sensor One-Wire","href":"/guides/dht-onewire-communication"},{"title":"Unipolar Stepper Motor (28BYJ-48)","sidebarTitle":"Unipolar Stepper Motor","href":"/guides/unipolar-stepper-motor"}]},{"group":"Kits","pages":[{"title":"Beginner Kit with GLYPH-C6","sidebarTitle":"Beginner Kit","href":"/guides/kits/beginner-kit"},{"title":"GLYPH Voice Kit","sidebarTitle":"GLYPH Voice Kit","href":"/guides/kits/glyph-voice"},{"title":"GLYPH MIDI Controller Kit","sidebarTitle":"GLYPH MIDI Controller","href":"/guides/kits/glyph-midi-controller"},{"title":"GLYPH Tank Kit","sidebarTitle":"GLYPH Tank Kit","href":"/guides/kits/glyph-tank"}]},{"group":"AI","pages":[{"title":"ESP32-C3 Voice Chatbot","sidebarTitle":"Voice Chatbot","href":"/guides/ai/esp32-c3-voice-chatbot"},{"title":"Z-Claw AI","sidebarTitle":"Z-Claw AI","href":"/guides/ai/z-claw"},{"title":"Edge Impulse Gesture Recognition","sidebarTitle":"Edge Impulse","href":"/guides/ai/edge-impulse"}]},{"group":"Basic Sensors","pages":[{"title":"HC-SR04 Ultrasonic Sensor","sidebarTitle":"Ultrasonic Sensor","href":"/guides/basic-sensors/ultrasonic-sensor"},{"title":"Flame Sensor Test","sidebarTitle":"Flame Sensor","href":"/guides/basic-sensors/flame-sensor"},{"title":"IR Sensor","sidebarTitle":"IR Sensor","href":"/guides/basic-sensors/infrared-sensor"},{"title":"LDR Light Sensor","sidebarTitle":"LDR Light Sensor","href":"/guides/basic-sensors/ldr"},{"title":"MQ2 Gas Sensor","sidebarTitle":"MQ2 Gas Sensor","href":"/guides/basic-sensors/mq2-sensor"},{"title":"Touch Sensor (TTP223)","sidebarTitle":"Touch Sensor","href":"/guides/basic-sensors/touch-sensor"}]},{"group":"Bluetooth","pages":[{"title":"BLE Server Demo","sidebarTitle":"BLE Server","href":"/guides/bluetooth/bluetoothglyph"}]},{"group":"WiFi","pages":[{"title":"Control a Dual Relay over Wi-Fi","sidebarTitle":"Wi-Fi Dual Relay","href":"/guides/wifi/local-webserver-to-control-relay"},{"title":"Create a Wi-Fi Access Point on Glyph","sidebarTitle":"Wi-Fi Access Point","href":"/guides/wifi/wifiaccess-point"}]},{"group":"Zigbee","pages":[{"title":"Arduino Zigbee Blink: C6 to H2","sidebarTitle":"Zigbee Blink","href":"/guides/zigbee/arduino-zigbee-blink"}]}]},{"tab":"PCB Design","pages":[{"title":"PCB Design","href":"/pcb-design/design/kicad/introduction-on-kicad"}]}]},"basePath":"","title":"Battery Voltage Measurement - PCB Cupid","deploymentId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","buildId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","dynamics":["a74be98ba7"],"chunks":["zoom-image-lightbox-DQG3o8Eu.js","lightbox-handle-r17bVUz3.js"]}