Smart Water Filtration.

by ykhalifa28 in Circuits > Robots

176 Views, 4 Favorites, 0 Comments

Smart Water Filtration.

IMG_20250602_102013_013.jpg

This Arduino-based project addresses three critical environmental challenges: water scarcity, water pollution, and the efficient use of plant irrigation. The system collects and stores rainwater in a primary container, helping conserve freshwater resources. When needed, the water is transferred via a pump to a secondary container equipped with a filtration system, which removes dirt and harmful bacteria, ensuring clean water for irrigation. A soil moisture sensor monitors the plant’s needs, and it activates the watering system only when the soil is dry. This smart, automated solution promotes sustainable water use and healthier plant growth while minimizing waste.

Supplies

Screenshot 2025-06-02 145153.jpg

Arduino uno

1

Relay module

2

Water pump

2

Jumper wire

alot

Water level sensors

2

Soil moisture sensor.

1

lcd

1 i2c

breadboard

1

The wiring diagram is attached.

Code

#include <Wire.h>

#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27, 16, 2);


const int soilMoisturePin = A1;

const int waterLevel1Pin = A0;

const int waterLevel2Pin = A2;

const int relayPump1Pin = 2;

const int relayPump2Pin = 3;


const int soilDryThreshold = 600;

const int waterLowThreshold = 300;


unsigned long pump2StartTime = 0;

bool pump2Running = false;


void setup() {

pinMode(relayPump1Pin, OUTPUT);

pinMode(relayPump2Pin, OUTPUT);

digitalWrite(relayPump1Pin, HIGH); // OFF

digitalWrite(relayPump2Pin, HIGH); // OFF


lcd.init();

lcd.backlight();

lcd.print("System Starting...");

delay(2000);

lcd.clear();


lcd.setCursor(0, 0);

lcd.print("W1: W2: ");

lcd.setCursor(0, 1);

lcd.print("S: P1: P2:");

Serial.begin(9600);

}


void loop() {

int soilMoisture = analogRead(soilMoisturePin);

int waterLevel1 = analogRead(waterLevel1Pin); // Reservoir status

int waterLevel2 = analogRead(waterLevel2Pin); // Tank status


// Print values on LCD

lcd.setCursor(3, 0);

lcd.print(" ");

lcd.setCursor(3, 0);

lcd.print(waterLevel1);


lcd.setCursor(10, 0);

lcd.print(" ");

lcd.setCursor(10, 0);

lcd.print(waterLevel2);


lcd.setCursor(2, 1);

lcd.print(" ");

lcd.setCursor(2, 1);

lcd.print(soilMoisture);


Serial.print("Soil: "); Serial.print(soilMoisture);

Serial.print(" | Water1: "); Serial.print(waterLevel1);

Serial.print(" | Water2: "); Serial.println(waterLevel2);


bool pump1State = false;

bool pump2State = false;


if ((waterLevel1 > waterLowThreshold) && (waterLevel2 < waterLowThreshold)) {

digitalWrite(relayPump2Pin, LOW); // ON

} else {

digitalWrite(relayPump2Pin, HIGH); // OFF

}


if ((soilMoisture > soilDryThreshold) && (waterLevel2 > waterLowThreshold)) {

digitalWrite(relayPump1Pin, LOW); // ON

} else {

digitalWrite(relayPump1Pin, HIGH); // OFF

}


// Show pump statuses on LCD

lcd.setCursor(9, 1);

lcd.print(pump1State ? "ON " : "OFF");


lcd.setCursor(14, 1);

lcd.print(pump2State ? "ON" : "OFF");


delay(500);

}