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

Arduino-Controlled Automatic Water Pump System with Dual Level Sensing and I2C LCD Feedback

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Automatic Water Pump System with Dual Level Sensing and I2C LCD Feedback

Circuit Documentation

Summary

The circuit described is a Rain Drainage Water Removal System designed to control a water pump based on readings from two water level sensors. It features an Arduino UNO microcontroller, which interfaces with a capacitive sensor, two water level sensors, a two-channel relay module, and an I2C LCD screen. The system also includes an LED indicator and voltage regulation components. The purpose of the circuit is to monitor water levels and activate a water pump to remove excess water, with the system status displayed on the LCD and indicated by the LED.

Component List

Battery (12V)

Two Channel Relay (5V)

Water Level Sensor

Water Pump

Voltage Regulator (7805)

Arduino UNO

LED (White)

Resistor (200 Ohms)

Capacitive Sensor

I2C LCD 16x2 Screen

Wiring Details

Battery (12V)

Two Channel Relay (5V)

Water Level Sensor

Water Pump

Voltage Regulator (7805)

Arduino UNO

LED (White)

Resistor (200 Ohms)

Capacitive Sensor

I2C LCD 16x2 Screen

Documented Code

/*
 * Rain Drainage Water Removal System
 *
 * This Arduino sketch controls a water pump based on the readings from two
 * water level sensors. The system displays the water level status on an I2C
 * LCD screen and indicates the pump status using an LED.
 */

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

// Pin definitions
const int waterLevelSensor1Pin = A5;
const int waterLevelSensor2Pin = A4;
const int capacitiveSensorPin = A2;
const int ledPin = 13;
const int relayPin1 = 7;
const int relayPin2 = 8;

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

// Timing variables
unsigned long pumpOnTime = 0;
unsigned long pumpOffTime = 0;
bool pumpState = false;

// Display variables
unsigned long lastDisplayUpdate = 0;
const unsigned long displayInterval = 2000; // 2 seconds
int displayState = 0;

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

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

  // Initialize pins
  pinMode(waterLevelSensor1Pin, INPUT);
  pinMode(waterLevelSensor2Pin, INPUT);
  pinMode(capacitiveSensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin1, OUTPUT);
  pinMode(relayPin2, OUTPUT);

  // Initial state
  digitalWrite(ledPin, LOW);
  digitalWrite(relayPin1, LOW);
  digitalWrite(relayPin2, LOW);
}

void loop() {
  // Read sensor values
  int waterLevel1 = analogRead(waterLevelSensor1Pin);
  int waterLevel2 = analogRead(waterLevelSensor2Pin);
  int capacitiveLevel = analogRead(capacitiveSensorPin);

  // Check water levels and control pump
  if (waterLevel1 > 500 || waterLevel2 > 500 || capacitiveLevel > 500) {
    if (!pumpState) {
      // Turn on pump
      digitalWrite(relayPin1, HIGH);
      digitalWrite(relayPin2, HIGH);
      digitalWrite(ledPin, HIGH);
      pumpOnTime = millis();
      pumpState = true;
    }
  } else {
    if (pumpState) {
      // Turn off pump
      digitalWrite(relayPin1, LOW);
      digitalWrite(relayPin2, LOW);
      digitalWrite(ledPin, LOW);
      pumpOffTime = millis();
      pumpState = false;

      // Print pump on and off times
      Serial.print("Pump was on for: ");
      Serial.print((pumpOffTime - pumpOnTime) / 1000);
      Serial.println(" seconds");
    }
  }

  // Update LCD display
  if (millis() - lastDisplayUpdate > displayInterval) {
    lastDisplayUpdate = millis();
    lcd.clear();
    switch (displayState) {
      case 0:
        lcd.setCursor(0, 0);
        lcd.print("Water1: ");
        lcd.print(waterLevel1);
        lcd.setCursor(0, 1);
        lcd.print("Water2: ");
        lcd.print(waterLevel2);
        break;
      case 1:
        lcd.setCursor(0, 0);
        lcd.print("Capacitive: ");
        lcd.print(capacitiveLevel);
        lcd.setCursor(0, 1);
        lcd.print("Pump: ");
        lcd.print(pumpState ? "ON " : "OFF");
        break;
      case 2:
        lcd.setCursor(0, 0);
        lcd.print("Pump On Time: ");
        lcd.setCursor(0, 1);
        lcd.print((pumpState ? millis() : pumpOffTime) - pumpOnTime);
        lcd.print(" ms");
        break;
    }
    displayState = (displayState + 1) % 3;
  }

  // Delay for stability
  delay(1000);
}

This code is responsible for reading the sensor data, controlling the relay to power the pumps, updating the LCD display, and providing a visual indication of the pump status via an LED. It includes setup and loop functions that initialize the system and handle the main operational logic.