Devices & Components
1Channel Relay 5v Robu
Official Arduino UNO EK (एक) R4 WiFi Made in India
Resistor 220 ohms Robu
PIR Sensor Robu
Jumper Wire Robu
LED Robu
Breadboard Robu
Software & Tools
Arduino IDE
Project description
Code
Smart LED Control Using PIR Sensor
cpp
EK Arduino Uno R4 Wi fi
1#define PIR_PIN 2 // PIR sensor OUT 2#define RELAY_PIN 8 // Relay control pin 3#define LED_PIN 12 // LED output pin 4 5void setup() { 6 pinMode(PIR_PIN, INPUT); 7 pinMode(RELAY_PIN, OUTPUT); 8 pinMode(LED_PIN, OUTPUT); 9 10 digitalWrite(RELAY_PIN, HIGH); // Relay OFF initially (active LOW) 11 digitalWrite(LED_PIN, LOW); // LED OFF initially 12 13 Serial.begin(115200); 14 Serial.println("Breadboard PIR + Relay + LED system ready."); 15} 16 17void loop() { 18 int motion = digitalRead(PIR_PIN); 19 20 if (motion == HIGH) { 21 Serial.println("Motion detected!"); 22 23 digitalWrite(RELAY_PIN, LOW); // Turn ON relay 24 digitalWrite(LED_PIN, HIGH); // Turn ON LED 25 26 delay(2000); // Keep ON for 2 seconds 27 28 digitalWrite(RELAY_PIN, HIGH); // Turn OFF relay 29 digitalWrite(LED_PIN, LOW); // Turn OFF LED 30 31 Serial.println("Motion ended."); 32 } 33 34 delay(100); // debounce 35}
Downloadable files
schematics for Smart LED Control Using PIR Sensor
file.None

Comments
Only logged in users can leave comments