Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →Detecting people's movement to build an alarm or smart lighting system.
VCC to 5V, GND to GND, and the middle signal pin to a digital pin like 2.
const int pirPin = 2;
const int ledPin = 13;
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Calibrating PIR...");
delay(30000); // يحتاج 30 ثانية ليتكيف مع حرارة الغرفة
}
void loop() {
if (digitalRead(pirPin) == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Motion Detected!");
} else {
digitalWrite(ledPin, LOW);
}
}Testing the sensor immediately after powering Arduino. The sensor needs a warm-up time of 30 to 60 seconds to recognize the room environment before it stabilizes.