1

enter image description here

I want to read my lithium battery voltage.

  1. I WANT TO CREATE A FUNCTION TO READ MY 3.7~4.2V,1200mAH BATTERY VOLTAGE THROUGH A MICROCONTROLLER (ARDUINO OR ATTINY44).

  2. 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;
    
  3. 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.

1 Answers1

1

I want the whole system to run on lithium battery

If you power the Arduino from the battery, then you can indirectly read the battery voltage by reading the internal voltage reference. This requires no pins - just connect the battery across the Arduino ground and the 5V pin. Here is more explanation on why this works...

https://wp.josh.com/2014/11/06/battery-fuel-guage-with-zero-parts-and-zero-pins-on-avr/

Note: Do not connect more than 5 volts or less than 0 volts to the 5V Arduino pin. This pin is connected directly to the AVR without any overvoltage or reverse polarity protection. Your 3.7~4.2V battery should be fine.

bigjosh
  • 1,593
  • 10
  • 13