Hi
Can someone check my findings please,
I have recently being trying to add smoothing code to a sketch I am writing for a sensor circuit. After several issues I decided to go back to basics and test each part of my code separately.
I started by building a basic voltage divider with a 10k resistor referenced to the ground rail from the "A0" pin and a 100 ohm resistor from the +5v pin to the "A0" pin.
I then wrote the following basic sketch to get an anologRead value from the voltage divider.
int inputpin = A0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
analogRead (inputpin);
Serial.println (inputpin);
delay (2000);
}
This returned a value of 14 see the screen dump below.
\Arduino\libraries\14.jpg)
Next I tried the Example smoothing code with the same voltage divider, which returned a totally different result of 1013 see below.
\Arduino\libraries\1013.jpg)
I decided to alter the code and added in Serial.println's for each of the indexes and the average. The maths side of the code works fine taking the individual readings of 1013 and placing them into the indexs' 0-9, totalling them then dividing by ten to get the average.
What is still a mystery is why this sketch returns an anolgread value on "A0" of 1013 and a different sketch returns a value of 14.
Any ideas?