Hello I have been trying to figure out how to meter a 12 volt lead acid battery of mine with this
16 bit adc ads1115 seems to be very accurate less than 5 volts i can get a resolution to less than 1mv
if i can meter a 12 volt battery close to that it would be great within 10mv would be great .. i know that the internal ref is 6.144 for this ADC divide that by 32764 and you get .0001875 which is great for less than 5 volts does anyone know how to write the code for this
here is the code to read up to vcc with 5v i was using it to charge a 100f cap to 2.5 volts worked
with my 12 volt battery and a logic mosfet
#include <math.h>
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,20,4);
Adafruit_ADS1115 ads(0x48);
float Voltage2 = 0.0;
float Voltage = 0.0;
int outputPin= 0;
void setup(void)
{
lcd.backlight();
lcd.init(); // initialize the lcd
lcd.init();
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
ads.begin();
}
void loop(void)
{
float adc0; // we read from the ADC, we have a sixteen bit integer as a result
//float adc1;
adc0 = ads.readADC_SingleEnded(0);
Voltage = (adc0 * 0.1875)/1000;
// adc1 = ads.readADC_SingleEnded(1);
// Voltage2 = (adc1 * 0.1875)/1000;
//float T2=Thermister(adc1);
int T3= analogRead(A3);
lcd.setCursor(0,1);
lcd.print("Voltage: ");
lcd.print(Voltage,4);
lcd.setCursor(0,0);
//lcd.print("Batt_Temp ");
//lcd.print(Thermistor(T3));
if(Thermistor(T3)>=110.0){digitalWrite(8,LOW);digitalWrite(7,LOW);}
else{
if(Voltage <= 2.500){digitalWrite(8,HIGH);digitalWrite(7,LOW);}
else{digitalWrite(8,LOW);digitalWrite(7,HIGH);}}
delay(500);
}
//*********************************************Steinhart-Hart equation************************************************
double Thermistor(int RawADC) { //Function to perform the fancy math of the Steinhart-Hart equation
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celsius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Celsius to Fahrenheit - comment out this line if you need Celsius
return Temp;
}
//******************************************************************************************************************