I am trying to get the Aref pin to work so I can scale down analog input references for better resolution. I cannot figure out what I am doing wrong here.
I am using the 3.3V supply from the Uno board through a voltage divider of 1.5M and 1K resistors. This provides around 2.19mV. I connect that to the Aref, and the GND below the Aref to the bottom of the divider. No matter what I do, I cannot read anything but 1023. I am understand the floating pin, but it doesn't go to 0 when grounded. I have tried just connecting it to the 3.3V supply directly (to AREF), and that works. I have tried INTERNAL and DEFAULT analog references, and they seem to work fine. It is only when I try and scale it down that it won't read. Also, I have tried multiple analog pins in case one was bad or something.
Divider:
Below is the code, however, I suspect there is something else going on as it work fine on a direct connection to board voltages...
Any help would be appreciated
float test;
float coeff[] = {0 , 1.978425E+2 , -2.001204E-7 , 1.036969E-11 , -2.549687E-16 ,
3.585153E-21 , -5.344285E-26 , 5.099890E-31}; //Type J coefficients
float temp;
float temp_comp;
long time_ref; //time to act as start time reference (milliseconds)
long time_current;
int analogpin = A1; //analog pin to use
int analoginput = 0; //integer value 0-1023 input from pin
void setup(){
Serial.begin(9600);
analogReference(EXTERNAL); //use AREF as voltage reference
Serial.println("Anolog input testing");
}
void loop(){
delay(2000);
time_current = millis(); //timestamp
// analoginput = 0;
analoginput = analogRead(analogpin); // reads analong input pin and stores to variable
test = 0;
temp = 0;
temp_comp = 0;
test = map(analoginput, 0 , 1023 , 0 , 2150); // maps 0-1023 to 0-2150 microvolts
test = test/1000; // converts microvolts to millivolts
temp = tc_calc(test);
temp_comp = temp + 21.222;
Serial.print(time_current);
Serial.print("\t");
Serial.print(analoginput);
Serial.print("\t");
Serial.print(test);
Serial.print("\t");
Serial.print(temp);
Serial.print("\t");
Serial.print(temp_comp);
Serial.println("");
}
// Thermocouple Calculations
float tc_calc(float tc_mv){
int i = 0;
while(i <=7) {
temp = temp + coeff[i]*pow(tc_mv,i);
i++;
}
return temp;
}
The voltage you applied to aref becomes the new reference... it's normal that you cannot read anything but 1023.
Take a look here : analogReference() - Arduino Reference
The voltage you applied to aref becomes the new reference... it's normal that you cannot read anything but 1023.
I am sorry, that doesn't make any sense. I am applying ~2.19mV at AREF, and grounding the analog input pin, I should get zero. When I apply 3.3V at AREF and ground the analog input pin, I get 0. Similarly, when I repeat this for 5V, I get 0. It is only when I apply the 2.2mV that I get 1023.
I forgot to mention in my first post, I tested all of this with a DVM, and I am infact getting the voltages as they should be at each pin and reference.
The voltage you applied to aref becomes the new reference... it's normal that you cannot read anything but 1023.
I am sorry, that doesn't make any sense. I am applying ~2.19mV at AREF, and grounding the analog input pin, I should get zero. When I apply 3.3V at AREF and ground the analog input pin, I get 0. Similarly, when I repeat this for 5V, I get 0. It is only when I apply the 2.2mV that I get 1023.
I forgot to mention in my first post, I tested all of this with a DVM, and I am infact getting the voltages as they should be at each pin and reference.
That is because you failed to study/read the datasheet about the electrical specification of the Aref pin and what's it's minimum voltage can be, approx +1.0 vdc.
I guess that is my mistake. I was relying on the Arduino reference guides and documentation. I guess maybe they should consider changes there documentation from: