Hi. I am hoping this is the right place to post this... if not please direct me.
I have a whole other setup and code set for this project, but I have put all that on the backburner and have stripped everything down just to try to pin down this issue.
Currently all I am trying to do is take readings from a 2.5V reference, averaging 25 measurements over a span of 1.25s . The averaged analog output is roughly 254, or about 1.24V, while my multimeter reads 2.50V . The same thing happens when try to read my AD22100 temperature sensors, they read at about 1.3V while my multimeter puts them at ~1.92V, which is exactly where they should be at this temp.
I've tried looking at the raw data without averaging and the error is not in the averaging... well, at least not only.
Right now I am running everything off the board 5V supply, but before I was using a regulated 5V 1A supply for the sensors and the reference.
I am new to arduino so I figure it might be something obvious I am missing, or maybe I got a lemon.
Any ideas? Code supplied below for reference.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int arraysize = 25;
char sensorPin;
void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Vref:");
}
//Function - Read and average-------------------
int s_readAvg(int sensorPin){
int i;
int s_read = 0;
int s_Avg = 0;
for (i = 0; i < arraysize; i++){
s_read = s_read + analogRead(sensorPin); // sensor on analog pin #sensorPin
delay(50);
}
s_Avg = s_read / arraysize; // average
return s_Avg;
}
void loop(){
float sensorVoltage;
//Read voltage reference and average over 25 readings
sensorPin = 'A5';
sensorVoltage = s_readAvg(sensorPin);
delay(10);
//Correct for 2.5V being read as ~1.3
// sensorVoltage = sensorVoltage*1.9768;
Serial.print("\t ref: ");
Serial.println(sensorVoltage);
delay(100);
//-------------LCD Output-----------------------------
lcd.setCursor(0,1);
lcd.print(sensorVoltage,0);
}