I have teensy 4.1 and i am connecting battery from outside as 12 V and connecting 3 resistors and getting the R1's volt but its not correct.
I draw the image and sharing with you.
So normally i will connect the battery to power teensy and i will just calculate the voltage of the battery from the teensy side.
But i have to test if it reads correctly. So i power teensy from the usb without any battery or anything. Then i read it. It gives me values 0.008...etc. It is not so weird i was thinking like okay then no voltage.
But then i connect the battery (usb is also plugged). Then i read the value 0.25..etc. This is weird for me. Why does it happen ?
I looked at the calculation from this website. It should be 0.0060 V.
Here is my code for voltage read, I dont think i am wrong here but i am missing something:
I draw the image and sharing with you.
So normally i will connect the battery to power teensy and i will just calculate the voltage of the battery from the teensy side.
But i have to test if it reads correctly. So i power teensy from the usb without any battery or anything. Then i read it. It gives me values 0.008...etc. It is not so weird i was thinking like okay then no voltage.
But then i connect the battery (usb is also plugged). Then i read the value 0.25..etc. This is weird for me. Why does it happen ?
I looked at the calculation from this website. It should be 0.0060 V.
Here is my code for voltage read, I dont think i am wrong here but i am missing something:
C:
void send_voltage_data(){
int value;
float volt;
value = analogRead( VOLTAGE_PIN );
volt = value * 5.0 / 1023.0;
DynamicJsonDocument voltage_json(1024);
voltage_json["CODE"] = "VOLTAGE_DATA";
voltage_json["voltage"] = volt ;
voltage_json["value"] = value ;
serializeJson(voltage_json, Serial);
Serial.println();
delay(1000);
}