After several tries, i was successful with reading stable battery voltage using internal voltage reference of 1.1v, now the issue i face is that i cannot read stable sensor voltage, could you please let me know how can i read my sensor voltage? or do i need additional voltage divider (my sensor goes directly to A0 and GND pin).
1 Answer
To measure the voltage at A0 with an internal reference of 1.1v, the formula is float voltage = 1.1 * analogRed(A0) / 1023;
. Your code can be simplified as
float Vref = 1.1;
void setup(){
Serial.begin(9600);
}
void loop() {
analogReference (INTERNAL);
float voltage = Vref * analogRead(A0) / 1023;
Serial.print (“voltage at A0:”);
Serial.println(voltage);
Serial.print (“Solar panel voltage:”);
Serial.println(voltage * 5.7);
delay(1000);
}
sensorValue = analogRead(A0)
is a value ranging from 0 to 1023, to convert it to a voltage, the formula isvoltage = (sensorValue/Vref) * 1023
, where Vref is the reference Voltage you are using, in this case, it is 1.1v. Furthermore, you can't get a correctsensorValue
if your input at A0 is HIGHER than the Vref, you will get the wrong value!