// Define GPIO pins
const int pebbleSandPin = 22; // for pebble and sand detection
const int waterLevelPin = A0; // pin for water level sensor
const int pHLevelPin = 25; // pin for pH level sensor
const int aquaPin = 5; // pin connected to the Aqua system
const int lightPin = 32; // pin connected to the Light system
void setup() {
Serial.begin(115200);
// Set pinMode for Aqua and Light systems
pinMode(aquaPin, OUTPUT);
pinMode(lightPin, OUTPUT);
}
void loop() {
// Read sensor values
int pebbleSand = digitalRead(pebbleSandPin);
int waterLevel = analogRead(waterLevelPin);
int pHLevel = analogRead(pHLevelPin);
// Print sensor values
Serial.print("Pebble and Sand: ");
Serial.print(pebbleSand);
Serial.print(", Water Level: ");
Serial.print(waterLevel);
Serial.print(", pH Level: ");
Serial.println(pHLevel);
// Condition 1: Pebble and sand detected, low water level, pH less than 7
if (pebbleSand && (waterLevel < 200) && (pHLevel < 7)) {
digitalWrite(aquaPin, HIGH); // Turn on Aqua
digitalWrite(lightPin, LOW); // Turn on Light
}
// Condition 2: Pebble and sand undetected, low water level, pH more or equal to 7
else if (!pebbleSand && (waterLevel < 200) && (pHLevel >= 700)) {
digitalWrite(aquaPin, HIGH); // Turn on Aqua
digitalWrite(lightPin, LOW); // Turn off Light
}
// Condition 3: pH less than 7, pebble and sand undetected
else if ((pHLevel < 700) && !pebbleSand) {
digitalWrite(aquaPin, LOW); // Turn off Aqua
// Blink the light LED
digitalWrite(lightPin, HIGH);
delay(500);
digitalWrite(lightPin, LOW);
delay(500);
}
// Condition 4: Low water level, pH more or equal to 7
else if ((waterLevel < 200) && (pHLevel >= 700)) {
digitalWrite(aquaPin, HIGH); // Turn on Aqua
digitalWrite(lightPin, LOW); // Turn off Light
}
// Condition 5: Pebble and sand undetected, water level is overflow, pH more or equal to 7
else if (!pebbleSand && (waterLevel >= 900) && (pHLevel >= 700)) {
digitalWrite(aquaPin, LOW); // Turn off Aqua
digitalWrite(lightPin, LOW); // Turn off Light
}
// Blink the light LED
digitalWrite(lightPin, HIGH);
delay(500); // Adjust delay duration as needed
digitalWrite(lightPin, LOW);
delay(500); // Adjust delay duration as needed
// Delay for stability
//delay(500);
}Loading
ds18b20
ds18b20