MKR1200 - ADC_Battery variable doesn't change


With my MKR1200, I tried to read the battery level and it doesn’t work.
I read this variable with this function int sensorValue = analogRead(ADC_BATTERY);
and the variable sensorValue send me always the same value???

It’s the same like if we do => analogRead(32)

A battery is connected on green screw terminals and I’m using the serial port from the pins.
Maybe one library is missing…

What can I do?


Here the code I’m using :

#include <pins_arduino.h>
#include <ArduinoLowPower.h>

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial1.println(“Setup done”);


// the loop routine runs over and over again forever:
void loop() {

// read the input on analog pin 0:
int sensorValue = analogRead(ADC_BATTERY);
float voltage = sensorValue * (3.3 / 1023.0/1.2*(1.2+0.33));

Serial1.print("Battery Voltage Raw: “);
Serial1.print(” - ");
Serial1.print(“Battery Voltage(V): “);
Serial1.println(” V”);

It looks like you are using the default analog reference, which would be the battery voltage, so it is comparing to itself, always returning 4095 (full scale).

You should set the analog reference to internal 1V0 or 1V65 to get the battery ADC reading. The battery voltage is read through a resistor divider of 33K and 68K, so multiply your measured voltage by 101/33.

So your formula would be (assuming 12 bit resolution and 1V65 reference):

batt_v = sensorValue * (1.65/4096) * (101/33)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.