I’m just getting started with Arduino UNO and a little confused…
When I do an analogRead() as follows:
const int voltagePin = 1; //Analog pin A1
void setup() {
Serial.begin(9600);
}
void loop() {
int voltage = analogRead(voltagePin);
float mult = 5/1023;
Serial.print((float)voltage*mult,3); //this gives 0.000 (BAD reading)
Serial.println((float)voltage*0.0048875); //this gives a GOOD reading
}
Why aren’t the two Serial.print() values the same?
The other thing I’m having trouble with is how to get an accurate voltage reading without measuring the actual voltage on the 5V pin (on the board) and calculating the multiplier and typing it into my program. Is there some way this can be automated? When I use my computer’s USB port to power it I measure 5.35V on the board’s 5V pin. When I use an external power supply I get 5.0V on the board’s 5V pin.