xxxxxxxxxx
const int photodiodePin = A0;
const int ledPin = 13;
int sensorValue = 0;
int threshold = 50; // Adjust this value based on your ambient light
unsigned long turnOnTime = 0;
unsigned long turnOffTime = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(photodiodePin);
Serial.println(sensorValue);
if (sensorValue < threshold) {
if (digitalRead(ledPin) == LOW) {
turnOnTime = millis();
Serial.print("LED turned on at: ");
Serial.println(turnOnTime);
}
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
if (digitalRead(ledPin) == HIGH) {