I am using a Teensy 3.2, and have connected a voltage divider consisting of 2 resistors of 100 kOhm each. See image. A voltage of 3.3 V is applied.
Board is connected to laptop via USB.
I measured the analog reference voltage pin (AREF) on the back of the board, which is 3.26 V. I am dividing the analogRead value by 1024 due to 10 bit resolution, and multiplying by 2 for the voltage divider.
The output value I am expecting is 3.26 V, instead I get values that are quite far off (see below). I also tried the same circuit on an Arduino Nano, taking into account 5 V reference voltage rather than 3.3 V, and that did work fine.
Output values.
See code below.
Board is connected to laptop via USB.
I measured the analog reference voltage pin (AREF) on the back of the board, which is 3.26 V. I am dividing the analogRead value by 1024 due to 10 bit resolution, and multiplying by 2 for the voltage divider.
The output value I am expecting is 3.26 V, instead I get values that are quite far off (see below). I also tried the same circuit on an Arduino Nano, taking into account 5 V reference voltage rather than 3.3 V, and that did work fine.
Output values.
Code:
2.95
2.84
3.01
2.91
3.06
2.77
2.79
2.82
2.76
2.87
2.78
2.82
2.95
2.75
2.72
2.94
2.94
3.02
See code below.
Code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
// wait for Arduino Serial Monitor to be ready
}
}
void loop() {
// put your main code here, to run repeatedly:
float bat_v = ((float) analogRead(A0))*(3.27/1024.0)*2.0;
// float bat_v = analogRead(A0);
Serial.println(bat_v);
}