Header Ads

Arduino with Pir Motion Sensor | Control Your Room Light by Motion Detection

Overview


In this tutorial, we will learn how to make automatic room light control by human motion detector using a PIR (Passive Infrared Sensor) sensor with Arduino. 

You can watch the following video below:-

Components Required

The required components list for this project given below:-
  • Arduino Uno
  • Pir Motion Sensor 
  • 5V Relay Module
  • AC Bulb
  • Breadboard
  • Some Jumper Wire

Pir Motion Sensor Pinout

The pinout of the Pir motion sensor has been given below:- 
Fig: Pir Motion Pin Configuration

Circuit Schematic

The circuit diagram of the Pir motion sensor interfacing with Arduino has been given below:- 
Fig: Pir Motion Sensor Interfacing with Arduino

    Circuit Description

    Source Code

    The source code is given below:-
     boolean sensingLow = true;  
     boolean takeSensingTime;   
        
     int pirPin = 7;  //the digital pin connected to the PIR sensor's output  
     int ledPin = 8;   
       
     void setup(){  
      Serial.begin(9600);  
      pinMode(pirPin, INPUT);  
      pinMode(ledPin, OUTPUT);  
      digitalWrite(pirPin, LOW);  
        
      Serial.print("calibrating sensor ");  
       for(int i = 0; i < 10; i++){  
        Serial.print(".");  
        delay(1000);  
        }  
       Serial.println(" done");  
       Serial.println("SENSOR ACTIVE");  
       delay(50);  
      }  
       
     void loop(){  
        
        if(digitalRead(pirPin) == HIGH){  
         digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state  
         if(sensingLow){   
         sensingLow = false;        
          }      
          takeSensingTime = true;  
         }  
        
        if(digitalRead(pirPin) == LOW){     
         digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state  
         if(takeSensingTime){  
         takeSensingTime = false;    //make sure this is only done at the start of a LOW phase  
         }  
         }  
      }  
    

    No comments

    Powered by Blogger.