Gravity: Analog Water Pressure Sensor Unstable value
I'm using Gravity: Analog Water Pressure Sensor with Xiao ESP32C6. I've connected ADS1115 16-Bit ADC in between pressure sensor and esp32.
However, I'm not able to get stable value.
First I run in an empty tank, and it shows the voltage of 0.485.
Now I've filled the tank with 80% water but still it shows 0.496 to 0.498 and sometimes it drops to 0.474.
I've put the drain the pipe at the bottom of the tank and put the sensor there.
Tank height is around 23 inch.
My code is in the below as well in attachment.
#define BLYNK_TEMPLATE_ID "id"
#define BLYNK_TEMPLATE_NAME "Water Level"
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include "Ultrasonic.h"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "key";
char ssid[] = "Creed Family";
char pass[] = "password";
// Define pins and constants
//#define TANK_HEIGHT_CM 58.42 // Tank height in cm (23 inches)
const float OffSet = 0.485; // Calibration offset for the pressure sensor
// Pressure sensor calibration (in KPa)
float emptyTankPressure = 0.4; // Pressure at empty tank in KPa
float fullTankPressure = 5.72; // Pressure at full tank in KPa (example value)
// Ultrasonic calibration (in cm)
float emptyTankDistance = 58.42;
float fullTankDistance = 10.0;
// Initialize components
Adafruit_ADS1115 ads;
Ultrasonic ultrasonic(0); // Ultrasonic sensor connected to pin 0
void setup() {
Serial.begin(115200);
Wire.begin();
ads.begin(); // Initialize ADS1115
Blynk.begin(auth, ssid, pass);
Serial.println("/** Water pressure and level monitoring system **/");
// Initial delay to let sensors stabilize
delay(1000);
}
void loop() {
Blynk.run();
int16_t pressureValue = ads.readADC_SingleEnded(0);
float pressureVoltage = pressureValue * 0.1875 / 1000; // Convert to voltage (assumes FSR ±6.144V)
float pressureKPa = (pressureVoltage - OffSet) * 250; // Calculate water pressure in KPa
// Calculate water level percentage based on pressure data
float pressureLevelPercentage = ((pressureKPa - emptyTankPressure) / (fullTankPressure - emptyTankPressure)) * 100.0;
if (pressureLevelPercentage < 0) pressureLevelPercentage = 0;
if (pressureLevelPercentage > 100) pressureLevelPercentage = 100;
// Read ultrasonic distance
long distanceCm = ultrasonic.MeasureInCentimeters();
delay(1000);
//float waterLevel = TANK_HEIGHT_CM - distanceCm; // Calculate water level in cm
// Calculate water level percentage from ultrasonic sensor
float ultrasonicPercentage = ((emptyTankDistance - distanceCm) / (emptyTankDistance - fullTankDistance)) * 100.0;
if (ultrasonicPercentage < emptyTankDistance) ultrasonicPercentage = 0;
if (ultrasonicPercentage >= fullTankDistance) ultrasonicPercentage = 100;
// Send values to Blynk
Blynk.virtualWrite(V0, pressureKPa);
Blynk.virtualWrite(V1, pressureLevelPercentage);
Blynk.virtualWrite(V2, distanceCm);
Blynk.virtualWrite(V3, ultrasonicPercentage);
// Print sensor readings
Serial.print("Pressure Sensor Voltage: ");
Serial.print(pressureVoltage, 3);
Serial.println(" V");
Serial.print("Pressure: ");
Serial.print(pressureKPa, 1);
Serial.println(" KPa");
Serial.print("Water Level (Pressure Sensor): ");
Serial.print(pressureLevelPercentage);
Serial.println(" %");
//Serial.print("Water Level (Ultrasonic): ");
//Serial.print(waterLevel);
//Serial.println(" cm");
Serial.print("Water Level (distanceCm): ");
Serial.print(distanceCm);
Serial.println(" cm");
Serial.print("Water Level (Ultrasonic Sensor): ");
Serial.print(ultrasonicPercentage);
Serial.println(" %");
Serial.println();
delay(5000); // Adjust delay as needed
}
The SEN0237 operates at 5V, so you need to supply 5V to the ADS1115 as well to get an accurate voltage value. This phenomenon is very much like powering the sensor with 3.3V.
Would you able to upload a wiring diagram so we can check if anything is missing?
I've removed the ADS1115 and also put the VCC into 3v3. I"m using Seeed Studio Xiao ESP32C6 Board.