Go Down

### Topic: MKRFOX1200 read battery voltage (Read 9695 times)previous topic - next topic

#### etimou

#15
##### May 27, 2020, 02:27 pm
hi! What  do you mean by correct values?
Are you getting values that are close to 3V? and not always 3.3V as I observed?

#### miot_es

#16
##### May 27, 2020, 03:25 pm
Hello.
I am really feeding with a power supply with which I can change the voltage if I give it 3V it gives me 3V if it goes down to 2.9V it gives me 2.9V, so I think it is giving the correct values.

Regards.

#### etimou

#17
##### May 27, 2020, 04:06 pmLast Edit: May 27, 2020, 04:07 pm by etimou
This is absolutely what it should do. I don't know what I am doing wrong. I tested with a second unit and I got the same problem. Always getting 3.3V when powered from the screw terminal. Is it possible that I have two faulty modules? Or that I did something that damaged them and cause this malfunction?

#### etimou

#18
##### May 27, 2020, 04:39 pmLast Edit: May 27, 2020, 04:39 pm by etimou
ok, working better with the 1.1V analog reference.
Now I can see some fluctuation but I am wondering how we shall calculate the theoretical multiplier.

Is it correct?

#### miot_es

#19
##### May 27, 2020, 07:08 pm

"float voltage = sensorValue * (3.25 / 1023.0);"

by

"float voltage = sensorValue * ( 3/ 1023.0);"

#### miot_es

#20
##### May 27, 2020, 07:23 pm
These days I plan to do more tests with some modules that I am waiting for.

I will tell you the results.

Regards.

#### etimou

#21
##### May 28, 2020, 10:31 am

"float voltage = sensorValue * (3.25 / 1023.0);"

by

"float voltage = sensorValue * ( 3/ 1023.0);"

The measurement should not depend on the nominal voltage since we want to measure this voltage.

I also did more testing and here my conclusions:
- it works using the 1.0V built-in analog reference
- As the reference is 1.0V and not 1.1V as in the AVR boards the theoretical calculation is:
voltage = sensorValue * (1.0/(2^10-1))*(68+33)/33
voltage = sensorValue * (3.061 / 1023.0)
voltage = sensorValue * 0.00299
- The ADC saturates at 3.061V so it will not be possible to measure voltage higher than this value.
- this is theoretical and off course the multiplier can be adjusted to compensate the component tolerance
- For some reason that I can't explain now, it does not work well with the 1.65V internal reference when no power is applied to the micro USB port.

Working code:

Code: [Select]
`analogReadResolution(10);//10bitsanalogReference(AR_INTERNAL1V0);//1.0V built-in referenceint sensorValue = analogRead(ADC_BATTERY);float voltage = sensorValue * 0.00299; // (1.0/(2^10-1))*(68+33)/33`

#### miot_es

#22
##### May 28, 2020, 11:24 am
Thank you very much etimou.
Regards.

Go Up