I have a load cell hooked up to a strain meter, which is then output in to the arduino. I have 8 pounds applied to the load cell and that equals .80 volts read into the analog output pin. Of course, when I read it on the serial monitor, it isn't a constant .80 volts as it fluctuates because of noise. I have tried to average the serial monitor to get a better read to as close to .80 volts as I can get. Here is part of the code that I'm working with right now:
[code]
int sensorValue = analogRead(sensorPin);
long sum = 0;
float voltage = sensorValue * (5.0 / 1023.0);
for(int i=0; i< 5; i++)
{
sum = sum + sensorValue;
float voltage = sum / 1023;
delay(300);
}
Serial.println(voltage, 3);
[/code]
I changed the delay 3 times (300ms 1sec and 1 min) and then took a sample size of about 200 from the serial monitor and posted it on an excel spreadsheet to take the average. The average was always around .80V which is what I want, but the max and min are not close to .80V. There really is not difference between the 3 time intervals I've done. The max - min of each sample of each time interval is about .40V. It seems like the serial monitor is just printing out the voltage it reads after the delay instead of taking the average. I figured that if I took the average, the number it prints should be roughly the same each time. After having it average for a minute, there would be times where it would print .835V and then .795V (rough estimate). Is my code not really taking the average? Thank you for taking the time to read this.