Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

PIR Motion Sensor

Available Languages
Picture
Picture

Introduction 

Picture
In this tutorial we will show you how to use the PIR Motion Sensor with the Arduino UNO board. PIR sensors are used to detect motion from pets or human from about 6 meters away. 

​

So let's see how it works!


What you will need - Hardware


​For this tutorial you will need:
  • Arduino uno
  • PIR motion sensor​
  • Some male to female breadboard cables

The Circuit

Picture
The connections are easy, see the image above with breadboard circuit schematic.
  • Vcc  pin to Arduino 5V Pin
  • GND   pin to Arduino GND
  • Out pin to Arduino 2 Pin

The code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * PIR sensor tester
 */
 
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 status
 
void setup() {
  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
    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 {
    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;
    }
  }
}
Download the code from here and open it with Arduino IDE.
pir_sensor.zip
File Size: 0 kb
File Type: zip
Download File

Serial Monitor

Picture

Well done!

You have successfully completed one more Arduino "How to use the PIR Motion Sensor "

I hope you liked this, let me know in the comments.
Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates