I want to display the power source and voltage.
My code below reads the A2 pin.
With the USB powering things, the "voltage" reads 3.62.
When the battery is powering it, the "voltage" reads 3.05.
The breakout board text stated anything over 4.7 V was USB.
Does that mean my USB is outputting less voltage or an I determining the voltage incorrectly?
Code: Select all
int sensorValue = analogRead(A2);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);