float tempSensorPin = A0; //Define the temp sensor pin
int heaterPin = 2; //Define the heater pin number
int thresholdTemp = 22; //Define the threshold temp
float pHSensorPin = A1; //Define the pH sensor pin
int filterSystem = 3; //Define the filter system pin number
int thresholdpH = 7; //Define the threshold pH
float ammoniaSensorPin = A2; //Define the ammonia sensor pin
int waterPump = 4; //Define the water pump system pin number
int thresholdAmmonia = 0.5; //Define the threshold ammonia level
#include <LiquidCrystal.h> //Connecting the LCD Display
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); //Pin numbers for the LCD Display
float temp = 0;
void setup() {
Serial.begin(9600); //Initialising the serial communication
pinMode(heaterPin, OUTPUT); //Set the heater pin as an output
pinMode(filterSystem, OUTPUT); //Set the filter system as an output
pinMode(waterPump, OUTPUT); //Set the water pump as an output
lcd.begin(16, 2); //Defining the type of LCD Display in use
}
void loop() {
int temp = analogRead(A0); //Read the temp from the sensor
float celsius = (5*temp*100)/1024; //Sensor value converstion to C
Serial.print("Temperature: "); //Print the temperature term
Serial.print(celsius); //Print the value
Serial.println("C"); //Print the unit
//Check if temperature is above the threshold value
if (temp < 22) { //if temperature is lower than 22 degrees
digitalWrite(heaterPin, HIGH); //turn on heater system
} else if (temp > 25) { //if temperature is higher than 25 degrees
digitalWrite(heaterPin, LOW); //turn on heater system
} else { //if temperature is within the desired range
digitalWrite(heaterPin, LOW); //turn off heater system
}
delay(500); //Wait for 500ms
int pH = analogRead(A1); //Read the pH from the sensor
float pHLevel = (14*pH) / 1024; //Sensor value conversion to pH level
Serial.print("pH Level: "); //Print the pH level term
Serial.print(pH); //Print the value
Serial.println(" pH"); //Print the unit
//Check if pH level is above the threshold value
if (pH>thresholdpH){
digitalWrite(filterSystem, HIGH); //Turn on the filter
} else{
digitalWrite(filterSystem, LOW); //Turn off the filter
}
delay(500);//Wait 500ms
int ammonia = analogRead(A2); //Read the ammonia level from the sensor
float ppm = (ammonia*5) /1024; //Sensor value conversion to ppm
Serial.print("Ammonia: "); //Print the ammonia term
Serial.print(ppm); //Print the value
Serial.println("ppm"); //Print the unit
//Check if Ammonia level is above the threshold value
if (ppm>thresholdAmmonia){
digitalWrite(waterPump, HIGH); //Turn water pump on
} else{
digitalWrite(waterPump, LOW); //Turn water pump off
}
delay(500); //Wait 500ms
// Clear the LCD
lcd.clear();
// Display temperature reading
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(celsius);
lcd.print("*C");
// Display pH reading
lcd.setCursor(0, 1);
lcd.print("pH:");
lcd.print(pH);
// Display ammonia reading
lcd.setCursor(6, 1);
lcd.print("NH3:");
lcd.print(ammonia);
lcd.print("ppm");
}