• 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 3 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 3 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 3 years ago

Hi Rui
4.2v
ESP32
Arduino IDE

0 Vote Up Vote Down
Rui Santos Staff answered 3 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

  • [eBook Updated] Firebase Web App with ESP32 and ESP8266 (version 1.2) April 25, 2022
  • [eBook Updated] MicroPython Programming with ESP32 and ESP8266 (version 1.3) February 7, 2022

You must be logged in to view this content.

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

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