PIR Motion Detection System Using Arduino
DIY Projects.
“You can’t use up creativity. The more you use, the more you have”
I got to know how electronics can really be fun to explore with, play with and learn new things with it.
This DIY contains how the components used works and how you can do it with the guidelines as mentioned.
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
What is PIR?
PIR (Passive InfraRed sensor): Everything we see in this universe emits some kind of radiation. Some emit low level radiation, some emit high level radiations. Radiations are mainly due to the temperature of the substance. The hotter it gets, more the radiation it emits.
This sensor detects the change in heat, or to be precise, it can detect Infrared rays.
What is Arduino?
Arduino is a company which makes user friendly microcontroller boards. It’s an open-source electronics platform. You can interact with the Arduino board by using the Arduino IDE. Check out their website www.arduino.cc
This is a great way to learn the basics of using digital input (from the sensor) and output on your Arduino.
This alarm is handy for booby traps and practical jokes, and it’s just what you’ll need to detect a zombie invasion. The whole project is built on a breadboard, so no soldering will be required!
Step 1: Gather your parts.
1. Arduino board / NodeMCU(or any clone).
2. PIR sensor.
3. Solderless boards (bread board).
4. Wires.
5. Buzzer or led.
Step 2: Wire the Arduino to the breadboard.
- Connect digital IO pin (pin 2) one of the rows of the breadboard (purple wire).
- Connect the 5V pin (red wire) on the Arduino to another row on the breadboard and connect a nearby [GND] ground (black wire) pin to another row.
Connections:
Step 3: Connect your motion sensor (PIR)
- Find the Gnd (–), Vcc (+), and Out pins on the PIR sensor.
- Plug the PIR sensor into the breadboard so that its (–) pin connects to the Gnd row, its (+) pin connects to 5V, and it's Out pin connects to digital pin 2.
NOTE: If you have a different sensor than the one shown here, you may need to extend the sensor’s pins with a female header to fit.
Step 4: Plug in the LED.
- Plug the LED’s positive pin or the anode (the longer leg) into digital pin 13 on the Arduino.
- Plug the LED’s cathode or the negative leg (the shorter leg) into the adjacent ground (GND) pin on the Arduino.
Step 5: Program the Arduino.
- Launch the Arduino IDE software. You can download it for free here. Check for the latest version.
- Plug the USB cable into your computer and Arduino.
- Set the board and port settings for your Arduino board, in this case, an Arduino Uno.
- Upload the sketch to the Arduino.
- Upload the below code into your Arduino IDE and configure your board setting and port settings
//The code starts here
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin statusvoid setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}void loop()
{
val = digitalRead(inputPin); // read input value
if (val == HIGH)
{ // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW)
{
// we have just turned on
Serial.println(“Motion detected!”);
// We only want to print on the output change, not state
pirState = HIGH;
}
} else
{
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println(“Motion ended!”);
// We only want to print on the output change, not state
pirState = LOW;
}
}
}//The code ends here
Note: For the ease of understanding: The code contains only LED part. Buzzer part will be added if requested.
Step 7: Test your Project.
- Now evaluate it by moving: the LED will light up.
- Be amazed! Your PIR Sensor can sense movement up to twenty feet away. No one will be stealing at your home today.
- NOTE: Might not be reliable for detecting the undead ;)