Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
50 min
Share

Detect motion using PIR sensor

It is possible to have a guard at the entrance to your house to keep it safe, but this will cost you a lot of money! The best solution to this problem is to use a motion sensor called a PIR sensor. This sensor can easily detect when someone moves in front of it.

Project Video

Overview

In this tutorial, we will use the PIR sensor to send a message to your computer when someone enters your house.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
PIR Motion Sensor
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the PIR motion sensor and the Arduino, as shown in the image below.

 Connections from the Arduino to the PIR sensor:


      • Arduino GND pin → PIR sensor GND pin (- pin)


      • Arduino pin 2 → PIR sensor out pin


      • Arduino VCC pin → PIR sensor VCC pin (+ pin)

Coding


/*
 Voltaat learn (https://www.voltaat.com)
 Link for full tutorial:
 Link for libraries: There is no need for libraries

 PIR sensor alerts you when someone enters your house

 The function of this code is to obtain the reading from the PIR sensor via the Arduino input pin.
 If it is high, this means there is someone in your house.
 In this case the Arduino will send a message to the computer warning that someone has entered your home.

 Connections from the Arduino to the PIR sensor:
 • Arduino GND pin → PIR sensor GND pin (- pin)
 • Arduino pin 2 → PIR sensor out pin
 • Arduino VCC pin → PIR sensor VCC pin (+ pin)

*/

//Define the variable pirSensor to digital Pin 2
int pirSensor = 2;

//Define the variable pirSensorRead and initialize its value to 0
int pirSensorRead = 0;

//Commands inside void setup run once
void setup() {

 //Start the serial monitor at 9600 baud rate (9600 bits per second)
 Serial.begin(9600);

 //pirSensor is defined as an input
 pinMode(pirSensor, INPUT);

}

// Commands inside void loop run forever
void loop()
{
 // Read the value of digital output from rainSensor and assign it in the variable pirSensorRead
 pirSensorRead = digitalRead(pirSensor);


 if (pirSensorRead == HIGH)
 {
   //Print to serial monitor
   Serial.println("Security Alarm, There is someone in your house!");
   //Delay for 5 seconds
   delay(5000);
 }

}

Testing it Out

You should also make sure you have chosen the right baud rate (9600) as specified in the code.
know when your plant needs watering

Now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.

know when your plant needs watering

Now, as we see in the following image, the serial monitor displays the security alert because the sensor was triggered, which means there is someone at your house!

know when your plant needs watering

Resources

No items found.