analogReference(INTERNAL) not seeming to "rescale" millivolt input

I am trying to use analogReference(INTERNAL); to reference small millivolt inputs. When I monitor the results in the serial monitor, they do not appear to be any different than when i don't include the analogReference statement.
My (possibly wrong) assumption is that without he statement included in the "set-up" that an analog input is a 5volt input is ADC converted to a 1024 result. Therefore, 1VDC input would result in a display of aprox. 204. A 500 mV input would result in a display of 100.

When inserting the "analogReference(INTERNAL) in to the "set up" I was expecting to see the 1024 now being referenced to aprox. 1.1 volt.
Therefore 1volt DC input would display slightly less than1024 and a 500 mV input would indicate aprox. slightly less than 512.

No matter what I include the displayed output always seems to be "scaled" 5volts/1024.

I am using two different UNO's.
One is an older original version one and has the ATMEGA328P-PU
The other is a Rev3 and has the ATMEGA328P U

I am using a 1.5 volt battery and a 5K ohm pot as a voltage source for my input.
(I will try and and attach a photo of my configuration.)
I have the negative of battery wired to one end of pot and to UNO ground.
I have the positive of battery wired to opposite end of pot.
The "wiper" of pot is wired to analog input A3.

I am going to attempt to attach my sketch and a drawing of my wiring to the UNO.

I haven't done a post in a long time so I apologize for any incorrect things that I have done.

I would greatly appreciate it if participants could explain my misconception and/or my errors that may be in my code.

I will attempt to attach code and drawing.

And I Thank you for your patience, understanding, and help.
Rick

[code]


#include <SD.h>

File myFile;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  pinMode(10, OUTPUT);

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }

  analogReference(INTERNAL);

}

void loop() {
  // put your main code here, to run repeatedly:

  float raw = analogRead (A3);
  delay (500);
  raw = analogRead (A3);

  float calc = raw * 5.0725;

  Serial.print (raw);
  Serial.print ("   ");
  Serial.println (calc, 3);

  myFile = SD.open("ricks.txt", FILE_WRITE);
  myFile.println (calc, 3);
  myFile.close();

  delay (5000);

}
[/code]

You can measure the internal reference voltage at the AREF pin.
Run your program and connect a voltmeter beween AREF an GND, it should read around 1.1V.
If not, something is very wrong.

Hello jim-p,

WOW,,,, and thanks for such a quick response!

I took your suggestion...
I am measuring the AREF pin to GND with a FLUKE 87V true rms multimeter.
Sorry to report that I'm reading 4.99 VDC.

I also have another FLUKE on A3 to GND and am inputting 500 mV.

Thanks Again

When testing the voltage reference, then remove everything else.
Just print the return value of analogRead() as a integer.

A "return" in setup() ? Please don't do that :dizzy_face:

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

void loop()
{
  int rawADC = analogRead(A3);
  Serial.println(rawADC);
  delay (1000);
}

That's hard to explain...

There is nothing connected to AREF (except a temporary DMM connection), right.

I wonder if your code isn't being loaded? Try loading the Blink Example, and if that works re-load your code.

@DVDdoug There is a "return" in setup().

Koepel,,,, Much thanks are in order.

I copied your code into a sketch. Amazing....With just that in sketch, everything works great.
500 mV input now indicates 470 in serial monitor. 1volt now indicates 941.
AREF now at 1.089 vdc.

Now I can work on printing it to an SD card which is my goal.

The reason the "return" is included in the "if" instruction....
This was copied, as needed as part of what was needed to be able to monitor a failed initiation of the SD card via the serial monitor. I just copied the code from the SD card website.

Do you suspect that this may be the cause of why the analogReference in my code is not working

Again,,,,,many thanks

Yes - you exited before setting the reference. The next thing that was called after your setup() return was loop()

EDIT: Obvious when pointed out. I completely missed the return because I don't expect to see one in setup().

Don't use "return" in the setup() function.

A "return" skips the rest of the setup() function and continues with the loop() function.
I found a number of example where a "return" is used in setup() if the SD card fails. I think that is not good.

Not if the SD card was detected.

Quick note,,,
Have several things going on HOWEVER,,,,
Would like to THANK all of you for your understanding and help.
I will be adding the SD code minus the return later today.
You all have been very helpful and I will keep you “posted”

Again many thanks
Rick

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