Voltmeter with Esp32

Author: Olteanu Eduard-Florin

Introduction

The main focus of this project is to be able to accurately measure low-voltage batteries in order to determine whether or not they are still functional.

Additionally, the user can save the values in a database in order to be easier to remember or review the values at a later time and not measure them again.

Hardware Description

Components:

  • ESP32 Microcontroller
  • ADS1115 ADC
  • 16×2 I2C LCD
  • Push Button
  • Multimeter cables
  • Wires
  • Breadboard

Electronic schema

Software Description

The libraries used are:

#include <Adafruit_ADS1X15.h>
#include <WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#include <Firebase_ESP_Client.h>

Communication between the ESP 32 and both the ADS1115 and the LCD screen is done through the I2C protocol. The button is connected to the GPIO4 pin and is used as a trigger to store in database the value read by the AIN0 pin from the ADS1115.

WiFi connection:

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
  Serial.print(".");
  delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Firebase connection:

/* Assign the api key (required) */
config.api_key = API_KEY;

/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;

/* Sign up */
if (Firebase.signUp(&config, &auth, "", "")){
  Serial.println("ok");
  signupOK = true;
}
else{
  Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
 
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
 
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);

Voltage measurement:

adc0 = ads.readADC_SingleEnded(0);
delay(10);
volts0 = ads.computeVolts(adc0);
 
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ADC0:");
lcd.print(adc0);
lcd.setCursor(0, 1);
lcd.print(volts0);
lcd.print("V");

Storing the value in the database:

// read the state of the switch/button:
currentState = digitalRead(BUTTON_PIN);
if ((lastState == LOW && currentState == HIGH) && Firebase.ready() && signupOK) {
  sendDataPrevMillis = millis();
  Serial.print ("time: ");
  Serial.println (sendDataPrevMillis);
    
  entry_path = path + "/" + String(sendDataPrevMillis);
    
  // Write an Float number on the database path test/float
  if (Firebase.RTDB.setFloat(&fbdo, entry_path , volts0)) {
    Serial.println("PASSED");
    Serial.println("PATH: " + fbdo.dataPath());
    Serial.println("TYPE: " + fbdo.dataType());
  }
  else {
    Serial.println("FAILED");
    Serial.println("REASON: " + fbdo.errorReason());
  }
}
lastState = currentState;

We use millis to store the value in order not to overwrite already known values.

Problems and Improvements

  • One problem that I could not fix is the noise the ADS1115 is getting when reading, even if there is nothing measured the pin reads 0.9V, but that doesn't impact measurements.
  • An improvement could be to add some other form of identification for the batteries when stored in the database.
  • Another improvement could be to have a phone application that manages the database for the batteries and also that communicates with the ESP32.

Results

The main use-case of this project is to measure the voltage of batteries.

We can see that the value is pretty accurate, only 0.01 error delta.

Also, if the button is pressed the value is stored in the database.

Bibliography

iothings/proiecte/2022sric/voltmeter.txt · Last modified: 2023/06/01 23:40 by eduard.olteanu1505
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0