Projects Hub, lesson 32 of 34

Water Level Monitoring and Fish Tank Pump Control with Arduino

intermediate3 min read

Introduction

Monitoring the water level in a fish tank and controlling the pump automatically ensures a healthy environment for your aquatic pets. In this project, we will use an ultrasonic sensor to monitor the water level in the tank and control a water pump using an Arduino. The water level will be displayed on an LCD screen for real-time monitoring.

Working Principle

The project works by using an ultrasonic sensor to measure the distance between the water surface and the top of the tank. This distance is then used to calculate the water level. The Arduino processes this data and controls the water pump to maintain the desired water level. When the water level is too low, the pump is activated to add more water. The current water level is displayed on an LCD screen for easy monitoring.

Things We Need

Before we get started, gather the following components:

  1. Arduino Uno
  2. HC-SR04 Ultrasonic Sensor
  3. 16x2 I2C LCD Display with I2C Module
  4. Relay Module (to control the pump)
  5. Water Pump
  6. Breadboard
  7. Jumper wires
  8. Power supply for the pump
  9. Fish tank

Circuit Diagram

Working of the System with Arduino

  1. Sensor Setup: Mount the ultrasonic distance sensor above the fish tank so that it can measure the water level. Connect its trigger and echo pins to digital pins on the Arduino.
  2. Pump Control: Wire the relay module to the Arduino. Connect one of the relay's terminals to the water pump and the other to an appropriate power supply. Ensure the pump's power supply voltage matches the relay's specifications.
  3. Arduino Programming: Write the Arduino code to read data from the ultrasonic sensor and control the relay module. The code should include logic to measure the water level and activate the pump if it falls below a certain threshold.
  4. Testing: Upload the code to the Arduino and test the system. Ensure that the pump activates when the water level falls below the threshold and deactivates when it reaches the desired level.

Code

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

// Initialize the LCD with I2C address 0x27 and 16x2 characters
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int trigPin = 9;
const int echoPin = 10;
const int relayPin = 7;
long duration;
int distance;
int tankHeight = 30; // Height of the tank in cm

void setup() {
  lcd.begin();
  lcd.backlight();
  
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(relayPin, OUTPUT);

  digitalWrite(relayPin, LOW); // Ensure the pump is off initially

  lcd.setCursor(0, 0);
  lcd.print("Water Level:");
  delay(1000);
}

void loop() {
  // Clear the trigPin by setting it LOW
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  // Set the trigPin HIGH for 10 microseconds to send the pulse
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read the echoPin, which returns the duration in microseconds
  duration = pulseIn(echoPin, HIGH);

  // Calculate the distance in cm
  distance = duration * 0.034 / 2;

  // Calculate the water level in the tank
  int waterLevel = tankHeight - distance;

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

  // Control the pump based on the water level
  if (waterLevel < 10) { // If water level is below 10 cm, turn on the pump
    digitalWrite(relayPin, HIGH);
  } else if (waterLevel > 20) { // If water level is above 20 cm, turn off the pump
    digitalWrite(relayPin, LOW);
  }

  delay(1000); // Wait for 1 second before the next measurement
}

Conclusion

Creating a water level monitoring and fish tank pump control system with Arduino can significantly simplify the task of maintaining an optimal water level in your aquarium. This automated setup ensures that your aquatic pets thrive in a stable environment. Moreover, it can be expanded with additional features such as real-time monitoring through a smartphone app or integrating a water filtration system to further enhance the health of your fish. By combining technology and aquaculture, you can enjoy a beautiful and thriving fish tank with ease.