Unstable analogue input

Here is a very simple situation. I have a resitor from 5v to ana in 0 and another resistor from ana 0 to 0v. 5v- 80k- input- 1k7 -0v
However the read is not stable at all, it ranges from 19 to 32. Does anyone know of a way of stabalizing this.
If I use higer value resistors it does get a bit better in the 500 range for the input, but this will not work for my intended project as I need a wide range or input.

unsigned long a0 = 0;

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

void loop() {
  a0 = analogRead(1);
  Serial.println(a0);
}

That's why there is a built-in 1.1V reference. It is much more stable than Vcc

I am using a battery to supply the voltage which is going through a voltage regulator, so the 5v line should be pretty stable.
I am using a nano and cant see a 1v1 pin anywhere, there is a 3v3 though.

Sounds like you mean:
"I have an 80k resistor from the +5V pin to Analog Input 0 (A0) and a 1.7k resistor from Analog Input 0 (A0) to Ground."

Then why are you using "analogRead(1)" to read from A1 and not A0?!?

Yes you are write, just my typo, I am reading ana1 and I have connected ana1, I have also tried ana0, but its the same.

You are seeing about 60mV of noise. You might try adding a capacitor fro AIN0 to ground in an attempt to filter it out. The software approach is to make multiple measurements and average them.

I have now connected to the 3v3 line intead of the 5v line, and its worse, range from 15 to 26.

This simple average helps, but its not a great solution and still gives me a range from 12 to 18

void loop() {
  a0 = analogRead(1);
   delay(20);
   a1 = analogRead(1);
  delay(20);
   a2 = analogRead(1);
  delay(20);
   a3 = analogRead(1);
  delay(20);
   a4 = analogRead(1);
  delay(20);
   
  Serial.println((a0+a1+a2+a3+a4)/5);
//  Serial.println(a0);
}

what value do you sugest, 0.1mf perhaps.

A 0.1mf cap between A1 and ground gave me the result of 7 - 24 so worse still.

There is no 1.1V pin. @blh64 is referring to the 1V1 internal analog reference.

What battery and how is it connected.

What is it that you want to do with that voltage divider?

0.1uF analog input to ground should help if it is high frequency noise.
1mF = 1000 uF, did you mean uF?

1 Like

Your divider has a reduction ratio of 48:1, to get an ADC reading in the 500 range, would take over 100 volts across the divider. What voltage are you trying to read (AC or DC)?

You are obviously getting noise from somewhere. Might not be much that you can do if you can't track the source down (oscilloscope?). You need a solid ground, a solid analog reference (look up the analogReference function, and the 1.1V reference is called INTERNAL. It will be better than the 5V power as a reference. And a solid signal.

2 Likes

Hi @Uknod
Your code is trying to analogRead(1)

Try this where the designated pin is A0.
You are using pin A0 on your Nano?

unsigned long RawValue0 = 0;
int analogPin0 = A0;

void setup()
{
  Serial.begin(9600);
  Serial.println("Code Begins");
}

void loop()
{
  RawValue0 = analogRead(analogPin0);
  Serial.println(RawValue0);
  delay (100);
}

See what you get in the monitor.

I tried your code and it is not reading A0, I suspect it is the Tx comms pin, which is part of the programming and monitor paired with Pin0.

Have you got a 10K potentiometer?
Do you have a DMM?

Tom.... :grinning: :+1: :coffee: :australia:

1 Like

I tried your code and it is not reading A0, I suspect it is the Tx comms pin, which is part of the programming and monitor paired with Pin0.

Sorry for my confusing start. Yes I used variable a0 but connected to pin a(1), sorry for the confusion.

Have you got a 10K potentiometer?
Do you have a DMM?

Yes I have both

Your divider has a reduction ratio of 48:1, to get an ADC reading in the 500 range, would take over 100 volts across the divider. What voltage are you trying to read (AC or DC)

No it wouldn't. Analogue inputs work from 0v to whatever vcc is, so maximum vcc would be a reading of 1023, in my case 5v would be 1023, you can't input more voltage than is the maximum.
What I meant was if I changed the resistors to a more equal value, then the readings would be 500 ish.

What I am trying to do is read the resetance to 0v, I am not reading voltage at all.

unsigned long RawValue0 = 0;
int analogPin0 = A0;

void setup()
{
Serial.begin(9600);
Serial.println("Code Begins");
}

void loop()
{
RawValue0 = analogRead(analogPin0);
Serial.println(RawValue0);
delay (100);
}

I am not sure this code is any different to my original code.

OK, so I have added code
analogReference(INTERNAL);
to the setup. When run this now gives me range 68 to 106, so believe it or not, even worse still.
Thanks for the suggestion though, it was a good one.

no I am using A(1) sorry for the confusion.