const int pHSensorPin = A0; // Analog pin connected to the pH sensor
const int turbiditySensorPin = A1; // Analog pin connected to the turbidity sensor
const int trigPin = 2; // Ultrasonic sensor's trig pin connected to digital pin 2
const int echoPin = 3; // Ultrasonic sensor's echo pin connected to digital pin 3
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
int sensorValue_pH = analogRead(pHSensorPin); // Read pH sensor analog value
float voltage_pH = sensorValue_pH * (5.0 / 1023.0); // Convert analog value to voltage for pH
int sensorValue_turbidity = analogRead(turbiditySensorPin); // Read turbidity sensor analog value
// Ultrasonic sensor to determine water level
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
// Check turbidity value, pH value, and water level to determine water condition
if (sensorValue_turbidity > 500 || voltage_pH < 1.8 || voltage_pH > 3.0) {
// If turbidity is high or pH is outside the safe range
Serial.println("Water condition: Not clean");
// Check pH level to determine acidity, neutrality, or alkalinity
if (voltage_pH < 1.8) {
Serial.println("Water pH is acidic");
} else if (voltage_pH > 3.0) {
Serial.println("Water pH is alkaline");
} else {
Serial.println("Water pH is neutral");
}
// Add code here for the filtering process or any actions for not clean water
} else {
// If turbidity is low and pH is within safe range
Serial.println("Water is clean");
}
// Determine water level based on ultrasonic sensor reading
if (distance >= 30) {
Serial.println("Water level: Full");
} else if (distance < 30 && distance > 10) {
Serial.println("Water level: Normal");
} else {
Serial.println("Water level: Too low");
}
delay(500); // Delay for readability, adjust as needed
}