Analog to Ground Values Jumpy

Hello!
I was doing some research for a project I'm working on with a TMP36 temp sensor. My readings were a bit jumpy. I happened to come across a post on the forum that suggested I simply connect my Analog Pin directly to Ground. I did this and displayed the analog reading every 50ms to my serial monitor. Those values seem a little jumpy to me as well. Would anyone have some ideas as to why this might be occurring or how to help improve the accuracy, or is this normal for analog readings? I presume if it is the latter, one option would be to average a certain number of values?

I've included a subset of my serial monitor data here for your reference. Thanks for any help you can give me!

0
0
8
1
2
2
0
0
0
2
0
0
0
4
0
2

No code presented, so I'll guess. Try reading the analog input twice in a row, keeping only the second value. See if that stabilizes.

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

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


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

?????? Schematics please.

Thank you, I will try reading the 2nd value and see if that makes a difference. In the meantime, I've attached my sketch and a picture. Note, this is an Arduino Nano Every. I've connected Pin A7 directly to Ground. The output was as shown in the first message. Thanks for the help!

#define tempSensor A7

void setup()
{Serial.begin(9600);}

void loop() 
{
  int reading = analogRead(tempSensor);
  Serial.println(reading);
  delay(50);
}

Add a second line, but without the int declaration.

Ok, I set this up to read the 2nd value as you suggested, but I'm seeing the same behavior.

Note, I also tried connecting the Analog Pin directly to the 5V supply rail from the Arduino Nano Every. Similar behavior occurred, where the values fluctuate between 1016-1023 instead of 1023 consistently.

Code should be simple, so please post it so we can be sure we're talking about the same thing.

Sure thing, here is the code.
Another note, the same behavior occurs when I use analog pin A6.

#define tempSensor A7

void setup()
{Serial.begin(9600);}

void loop() 
{
  int reading = analogRead(tempSensor);
  reading = analogRead(tempSensor);
  Serial.println(reading);
  delay(50);
}

Okay. So at this point, I'd say you're suffering from noise, likely from the voltage reference being used. Remember, the ADC may be looking at a 'grounded' input, but the ADC is judging that based on whatever it's using as a reference voltage.
I'd also simply change wires, because a sketchy or intermittent wire would give that sort of behavior as well. Try just wiggling it, to see if the value changes.

I'd also try it on A0, and maybe another input, just to see if there's any variability there.

I think that's "unusual" and maybe there is something wrong with the Arduino... Or maybe your ground connection is a little flakey...

Some noise (instability) is common but worst-case, I'd expect maybe some "1" readings with the input grounded. Noise in the power supply can translate to noise in the reading (with the default 5V ADC reference) and USB power from a computer is often noisy. But again, I wouldn't expect that to happen with the input solid-grounded.

With actual temperature measurements you can also expect some noise and with ANY analog-to-digital conversion you can be on the "hairy edge" between two digital values and the reading can jump up & down by one count.

See the Smoothing Example.

I think the Arduino Nano Every has a switch mode DC/DC converter in it. This could be faulty and adding noise into the system.

Connecting a pin directly to ground should not results in jumps especially in a value of 8.

I would see if adding a capacitor from the 3V3 to ground helps stop this.

Every - I think we've seen threads about this issue before. Searched the forum for "Every Analog Noise", found a thread in March 22 that relates.

Great minds think alike :slight_smile:
The switching supply of the Every is likely the source of the noise.
Leo..

Thanks for the responses everyone!
I took some time to set up my code so it uses a moving average. This seems to have helped smooth out the signal overall. But I'd certainly be interested in knowing how the capacitor changes things, so I may remove the moving average and see what the capacitor does. For now, the moving average solves my problems, so thanks again for the help!

Here is my code for the temp sensor just for reference.

#define tempSensor A7
#define totalValues 50
int count = 0;
int movingValues[totalValues];
float spectroTemp = 0;
float reading = 0;

void setup()
{Serial.begin(9600);}

void loop() 
{
  movingValues[count] = analogRead(tempSensor);
  int sum = 0;
  for (int i=0;i<totalValues;i++){
    sum += movingValues[i];
  }
  reading = sum/totalValues;
  
  float voltage = reading * 5.0;
  voltage /= 1024.000;
  spectroTemp = ((voltage - 0.5) * 100) * (9.0 / 5.0) + 32.0; //In Fahrenheit
 
  Serial.println(spectroTemp); 
  count += 1;
  if(count >= totalValues){count = 0;}
}

Just a suggestion. Instead of 10 storage values, use your average value.
In setup, assign the average a first read value.
In loop, multiply the average by 9/10, then add 1/10 of the new value. Same difference. Transient values are suppressed by a factor of 10. If you want to change to 20, change one constant. That way, you're also only reading the analog input once per loop, so you have time for other things.
In the world of Arduino, I find myself running out of memory before I run out of anything else.

1 Like

The TMP36 is last century.
Move to the digital age, and use a digital temp sensor.
A DS18B20 is factory calibrated and has a several times higher resolution.
A digital sensor also eliminates your A/D problems.
Leo..

3 Likes

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