#include <Wire.h> // For I2C communication (pH sensor and light sensor if needed)
#include <Adafruit_Sensor.h>
#define LIGHT_SENSOR_PIN 34 // Define light sensor pin (analog)
#define LED_PIN 26 // LED light control pin
int lightIntensity = 0; // Light intensity value
int threshold = 500; // Initial threshold for testing, to be calibrated
void setup() {
Serial.begin(9600);
// Initialize sensors
pinMode(LIGHT_SENSOR_PIN, INPUT);
// Initialize output devices
pinMode(LED_PIN, OUTPUT);
// Turn off all output devices initially
digitalWrite(LED_PIN, LOW);
Serial.println("Calibrating... Check the Light Intensity Values on Serial Monitor.");
Serial.println("Adjust the threshold in the code accordingly.");
}
void loop() {
// Read light intensity
lightIntensity = analogRead(LIGHT_SENSOR_PIN);
// Print sensor readings
Serial.print("Light Intensity: "); Serial.println(lightIntensity);
// Check and display the current threshold
Serial.print("Current Threshold: "); Serial.println(threshold);
// Control logic for output devices
controlLED();
delay(2000); // Adjust delay as per required sampling rate
}
void controlLED() {
if (lightIntensity < threshold) { // Compare with the threshold
digitalWrite(LED_PIN, HIGH); // Turn on LED if light intensity is low
Serial.println("LED ON");
} else {
digitalWrite(LED_PIN, LOW);
Serial.println("LED OFF");
}
}