• Support
  • Cart
Warefab Warefab
  • Shop
    • Makers
      • Boards
      • Displays
      • Sensors
      • Prototyping
      • Actuators
      • Power Supply
    • Educators
    • IoT & Wireless
      • GSM
      • WiFi
      • Bluetooth
      • Radio
      • LoRa
      • Sensors
    • Parts Library
    • Tools
  • Fab Space
    • Laser Cutting & Engraving
    • 3D Printing
    • CNC Milling & Drilling
    • PCBA, CAD and Firmware
    • Co-Working Space
    • Training
  • IoT
  • STEM
  • Learn
    • Getting Started
      • Basics
      • Scratch-n-Sketch
    • Explore
      • Actuators
      • Arduino
      • Modules
      • Displays
      • Microcontrollers
      • Robotics
      • Sensors
    • Basic Electronics
      • Discrete Components
      • Intergrated Circuits
      • Power Supplies
  • Register
  • Login|
LoginRegister
­
Learn/Explore/PIR Motion Sensor

Close

PIR Motion Sensor

By Muchiri John

Share this project

Introduction

A PIR motion sensor, is a small, low power and inexpensive sensor that is used to sense objects emitting low level radiation e.g humans, cats, dogs, etc. Mostly these sensors are used in motion detecting devices e.g motion activated lamps.

PIRs or referred to as PIR, “Passive Infrared”, “Pyroelectric”, or “IR motion” sensors, are easy to interface with, that is, if it detects something the output goes High else its always LOW.

PIRs have simple circuit made up of capacitors, resistors, voltage regulator(3.3V) and a BISS0001 chip that does all the processing. For settings, the sensor has two variable resistors to set sensitivity and delay time. Also there is a retrigger setting jumper.

Top View, Fresnel Lenses

PIR Motion Sensor

Circuitry

PIR Motion Sensor

Parts Used

We’ll learn how to interface PIR sensor with an Arduino Uno. Here is the part list we’ll need.

– PIR Motion Sensor
– Arduino Uno
– Jumper pack
– Mini Breadboard

Wiring

– Connect PIR motion Sensor Signal pin to Arduino digital pin 7
– Connect positive lead of the LED to Arduino digital pin 6
– Connect both LED and PIR sensor ground pins to Arduino ground pin
– Connect both LED and PIR sensor VCC pins to Arduino +5V pin

Breadboard Connections

PIR Motion Sensor

Arduino Wiring

PIR Motion Sensor

Code

Arduino code, PIR_Motion_Sensor.ino

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* connections
* pir -- 7
* led -- 6
* vcc -- +5v
* gnd -- gnd
*
*/
 
#define On 1 //led on value
#define Off 0 //led off value
#define pir_pin  7 //PIR sensor input pin
#define led_pin 6 //led output pin
 
//setup
void setup() {
  //set PIR pin as input
  pinMode(pir_pin, INPUT);
  //set led pin as ouput
  pinMode(led_pin, OUTPUT);
}
 
//loop
void loop() {
  if(motionDetected()){
    setLed(On);
  }else{
    setLed(Off);
  }
  delay(250);
}
 
//change led
void setLed(uint8_t status){
  if(status)
  {
    digitalWrite(led_pin, HIGH); //set LED on
  }else{
    digitalWrite(led_pin, LOW); //set LED off
  }
}
 
//Check if there is motion
uint8_t motionDetected()
{
  //read sensor ouput value
  if(digitalRead(pir_pin) == 1)
  {
    return true; //if person detected return true
  }else
  {
    return false;  //if no person detected return false
  }
}

How the Code works

in the macro definitions, we define all the pins, PIR connected to pin 7 and LED to pin 6 on the Arduino.

C++
1
2
#define pir_pin  7
#define led_pin 6

Then we have two functions, ‘setLed’ and ‘motionDetected’. The ‘setLed’ method takes a parameter that defines whether to turn the On/Off the LED.

C++
1
void setLed(uint8_t status)

The ‘motionDetected’ function reads the PIR sensor output and returns a HIGH or LOW

C++
1
uint8_t motionDetected()

The two methods are then used in the loop function where we continously check if the sensor is triggered (using motionDetected() method), if there is a person the LED goes on else its off.

C++
1
2
3
4
5
if(motionDetected()){
  setLed(On);
}else{
  setLed(Off);
}

finally we give our program a delay of 250 milliseconds between sensor reads

C++
1
delay(250);

Running the code

Click ‘Run on Arduino’ to upload code to your Arduino board.

Resources

– BISS0001 Datasheet
– Fritzing Wiring
– PIR_Motion_Sensor.ino

Share this post

Like this project

Tags

accelerometer Arduino breadboard buzzer color sensor jumper jumpers jumper wires kit learn led PIR programming prototyping scratch-n-sketch Scratch_n_Sketch sensors tcs3200 touch

Feedback is closed.


Related Projects

  • MMA7361LC 3-Axis Accelerometer


    By Muchiri John

    This Module is a 3-axis Xyz accelerometer using Freescale MMA7361L micromachined ±1.5g or ±6g sensitivity. It's great for a motion sensing or stab...

  • tcs3200_cl_02

    Color Sensor TCS3200


    By Muchiri John

    This module is based on TCS3200 programmable color light-to-frequency converters that combine configurable silicon photodiodes and a current-to-fre...

  • touch_sensor

    Touch Sensor


    By Dennis

    If you are interested in adding the ‘magic’ of touch to control your electronics project, a capacitive touch sensor module might be the way to go. ...

  • ard_piezo_image

    Piezo Buzzer


    By Dennis

    This tutorial shows how to hook up a piezo buzzer and an Arduino Uno board to make a simple sound alarm whose volume can be adjusted . The buzzer i...

  • Arduino_Logo

    Arduino : Getting Started


    By Mercy Ngoiri

    In this lesson we will learn how to set up the computer to get started with Arduino, that is, downloading and installing the software and then open...

  • Arduino_Logo

    Arduino : Introduction


    By Muchiri John

    Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sens...

Sections

  • Introduction
  • Parts Used
  • Wiring
  • Code
  • Resources
Paginate View
PDF / Print
Feedback

Components Used

  • mk04

    Adjust IR PIR motion sensors

    Ksh. 200.00
    PIR sensors allow you to sense motion.They are mostly used to detect…
    Add to cartLearn More

Get Updates

Customer Service

  • Contact Page
  • Support
  • Distributors
  • FAQ Page

Terms of Use

  • Shipping & Returns
  • Terms of Service

About Us

Electronics Kits, Modules, PCBA, CNC milling, 3D Printing, Coding, Laser Cutting, Training, Fun and many more