This shows you the differences between two versions of the page.
iothings:proiecte:2022sric:voltmeter [2023/06/01 23:13] eduard.olteanu1505 |
iothings:proiecte:2022sric:voltmeter [2023/06/01 23:40] (current) eduard.olteanu1505 |
||
---|---|---|---|
Line 51: | Line 51: | ||
</code> | </code> | ||
- | <code> | ||
Firebase connection: | Firebase connection: | ||
+ | <code> | ||
/* Assign the api key (required) */ | /* Assign the api key (required) */ | ||
config.api_key = API_KEY; | config.api_key = API_KEY; | ||
Line 74: | Line 74: | ||
Firebase.reconnectWiFi(true); | Firebase.reconnectWiFi(true); | ||
</code> | </code> | ||
- | | + | |
- | ===== Demo ===== | + | Voltage measurement: |
- | The main usecase of this project is to measure the voltage of batteries. | + | <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 |}} | {{ :iothings:proiecte:2022sric:20230601_225009.jpg ?700 |}} | ||
Line 85: | Line 131: | ||
Also, if the button is pressed the value is stored in the database. | Also, if the button is pressed the value is stored in the database. | ||
{{ :iothings:proiecte:2022sric:database_batteries.png?700 |}} | {{ :iothings:proiecte:2022sric:database_batteries.png?700 |}} | ||
- | |||
- | ===== Conclusion ===== | ||
===== Bibliography===== | ===== Bibliography===== | ||
* [[https://ocw.cs.pub.ro/courses/iothings/laboratoare/2022/lab4]] | * [[https://ocw.cs.pub.ro/courses/iothings/laboratoare/2022/lab4]] | ||
* [[https://how2electronics.com/how-to-use-ads1115-16-bit-adc-module-with-esp32/]] | * [[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]] | ||