I just want to make my own code work and understand that before i try other codes.
When i start the serial monitor the voltage shows correct smooth and fine the first seconds. But after some seconds, its begin to fluctuate by approx 0.1V.
I hvae mounted an 10uF electrolytic capacitor between ground and analog input, but that does not smooth out the readings. But when i adjust the input voltage i can se the values change more slowly. But it does not fix the voltage readings.
But why does the voltage sows nice and smooth for some seconds when i start the serial monitor and resets the board?
This is my last code:
int voltPin = A0;
void setup() {
Serial.begin(9600);
pinMode(voltPin, INPUT);
}
void loop() {
int numReads = 5;
int senseSum = 0;
for (int k = 0; k < numReads; k++) {
senseSum += analogRead(voltPin);
delay(1);
}
int senseAve = senseSum / numReads;
float voltage = senseAve * (17.1 / 1023.0);
Serial.print("Battery Voltage: ");
Serial.print(voltage);
Serial.println("V");
delay(100);
}