Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2022sric:voltmeter [2023/06/01 21:52]
eduard.olteanu1505 [Electronic schema]
iothings:proiecte:2022sric:voltmeter [2023/06/01 23:40] (current)
eduard.olteanu1505
Line 1: Line 1:
-==== Voltmeter ====+==== Voltmeter ​with Esp32 ====
 Author: Olteanu Eduard-Florin Author: Olteanu Eduard-Florin
  
 ===== Introduction ===== ===== 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 ===== ===== Hardware Description =====
Line 21: Line 25:
  
 ===== Software Description ===== ===== Software Description =====
 +The libraries used are:
 +<​code>​
 +#include <​Adafruit_ADS1X15.h>​
 +#include <​WiFi.h>​
 +#include <​LiquidCrystal_I2C.h>​
 +#include <​Arduino.h>​
 +#include <​Firebase_ESP_Client.h>​
 +</​code>​
 +
 +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:
 +<​code>​
 +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();​
 +</​code>​
 +
 +Firebase connection:
 +<​code>​
 +/* 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);​
 +</​code>​
 +
 +Voltage measurement:​
 +<​code>​
 +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"​);​
 +</​code>​
 +
 +Storing the value in the database:
 +<​code>​
 +// 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;​
 +</​code>​
 +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.
 +
 +{{ :​iothings:​proiecte:​2022sric:​20230601_225009.jpg ?700 |}}
  
-===== Demo =====+{{ :​iothings:​proiecte:​2022sric:​20230601_225034.jpg?​700 |}} 
 +We can see that the value is pretty accurate, only 0.01 error delta.
  
-===== Conclusion =====+Also, if the button is pressed the value is stored in the database. 
 +{{ :​iothings:​proiecte:​2022sric:​database_batteries.png?​700 |}}
  
 ===== Bibliography===== ===== Bibliography=====
-  * [[https://​ocw.cs.pub.ro/​courses/​iothings/​laboratoare/​2022/​lab3]]+  * [[https://​ocw.cs.pub.ro/​courses/​iothings/​laboratoare/​2022/​lab4]] 
 +  * [[https://​how2electronics.com/​how-to-use-ads1115-16-bit-adc-module-with-esp32/​]] 
 +  * [[https://​github.com/​mobizt/​Firebase-ESP-Client]] 
 +  * [[https://​github.com/​adafruit/​Adafruit_ADS1X15]]
  
iothings/proiecte/2022sric/voltmeter.1685645570.txt.gz · Last modified: 2023/06/01 21:52 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