• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Battery level

Q&A Forum › Battery level
0 Vote Up Vote Down
Brian Webb asked 6 years ago

If we wanted to get the battery level as a voltage value (say 3.1v) rather than a % what should we do?

3 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Hello Brian, I need more details:

  • What’s the maximum voltage of your battery?
  • Which board are you using?
  • Which programming language?

Regards,
Rui

0 Vote Up Vote Down
Brian Webb answered 6 years ago

Hi Rui
4.2v
ESP32
Arduino IDE

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Hello Brian,

You can find that answer in this thread: https://rntlab.com/question/get-battery-level/

You need to do what Sara already suggested. First, you need to use a voltage divider in the battery (so it only outputs 3.3V, because that’s the maximum voltage the ESP32 GPIOs can read): https://rntlab.com/esp32-lora-sender-solar-powered-part-4/

In line 133 of the code https://github.com/RuiSantosdotme/ESP32-Course/blob/master/code/LoRa_Project/LoRa_Sender/LoRa_Sender.ino you should use something as follows:

batteryLevel = map(analogRead(batteryPin), 0.0f, 4095.0f, 0, 3.3);

Instead of mapping to a range of 0 to 100, you use a range of 0 to 3.3V.

I haven’t tested this, but I think it should definitely work.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.