Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino ESP32 Automated Water Tank Filling System with Flow Monitoring

View and Edit Project In Cirkit DesignerImage of Arduino ESP32 Automated Water Tank Filling System with Flow Monitoring

Water Tank Monitoring and Control System Documentation

Summary

This circuit is designed to monitor and control a water tank system. It features an ultrasonic sensor to measure water levels, an LCD display for status updates, a water flow sensor to ensure the pump's proper operation, a relay module to control a water pump, and indicators including a buzzer and LEDs for alerting about the water level status. The system is managed by an Arduino Nano ESP32 microcontroller, which processes the sensor data, controls the pump, and communicates with a mobile app for remote monitoring.

Component List

Water Flow Sensor

LCD Display 16x4 I2C

KY-019 Relay Module 1 Channel

Water Pump

Arduino Nano ESP32

Ultrasonic Sensor

Buzzer

LED: Two Pin (Green)

LED: Two Pin (Red)

Resistor

Wiring Details

Water Flow Sensor

LCD Display 16x4 I2C

KY-019 Relay Module 1 Channel

Water Pump

Arduino Nano ESP32

Ultrasonic Sensor

Buzzer

LED: Two Pin (Green)

LED: Two Pin (Red)

Resistor

Documented Code

/*
 * This Arduino Sketch monitors and controls a water tank system.
 * It uses an ultrasonic sensor to measure water levels, displays the status on an LCD,
 * and sends updates to a mobile app. When the water level is low, it triggers a red LED
 * and a buzzer, then starts a water pump. When the tank is full, it stops the pump,
 * turns on a green LED, and sounds the buzzer. The water flow sensor ensures the pump
 * is working correctly.
 */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Pin definitions
#define WATER_FLOW_SENSOR_PIN 4
#define ULTRASONIC_TRIGGER_PIN 2
#define ULTRASONIC_ECHO_PIN 3
#define RELAY_PIN 3
#define BUZZER_PIN 5
#define RED_LED_PIN 7
#define GREEN_LED_PIN 6

// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 4);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize LCD
  lcd.begin();
  lcd.backlight();

  // Initialize pins
  pinMode(WATER_FLOW_SENSOR_PIN, INPUT);
  pinMode(ULTRASONIC_TRIGGER_PIN, OUTPUT);
  pinMode(ULTRASONIC_ECHO_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);

  // Initial states
  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(GREEN_LED_PIN, LOW);
}

void loop() {
  // Measure water level
  int waterLevel = measureWaterLevel();

  // Display water level on LCD
  lcd.setCursor(0, 0);
  lcd.print("Water Level: ");
  lcd.print(waterLevel);

  if (waterLevel == 1) {
    // Low water level
    lcd.setCursor(0, 1);
    lcd.print("Status: Low");
    alertLowWaterLevel();
    startWaterPump();
  } else if (waterLevel == 6) {
    // Full water level
    lcd.setCursor(0, 1);
    lcd.print("Status: Full");
    stopWaterPump();
    alertFullWaterLevel();
  }

  // Monitor water flow
  monitorWaterFlow();

  // Delay for stability
  delay(1000);
}

int measureWaterLevel() {
  // Send trigger pulse
  digitalWrite(ULTRASONIC_TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(ULTRASONIC_TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(ULTRASONIC_TRIGGER_PIN, LOW);

  // Measure echo pulse
  long duration = pulseIn(ULTRASONIC_ECHO_PIN, HIGH);
  int distance = duration * 0.034 / 2;

  // Convert distance to water level (1 to 6)
  if (distance < 10) return 6;
  else if (distance < 20) return 5;
  else if (distance < 30) return 4;
  else if (distance < 40) return 3;
  else if (distance < 50) return 2;
  else return 1;
}

void alertLowWaterLevel() {
  // Blink red LED and sound buzzer
  for (int i = 0; i < 5; i++) {
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(BUZZER_PIN, HIGH);
    delay(500);
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
    delay(500);
  }
  // Send low water level alert to mobile app
  Serial.println("Low water level!");
}

void alertFullWaterLevel() {
  // Turn on green LED and sound buzzer
  digitalWrite(GREEN_LED_PIN, HIGH);
  digitalWrite(BUZZER_PIN, HIGH);
  delay(5000);
  digitalWrite(GREEN_LED_PIN, LOW);
  digitalWrite(BUZZER_PIN, LOW);
  // Send full water level alert to mobile app
  Serial.println("Water tank full!");
}

void startWaterPump() {
  digitalWrite(RELAY_PIN, HIGH);
  Serial.println("Water pump started.");
}

void stopWaterPump() {
  digitalWrite(RELAY_PIN, LOW);
  Serial.println("Water pump stopped.");
}

void monitorWaterFlow() {
  int flowRate = digitalRead(WATER_FLOW_SENSOR_PIN);
  Serial.print("Water flow rate: ");
  Serial.println(flowRate);
  // Send water flow rate to mobile app
}

This code is responsible for the operation of the water tank monitoring and control system. It initializes the hardware components, takes measurements from the sensors, controls the water pump via the relay, and provides visual and audible alerts based on the water level. It also communicates with a mobile app to provide real-time updates on the system's status.