Hello!
I created a voltage divider (schematic below) and tied it with an Arduino first, and I was able to get an accurate reading. The code was as follows:
float batteryVoltage;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
float batteryVoltage = (sensorValue * (5 / 1023.00))/0.090909; //0.090909 is (R2/R1+R2)
Serial.print(batteryVoltage,1); Serial.println("V");
Serial.println(sensorValue);
delay(500);
}
Tried the same code with my Teensy 4.1, just switched out the Analog pin to analogRead(A13);
On the serial monitor I got a reading of ~220-230 as the sensorValue and a voltage of 11.7-12.1V with nothing connected other than a cable to a laptop for serial monitoring. When I attached the ground and and analog cable to the board, with 14V going through the divider it would read 425 as the analog value and 22.8V.
Not sure what I'm doing wrong. Worked with one, not the other.
I created a voltage divider (schematic below) and tied it with an Arduino first, and I was able to get an accurate reading. The code was as follows:
float batteryVoltage;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
float batteryVoltage = (sensorValue * (5 / 1023.00))/0.090909; //0.090909 is (R2/R1+R2)
Serial.print(batteryVoltage,1); Serial.println("V");
Serial.println(sensorValue);
delay(500);
}
Tried the same code with my Teensy 4.1, just switched out the Analog pin to analogRead(A13);
On the serial monitor I got a reading of ~220-230 as the sensorValue and a voltage of 11.7-12.1V with nothing connected other than a cable to a laptop for serial monitoring. When I attached the ground and and analog cable to the board, with 14V going through the divider it would read 425 as the analog value and 22.8V.
Not sure what I'm doing wrong. Worked with one, not the other.