I have to measure a voltage. In this example I see this int Voltage = (rawRFlevel * 5.0 ) / 1024.0; // scale the ADC
where 1023 is used as the divider, but in other examples I see 1024 being used.
The reason for asking is that I get two diferent results using this code{code} int newPercent;
TFTscreen.setTextColor(TEXTCOLOR, BACKCOLOR);
TFTscreen.setTextSize(3);
rawRFlevel = analogRead(RFlevel);
TFTscreen.setCursor(0, 0);
int Voltage = (rawRFlevel * 5.0 ) / 1024.0; // scale the ADC
TFTscreen.print(Voltage, 3);
TFTscreen.setCursor((screenWidth / 2), screenHeight / 2);
newPercent = int((rawRFlevel / 1024.0) * 100.0); // Get a percentage for the reading[/code]
To test this I connected a potentiometer to AN0 so I can slide between 0V and +5V.
So with the slider at the 0V position, Voltage=0 and newPercent shows also 0.
If I move the slider to the +5V position I get a reading 10 for Volate and aproxx. 2219 for the newPercentage value.
Moving the slider halfway Voltage shows 20 and newPercent shows 1210.
As this makes no sense to me, so what maybe wrong??
Regards
Harry H.
sketch_oct17b.ino (3.37 KB)