const int PH_PIN = 34; // Pin connected to the pH sensor
const int LED_PIN = 13; // Pin connected to the LED
const float PH_THRESHOLD = 5.5; // pH value below which the LED should be turned on
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // Ensure LED is off initially
}
void loop() {
// Read the pH sensor value (analog value from 0 to 4095)
int sensorValue = analogRead(PH_PIN);
// Convert the sensor value to pH (calibrate this for your specific sensor)
float pHValue = map(sensorValue, 0, 4095, 0, 14); // Example conversion; adjust as needed
// Print the pH value for debugging
Serial.print("pH: ");
Serial.println(pHValue);
// Check if the pH level is below the threshold and control LED
if (pHValue < PH_THRESHOLD) {
digitalWrite(LED_PIN, HIGH); // Turn on LED if pH is below PH_THRESHOLD
} else {
digitalWrite(LED_PIN, LOW); // Turn off LED if pH is within the acceptable range
}
// Wait before the next reading
delay(2000); // Adjust delay as needed
}