Arduino Easy Smart Home Series: Motion-Activated Room Light
Arduino Easy Smart Home Series: Motion-Activated Room Light
Automate your lights! πΆπ‘ This project uses a PIR motion sensor to turn LEDs or a room light on when motion is detected, and off after a set delay. Perfect for hallways, bedrooms, or energy-saving smart homes. Learn about sensors, interrupts, and Arduino logic while creating a practical automation device!
Table of Contents
- Introduction
- Required Hardware
- Arduino IDE Setup
- Wiring the Components
- Arduino Code
- How It Works
- Testing Your Project
- Advanced Modifications
- Common Issues and Troubleshooting
- Learning Insights
- Conclusion
1. Introduction
The Motion-Activated Room Light project allows your room lights or LED setup to respond automatically to human movement. Using a PIR sensor, the system detects motion and turns on the lights immediately. After a defined inactivity period, the lights turn off automatically. This project teaches sensor interfacing, timing logic, and energy-efficient automation, making it perfect for beginners exploring smart home applications.
2. Required Hardware
- Arduino UNO or compatible board (Approx. ₹2,100)
- PIR Motion Sensor (HC-SR501) (Approx. ₹150)
- LEDs or a small room lamp (8 LEDs or 1 lamp, Approx. ₹850)
- Resistors 220Ξ© (if using LEDs) (Approx. ₹420)
- Relay module (if controlling a lamp) (Approx. ₹300)
- Jumper wires (Approx. ₹100)
- Breadboard (Approx. ₹300)
- Arduino IDE installed on your PC
3. Arduino IDE Setup
- Install the Arduino IDE from the official site.
- Connect your Arduino board to your PC via USB.
- Select your board type and COM port under Tools.
4. Wiring the Components
- Connect the VCC of PIR to 5V and GND to GND on Arduino.
- Connect the output pin of PIR to digital pin 2 on Arduino.
- Connect LEDs to digital pins 3–10 (or a relay to control a lamp) with appropriate resistors.
- If using a relay, ensure it is rated for the load and shares a common ground with Arduino.
5. Arduino Code
Upload this code to make your LEDs or lamp respond to motion with adjustable off delay:
// Motion-Activated Room Light const int pirPin = 2; // PIR sensor output const int ledPin = 3; // LED or relay control const unsigned long offDelay = 10000; // 10 seconds delay unsigned long lastMotionTime = 0; bool ledState = false; void setup() { pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); Serial.begin(9600); } void loop() { int motion = digitalRead(pirPin); if(motion == HIGH){ digitalWrite(ledPin, HIGH); ledState = true; lastMotionTime = millis(); Serial.println("Motion Detected - LED ON"); } // Turn off LED after delay if(ledState && (millis() - lastMotionTime >= offDelay)){ digitalWrite(ledPin, LOW); ledState = false; Serial.println("No Motion - LED OFF"); } }
6. How It Works
The PIR sensor detects infrared radiation emitted by moving humans. When motion is detected, the PIR output goes HIGH, triggering the LED or relay. The Arduino records the last motion time and keeps the light on. After the defined delay with no motion, the system turns off the light. This simple logic ensures energy efficiency and automated lighting control.
7. Testing Your Project
- Power up the Arduino and check PIR status via Serial Monitor.
- Move in front of the sensor to ensure the LED or lamp turns on immediately.
- Wait the offDelay period to verify the lights turn off automatically.
- Adjust PIR sensitivity or offDelay time as needed for your environment.
8. Advanced Modifications
- Add multiple LEDs or relay-controlled lights in different zones.
- Use interrupts instead of polling for instant reaction and lower power consumption.
- Integrate with WiFi or IoT to control lights remotely when no motion is detected.
- Add a dimmer circuit or PWM-controlled LEDs for gradual fade in/out.
- Combine with a timer or schedule for advanced home automation.
9. Common Issues and Troubleshooting
- LED or lamp not turning on – Verify PIR wiring and LED/resistor connections.
- False triggers – Adjust PIR sensor sensitivity and delay potentiometer.
- Light stays on – Check if offDelay logic is working correctly and millis() overflow.
- Relay not switching – Ensure relay is rated for load and shares common ground with Arduino.
10. Learning Insights
- Understanding PIR sensor operation and analog/digital interfacing.
- Implementing time-based logic with millis() for automation.
- Practical experience in energy-efficient smart home devices.
- Integration of sensors with output devices like LEDs and relays.
11. Conclusion
The Motion-Activated Room Light project is a practical smart home solution that automates your lighting based on human presence. It introduces beginners to sensor interfacing, timing logic, and real-world automation applications. Expand this project with multiple zones, IoT connectivity, or dimming to create a fully customized automated lighting system for your home.
By Kaushal Haladi
Comments
Post a Comment