ESP32-Based Smart Water Flow and Ultrasonic Level Monitoring System with I2C LCD Display
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to measure water flow and distance using a water flow sensor and an ultrasonic distance sensor, respectively. The data is processed by an ESP32 microcontroller and displayed on a 16x2 I2C LCD. The ESP32 also handles the communication with the sensors and the display.
Component List
Water Flow Sensor
- Description: Measures the rate of water flow.
- Pins: Signal, Vcc, GND
ESP32-Devkitc-V4
- Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: 3v3, EN, VP, VN, 34, 35, 32, 33, 25, 26, 27, 14, 12, GND, 13, D2, D3, CMD, 5V, 23, 22, TX, RX, 21, 19, 18, 5, 17, 16, 4, 0, 2, 15, D1, D0, CLK
MKE-S01 Ultrasonic Distance Sensor
- Description: Measures distance using ultrasonic waves.
- Pins: GND, 5V, TRIG, ECHO
16x2 I2C LCD
- Description: Displays data in a 16x2 character format using I2C communication.
- Pins: GND, VCC, SDA, SCL
Wiring Details
Water Flow Sensor
- Signal pin connected to D0 pin of ESP32-Devkitc-V4
- Vcc pin connected to 3v3 pin of ESP32-Devkitc-V4
- GND pin connected to GND pin of ESP32-Devkitc-V4
ESP32-Devkitc-V4
- 3v3 pin connected to Vcc pin of Water Flow Sensor
- D0 pin connected to Signal pin of Water Flow Sensor
- D2 pin connected to TRIG pin of MKE-S01 Ultrasonic Distance Sensor
- D3 pin connected to ECHO pin of MKE-S01 Ultrasonic Distance Sensor
- 5V pin connected to VCC pin of 16x2 I2C LCD and 5V pin of MKE-S01 Ultrasonic Distance Sensor
- GND pin connected to GND pin of 16x2 I2C LCD, Water Flow Sensor, and MKE-S01 Ultrasonic Distance Sensor
- 22 pin connected to SCL pin of 16x2 I2C LCD
- 21 pin connected to SDA pin of 16x2 I2C LCD
MKE-S01 Ultrasonic Distance Sensor
- TRIG pin connected to D2 pin of ESP32-Devkitc-V4
- ECHO pin connected to D3 pin of ESP32-Devkitc-V4
- 5V pin connected to 5V pin of ESP32-Devkitc-V4
- GND pin connected to GND pin of ESP32-Devkitc-V4
16x2 I2C LCD
- GND pin connected to GND pin of ESP32-Devkitc-V4
- VCC pin connected to 5V pin of ESP32-Devkitc-V4
- SCL pin connected to 22 pin of ESP32-Devkitc-V4
- SDA pin connected to 21 pin of ESP32-Devkitc-V4
Documented Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Inisialisasi LCD I2C dengan alamat 0x27 (alamat bisa berbeda tergantung modul)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Inisialisasi pin sensor ultrasonik
const int trigPin = 2;
const int echoPin = 3;
// Inisialisasi pin sensor aliran air
const int flowSensorPin = 0;
void setup() {
// Inisialisasi LCD
lcd.begin();
lcd.backlight();
lcd.print("Level Tangki:");
// Inisialisasi pin sensor ultrasonik
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Inisialisasi pin sensor aliran air
pinMode(flowSensorPin, INPUT);
}
void loop() {
// Mengukur jarak menggunakan sensor ultrasonik
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
// Menampilkan jarak pada LCD
lcd.setCursor(0, 1);
lcd.print("Jarak: ");
lcd.print(distance);
lcd.print(" cm ");
// Membaca data dari sensor aliran air
int flowRate = digitalRead(flowSensorPin);
// Proses data flowRate sesuai kebutuhan
delay(1000);
}
This code initializes the LCD, ultrasonic distance sensor, and water flow sensor. It measures the distance using the ultrasonic sensor and displays it on the LCD. It also reads the water flow rate from the water flow sensor.