How to Make a Motion Sensor Light Switch using Arduino

Security is the major concern at our home, office and other areas where safety and security are required. We use the different type of home security system to protect the premises from the trespassers and the thief.

We are working on PIR motion sensor light switch project. It is used to deter the trespasser who enters into the secured area. It is a very simple project.

We are using the motion sensor to detect the movement of the trespasser. Once movement is detected it switches the light ON automatically for a period of time – typically around 30-40 seconds. It can be used to deter the trespassers and burglary as well as can be used to automatic night lamp when you come at home at night. We can connect a small night light lamp to flood light depending on the application need of the user.

How to build Motion Sensor PIR Light Switch Project

We are interfacing the motion sensor to the arduino using the arduino interrupt. And once any motion is detected by the Motion Sensor PIR Light Switch it sends a high signal to the arduino. Arduino process the signal and triggers the relay. We can connect any AC or DC load with relay for triggering it ON/OFF based on the input. So if we use the AC load like a bulb, we use the relay. So doing this project we should know, how to use PIR motion sensor with arduino and how to interface relay with arduino. You can refer our tutorial on that.

At the end connect all the modules.

Hardware Required

  • Arduino Uno
  • PIR Motion Sensor
  • Relay 5V
  • NPN Transistor BC548
  • Resistor 1K ohm
  • Breadboard

 

PIR Motion Sensor Light Switch Arduino Connection

5V Relay Arduino Connection with AC Load

This is the reference circuit. Here the relay is connected to digital pin 0. But in this project, we are controlling the relay from the digital pin 7, as the complete circuit is given below.

 

Relay 5V Arduino Connection with AC Load

 

PIR Motion Sensor Light Switch Arduino Connection using 5V Relay

 

PIR Motion Sensor Light Switch Arduino Circuit using 5V Relay

 

Motion Sensor PIR Light Switch Arduino Code

When a movement is detected by the PIR motion sensor light switch. It gives a high signal to the arduino and it turns the 5v relay ON. Here we can connect the relay with alarm or relay with the lights.

/*#####PIR Motion Sensor Light Switch Arduino Project####
Connection:
Relay         - Digital Pin 7
Motion Sensor - Digital Pin 02
And Connect the supply to above module
*/

int relay = 7;
void setup()
{
  pinMode(relay, OUTPUT);    // Relay as output
  digitalWrite(relay, LOW);  //make Relay OFF
  //PIR Motion Sensor connected at digital pin 2 i.e. interrupt 0
  attachInterrupt(0, lightON, RISING); 
}

void loop()
{   

}

void lightON()
{ 
  // Relay ON - Bulb ON  
  digitalWrite(relay, HIGH); 
  for(int i = 0; i <= 3000; i++){ //50 Seconds Aprox. time 
    delay(1000);
  }
  digitalWrite(relay, LOW); 
 }

Leave a Reply

Your email address will not be published. Required fields are marked *