#include <Wire.h> // For I2C communication (pH sensor and light sensor if needed)
#include <Adafruit_Sensor.h>
#define PH_SENSOR_PIN 25 // Define pH sensor pin (analog)
float phValue = 0.0; // pH value to be read from sensor
void setup() {
Serial.begin(9600);
// Initialize sensors
pinMode(PH_SENSOR_PIN, INPUT);
}
void loop() {
// Read pH level (analog)
int phValueRaw = analogRead(PH_SENSOR_PIN);
phValue = (phValueRaw * (14.0 / 4095.0)); // Scale raw value to pH range (0-14)
// Classify the pH value
String phClassification = classifyPH(phValue);
// Print sensor readings
Serial.print("pH: "); Serial.println(phValue); Serial.print(" - ");
Serial.println(phClassification); // Print the classification
delay(2000); // Adjust delay as per required sampling rate
}
String classifyPH(float ph) {
if (ph < 7.0) {
return "Acidic";
} else if (ph == 7.0) {
return "Neutral";
} else {
return "Alkaline";
}
}