Translate

Arduino Ultrasonic Automatic Water Level Controller

📖 1. Introduction

Monitoring water level manually is difficult and often leads to overflow or dry running of motors. A smart system with display gives real-time information.

In this project, we design a reliable water level controller with LCD display using:

👉 JSN-SR04T Waterproof Ultrasonic Sensor
👉 16x2 LCD for real-time level display
👉 Automatic motor control using relay

This system is accurate, durable, and user-friendly.


🔧 2. Components

  • Arduino UNO
  • JSN-SR04T Waterproof Ultrasonic Sensor
  • 16x2 LCD Display with I2C Module
  • Relay Module (5V)
  • Water Pump / Motor
  • Buzzer (optional)
  • Connecting wires
  • 5V Power Supply

🔌 3. Circuit and Connections

Pinout Diagram of Arduino Uno R3

Pinout Diagram of Single Channel Relay Module

Pinout Diagram of JSN SR04T Ultrasonic Sensor

Pinout Diagram Buzzer


Pinout Diagram of LCD with I2C


📍 Ultrasonic Sensor:

  • VCC → 5V
  • GND → GND
  • TRIG → Pin 6
  • ECHO → Pin 7

📍 Relay:

  • INPUT → Pin 8
  • Motor One end to Phase other to Normally Open pin 
  • Common Contact  → Neutral Point

📍 Buzzer:

    • Positive → Pin 9
    • Negative → GND

📍 LCD (I2C):

  • VCC → 5V
  • GND → GND
  • SDA → A4
  • SCL → A5

⚙️ 4. Step by Step Circuit Working

  1. Ultrasonic sensor measures distance from tank top to water
  2. Arduino calculates water level
  3. Converts it into percentage (%)
  4. Displays:
    • Water Level (cm)
    • Percentage (%)

Decision Logic:

  • Low level → Motor ON
  • Full tank → Motor OFF
  • LCD shows live status

💻 5. Code

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

#define trigPin 6
#define echoPin 7
#define relay 8
#define buzzer 9

LiquidCrystal_I2C lcd(0x27, 16, 2);

long duration;
int distance;
int waterLevel;

int tankHeight = 40; // cm

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);

lcd.init();
lcd.backlight();

Serial.begin(9600);
}

int getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
return duration * 0.034 / 2;
}

void loop() {

long total = 0;

for(int i = 0; i < 5; i++) {
total += getDistance();
delay(50);
}

distance = total / 5;
waterLevel = tankHeight - distance;

int percentage = (waterLevel * 100) / tankHeight;

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Level:");
lcd.print(waterLevel);
lcd.print("cm");

lcd.setCursor(0,1);
lcd.print("Fill:");
lcd.print(percentage);
lcd.print("%");

if (waterLevel < 10) {
digitalWrite(relay, HIGH);
digitalWrite(buzzer, LOW);
}

else if (waterLevel > 35) {
digitalWrite(relay, LOW);
digitalWrite(buzzer, HIGH);
}

delay(1000);
}

🔍 6. Step by Step Code Working

  • LiquidCrystal_I2C → controls LCD
  • getDistance() → reads ultrasonic data
  • 5 readings averaged → improves accuracy
  • Water level calculated
  • Converted to percentage (%)

LCD Output:

  • Line 1 → Level in cm
  • Line 2 → Percentage

Control:

  • Low → Motor ON
  • Full → Motor OFF

💡 7. Tips

✔ Use correct I2C address (0x27 or 0x3F)
✔ Mount sensor vertically
✔ Use enclosure for protection
✔ Adjust tank height correctly
✔ Use good quality power supply


🚀 8. Uses

  • Smart home water tank
  • Apartment automation
  • Industrial monitoring
  • Farming irrigation systems

⚠️ 9. Common Issues and Solutions

❌ LCD not displaying

✔ Check I2C address

❌ Wrong readings

✔ Adjust tank height
✔ Use averaging

❌ Flickering display

✔ Add delay

❌ Sensor error

✔ Check wiring and alignment


🧠 10. Conclusion

This project combines automation + monitoring + display, making it a complete smart water management system.

It is highly suitable for real-world implementation and student learning.

തുടക്കക്കാർക്കായി ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.