analogRead fluctuating values with constant input

Using a nano every:

I am reading the voltage from a voltage divider network. Measuring the voltage at the analog input pin (A1) with a DMM, the voltage is a constant 3.49 volts. Voltage on the 5 volt pin is 4.92 volts and is constant also. However, when I print out an analog read of that pin, the value fluctuates wildly between 723 to 728. The voltages are measured directly at the pins of the Arduino and are rock-solid.

I swapped out the nano every, and still get the same results.

Why am I getting this fluctuation?

Code:

const byte thermHot = A1;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  pinMode(thermHot, INPUT);
}

void loop() {
  Serial.println(analogRead(thermHot));
  delay(200);
}

Your definition of "wildly" and mine vary, wildly.

What makes you think this is an installation issue?

This is normal. The multimeter has a filter to reduce the noise and reduce the 50/60Hz of the mains.

The default analog reference is the 5V of the Arduino board.
Use a internal voltage reference that is not influenced by fluctuations of the 5V.
I think they forgot the Nano Every here: https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/.

Then take the average of a number of samples. Just 5 samples is already an improvement, but perhaps you need 100.

Voltage divider resistor values >10K? ... add a 0.1μF cap from A1 to GND.

Ah yes, Electronics 101. I put a scope on the supply, and yes, quite noisy. The first thing I need to do is fix that. The supply rails should be solid.

"wildly" - a different reading almost every 200 ms pass.

I don't, I think it is a troubleshooting issue. The name of the thread is "Installation & Troubleshooting".

...and then it goes on "For problems with the Arduino IDE (integrated development environment). NOT for problems with your project."

...within 0.6% of FSD.

Wild.

"& Guessing" ... I guess R1/R2 value(s) are greater than 10K, which is beyond the maximum recommended ADC input impedance for the ATmega4809. In this case, adding a capacitor would help.

Anyways, I wouldn't expect miracles with the Nano Every's ADC, it lacks hardware noise filtering. The filtering on the ATmega4809 Curiosity Nano is quite good. It looks like this ...

image

He is right you know it isn't, you posted in the wrong place, I have moved it here.

Don't post there with your projects. If you can get the led blink program running your post belongs some place else.

1 Like

Thanks for moving it. Sorry for the trouble.

You hit the nail on the head regarding the input impedance, as I observed that if I used a 10k pot on the input, there was virtually NO fluctuation on analogRead().

I am reading a 100k NTC thermistor, so I am locked in on the impedance of that network. I assume they use hi Z thermistors to reduce self-heating. I could use op-amp buffers to drop the impedance seen by the nano. As long as I stay away from the rails it should work fine.

Nonetheless it was good to look at it with a scope and clean up the noise. Some tidying up of wires (twisting a bundle together) and a few decoupling capacitors and things are already looking a lot better (+- 1 count fluctuation) even without buffering. I am extending an existing circuit board so the nano resides about 8 inches away, connected via a bundle of wires (which are now twisted together.) Just getting off the breadboard on to a circuit board will probably help as well.

The Every might not have other Aref voltages, which makes it in theory unsuitable for voltage measurements. And most of us have zero experience with these relative new boards.

But OP might be measuring a thermistor ratio , not a voltage, judging by his sketch (thermHot).

OP can try powering the Every externally (V-in), with a 9volt battery, and see if that solves the problem. Not much hope there, because the Every has a switching (buck) power supply for V-in, which can add more noise.
Leo..

@KevinJones, then you are not reading a voltage, but a "ratiometric" signal as Wawa wrote. The default 5V is perfect for that. I don't understand the documentation of analogReference(), perhaps you have to set "VDD" for the analog reference.

Getting a few samples and calculating the average is a common practice to read a temperature with a NTC, even with the hardware filter.
You can take the value of a number of analogRead(). There is no need to put a delay() between the reads. It will reduce the high frequency electronic noise.

@Wawa, I did not look very good. The "Arduino megaAVR Boards" is also for the Nano Every. But then it says that DEFAULT is the built-in 0.55V reference :face_with_spiral_eyes: which is indeed defined in Arduino.h and not changed in its variant section.

I have a Nano Every, but I guess that I never used its analog input.

Just my unproven assumption, but I assume the nano will use V+ ("5V" pin) as a reference if Aref is not present.

Calculations of expected analogRead() based on the voltage at the 5V pin as a reference seem to indicate it is indeed using the 5V rail as the reference.

So what are you measuring.
A thermister ratio (voltage divider) or a voltage (from a power supply).
Both need different A/D settings.
Leo..

It seems it is somewhat a matter of semantics and how you choose to do the computation. It is indeed a voltage divider, and the change in resistance of the thermistor over temperature results in a change in voltage across the thermistor (in my application.) As long as you know the values that change and what information they are reflecting (eg, NTC curve) and what computation you need to do to get the end result you're looking for for your algorithm. It is somewhat analogous to measuring "current" by measuring the voltage drop across a resistor of known value. Am I wrong?

But it clearly says "Installation and troubleshooting" and is the first listed forum.

It may add other comments in the fine print, but it is clearly intended to be the first choice. :roll_eyes: