Analog analogRead value off by a large value

I'm trying to do some analogRead() of a voltage with MKR1010 but the value is off by quite a bit from what's expected.

I've pretty much setup the simple voltage divider like one shown here https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput with same resistance values on the resistors so that voltage divided by half. When I measure on the A1 pin, I get 770, or 770 * (5 / 1023) = 3.76 V, 1.2 V greater than the expected 2.5 V.

As a sanity check, I went and measured everything with a multi-meter (albeit a cheap one that may not be too reliable). The resistance values were both pretty much the same at 22 k Ohm so no offset due to mismatch. I went and measure from the head of the top resistor and tail of bottom resistor and measured 4.8 V across both resistors. A little off from 5V claimed on source, but not too bad. Measured at the halfway point and got 2.35V, right around what's expected.

Thinking it maybe Arduino power source interfering somehow, I instead got a power supply independent of Arduino's 5V source pin and provided the voltage across divider and same result, multimeter showed 2.5V but Arduino analogRead() showed around 3.6V. I changed port from A1 to A2, same result. Tried grounding the pin and actually got 0 reading or 0V on analogRead() ; shorting it with resistor below got me 1023 or 5V so it seems to be working on the fringes. I'm stuck and cannot figure out where this 1.2V offset is coming from. Is this expected on analogRead() where it's expected to be a bit off and I need to calibrate it? Are there other steps I need to take to make it work? Am I missing something?

Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.

TL;DR

provide a short version.

Please read: operating voltage is 3.3V

The microcontroller on the this board runs at 3.3V, which means that you must never apply more than 3.3V to its Digital and Analog pins. Care must be taken when connecting sensors and actuators to assure that this limit of 3.3V is never exceeded. Connecting higher voltage signals, like the 5V commonly used with the other Arduino boards, will damage the board.

What is the reference voltage for the ADC? Surely not 5V.
your 5/1023 (wrong anyway should be 1024) is for an arduino using a "default" reference of Vcc (ie 5V approx)

IF the ADC reference is 3.3V
AND the ADC is working at 10 bit resolution
then 770 * 3.3 / 1024 = 2.5V

This is it, thank you!

https://docs.arduino.cc/tutorials/mkr-wifi-1010/connecting-sensors
https://docs.arduino.cc/static/6fe490c1cd339b47f224b68cd1c27543/29114/mkr_tutorial_06_img_02.png
Upon looking closer on what's written in the tutorial above, it does say to use 3.3 V Vcc to power the analog read circuit. But the wiring diagram showed 5V (an errata?) as the source and that's what I was following.

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