O Level Exam : Practical Question
📝 HTML
🎨 CSS
⚡ Java Script
void setup() { // Initialize the Serial Monitor at a baud rate of 9600 Serial.begin(9600); // Set the PIR sensor pin as input pinMode(2, INPUT); // Set the built-in LED pin as output pinMode(13, OUTPUT); } void loop() { // Read the value from the PIR sensor int sensorValue = digitalRead(2); // Print the sensor value to the Serial Monitor Serial.println(sensorValue); // If motion is detected, turn on the LED if (sensorValue == HIGH) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } // Add a small delay to avoid overwhelming the Serial Monitor delay(100); }
▶ Run Code
🖥 Output: