ESP32-S3 Based Water Level and Temperature Monitoring System with WiFi Connectivity
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor the water level and temperature in a tank using an ESP32-S3 microcontroller. It features a JSN-SR04T ultrasonic sensor for water level measurement, a DS18B20 temperature sensor for water temperature monitoring, and an LCD I2C display for real-time data visualization. The circuit is capable of sending the collected data to a web service via WiFi.
Component List
JSN-SR04T Sensor
- Description: Ultrasonic distance sensor.
- Pins: 5V, TRIG, ECHO, GND.
ESP32-S3
- Description: Microcontroller with WiFi capability.
- Pins: Multiple GPIOs, 3v3, EN, 5V, GND, and others for various functionalities.
DS18B20
- Description: Digital temperature sensor.
- Pins: signal, GND, vcc.
Resistor
- Description: Passive electrical component to create resistance.
- Value: 4700 Ohms.
LCD I2C Display
- Description: Alphanumeric liquid crystal display with I2C interface.
- Pins: GND, VCC, SDA, SCL.
Wiring Details
JSN-SR04T Sensor
- 5V: Connected to the 5V pin of the ESP32-S3.
- TRIG: Connected to GPIO4 of the ESP32-S3.
- ECHO: Connected to GPIO5 of the ESP32-S3.
- GND: Common ground with ESP32-S3, DS18B20, and LCD I2C Display.
ESP32-S3
- 3v3: Connected to the vcc pin of the DS18B20 through a 4700 Ohm resistor.
- GPIO4: Connected to the TRIG pin of the JSN-SR04T Sensor.
- GPIO5: Connected to the ECHO pin of the JSN-SR04T Sensor.
- GPIO14: Connected to the signal pin of the DS18B20.
- GPIO20: Connected to the SCL pin of the LCD I2C Display.
- GPIO21: Connected to the SDA pin of the LCD I2C Display.
- 5V: Supplies power to the JSN-SR04T Sensor and the LCD I2C Display.
- GND: Common ground with all other components.
DS18B20
- signal: Connected to GPIO14 of the ESP32-S3 through a 4700 Ohm resistor.
- GND: Common ground with ESP32-S3, JSN-SR04T Sensor, and LCD I2C Display.
- vcc: Connected to the 3v3 pin of the ESP32-S3 through a 4700 Ohm resistor.
Resistor
- pin1: Connected to the signal pin of the DS18B20.
- pin2: Connected to the 3v3 pin of the ESP32-S3.
LCD I2C Display
- GND: Common ground with ESP32-S3, JSN-SR04T Sensor, and DS18B20.
- VCC: Connected to the 5V pin of the ESP32-S3.
- SDA: Connected to GPIO21 of the ESP32-S3.
- SCL: Connected to GPIO20 of the ESP32-S3.
Documented Code
ESP32-S3 Code
/*
* This Arduino Sketch monitors the water level and temperature in a tank.
* It uses an ultrasonic sensor to measure the water level and a DS18B20
* sensor to measure the water temperature. The data is displayed on an
* I2C LCD and transmitted via WiFi to a web service.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin definitions
#define TRIG_PIN 4
#define ECHO_PIN 5
#define TEMP_PIN 14
#define SDA_PIN 21
#define SCL_PIN 20
// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* server = "http://your_server_address";
// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Temperature sensor setup
OneWire oneWire(TEMP_PIN);
DallasTemperature sensors(&oneWire);
// Tank dimensions
const float tankHeight = 2.5; // meters
const float tankWidth = 2.0; // meters
const float tankDepth = 2.0; // meters
const float tankVolume = tankHeight * tankWidth * tankDepth; // cubic meters
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize LCD
lcd.begin();
lcd.backlight();
// Initialize temperature sensor
sensors.begin();
// Initialize WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize ultrasonic sensor pins
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
// Measure distance
float distance = measureDistance();
float waterHeight = tankHeight - distance;
float waterVolume = waterHeight * tankWidth * tankDepth;
float fillPercentage = (waterVolume / tankVolume) * 100;
// Measure temperature
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
// Display data on LCD
lcd.setCursor(0, 0);
lcd.print("Volume: ");
lcd.print(waterVolume * 1000, 2); // Convert to liters
lcd.print(" L");
lcd.setCursor(0, 1);
lcd.print("Fill: ");
lcd.print(fillPercentage, 1);
lcd.print("%");
lcd.setCursor(8, 1);
lcd.print("Temp: ");
lcd.print(temperature, 1);
lcd.print("C");
// Send data to server
sendDataToServer(waterVolume, fillPercentage, temperature);
// Wait before next measurement
delay(5000);
}
float measureDistance() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH);
float distance = duration * 0.034 / 2;
return distance;
}
void sendDataToServer(float volume, float fill, float temp) {
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client;
if (client.connect(server, 80)) {
String postData = "volume=" + String(volume) + "&fill=" + String(fill) + "&temp=" + String(temp);
client.println("POST /data HTTP/1.1");
client.println("Host: " + String(server));
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: " + postData.length());
client.println();
client.println(postData);
client.stop();
}
}
}
(Note: The code for the JSN-SR04T Sensor and the LCD I2C Display microcontroller instances is not provided with specific functionality and is therefore not included in this documentation.)