void loop() {
val = analogRead(potPin);
Serial.println(val);
delay(1000);
}
These are the values I see when the pot is at maximum, I was hoping they would be consistent?
1014
1013
1013
1013
1013
1012
1013
1013
1013
1013
1013
1014
1013
1012
1014
1013
1013
1013
Side question, why with the pot at 0, are my values around 18 and not 0?
Those are pretty consistant readings. If you research the AVR data sheet you will find that they spec the overall accuracy as +/- 2 LSBs. The readings are also subject to any noise on the AVCC pin, used as the internal reference. The AVR analog inputs are very useful and handy to have, but one can't expect lab quality performance with such an inexpensive device.
One can add software 'filtering' to smooth out readings by oversampling and averaging the readings. The 'zero' error your seeing is most likely caused by the pot itself. To prove that just disconnect the wire going to the pot and wire a ground to the analog input and see what that measures.
Thanks Lefty.
When you say oversampling...
Read say 10 values into an array, then average them, then start again?
Or just ignore value changes unless >3 say?
When you say oversampling...
Read say 10 values into an array, then average them, then start again?
Yep, thats what I meant. Even adding four readings in a row to a single variable and then divide that variable by four should show a good smoothing function, no need for an array.