I want to read my lithium battery voltage.
I WANT TO CREATE A FUNCTION TO READ MY 3.7~4.2V,1200mAH BATTERY VOLTAGE THROUGH A MICROCONTROLLER (ARDUINO OR ATTINY44).
THEN I WANT TO CALL THE CREATED BATTERY FUNCTION IN THE FORMULA TO READ PRECISE SENSOR VALUE
int voltage = ((CALLING BATTERY FUNCTION) * (READ SENSOR VALUE)) / 1023;
I AM USING INTERNAL REFERENCE VOLTAGE 1.1V. NOTE: I want the whole system to run on lithium battery ( I am just creating a prototype on Arduino, if it works, ill be editing the code for my attiny44 using 8mhz external crystal).
void setup(){ Serial.begin (115200); } void loop() { //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference ADMUX |= B11000000; //We read A1 (MUX0) ADMUX |= B00000001; // Start AD conversion ADCSRA |= B11000000; // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); float val = ADCL | (ADCH << 8); val = val * 5.7; //Multiply by the inverse of the divider Serial.println(val); }
This code is working but it is reading from analog Pin. Is there any possibility to do it without using AnalogPin because I dont have any spare pin on my attiny.