O Level Exam : Practical Question
📝 HTML
🎨 CSS
⚡ Java Script
#define LDR_PIN A0 // LDR connected to analog pin A0 #define LED_PIN 13 // LED connected to pin 13 int threshold = 500; // Light level threshold (adjust as needed) void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(9600); } void loop() { int lightValue = analogRead(LDR_PIN); // Read LDR value Serial.print("Light Level: "); Serial.print(lightValue); if (lightValue > threshold) { Serial.println(" | Light Detected | LED ON"); digitalWrite(LED_PIN, HIGH); } else { Serial.println(" | No Light | LED OFF"); digitalWrite(LED_PIN, LOW); } delay(1000); }
▶ Run Code
🖥 Output: