# Alarm Project using PIR Motion Sensor

**URL:** <https://forum.digikey.com/t/alarm-project-using-pir-motion-sensor/13024>\
**Category:** Maker, DIY\
**Tags:** sensors-transducers, maker-diy, automation-and-control, design-tools-and-resources\
**Created:** [March 25, 2021, 6:21pm UTC](https://forum.digikey.com/t/alarm-project-using-pir-motion-sensor/13024 "2021-03-25T18:21:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TechForum](https://avatars.discourse-cdn.com/v4/letter/t/a698b9/32.png) [@TechForum](https://forum.digikey.com/u/TechForum)\
**Post date:** [March 25, 2021, 6:21pm UTC](https://forum.digikey.com/t/alarm-project-using-pir-motion-sensor/13024/1 "2021-03-25T18:21:30Z")

</div>

Created by John LeDuc, last modified on Oct 27, 2017

 ![image](https://global.discourse-cdn.com/digikey/original/2X/0/0e28b645e6f4a1703c527eaa388fd1bce0898056.jpeg)

# Introduction

This page is about using a PIR (Passive Infrared) Motion sensor to trigger an alarm using an Arduino compatible MCU board called- Gemma, created by Adafruit part no.[1528-1297-ND](http://www.digikey.com/products/en?keywords=1528-1297-ND)

PIR sensors are triggered by changes in heat radiated from our bodies or other energy source by comparing the difference between the heat source and surrounding area. An amplifier and ASIC are used in the Panasonic brand to make detection almost like a Schmitt trigger effect and easy to interface to any microcontroller. There is a plastic Fresnel lens on each PIR sensor to enable detection of various zoned areas.

 ![image](https://global.discourse-cdn.com/digikey/original/2X/e/e763bc16663d8774817f481028a80ba386e59c18.jpeg)

The diagram below shows the timing of the PIR sensor from power up where there is a bit of a delay before the sensor stabilizes and is ready for detection (~15 seconds by my testing)

 ![image](https://global.discourse-cdn.com/digikey/original/2X/0/0b0f458c1b295dfb712d87f70af08d25bf8a7786.jpeg)

Circuit operation: When the PIR sensor detects a heat change, the signal pin, rises to a high voltage, when the MCU is polling for a high input, uses the true condition to turn on another pin (D2 below), which turns on the audio alarm (note that the alarm operates off of DC and has it’s own pulsing circuit). At almost the same time, pin D1 brings in a series of pulses (set up by the Adafruit NEOPIXEL include library) to help flash the 16 LEDs red. This creates a loud, irritating and bright flashing red lights- perfect for scaring or alarming someone for a special purpose. [Panasonic PIR Motion Sensors Datasheet Link](https://www3.panasonic.biz/ac/e_download/control/sensor/human/catalog/bltn_eng_papirs.pdf).

# Hardware Requirements

This alarm project was created with the following part numbers from Digi-Key:

- [255-3075-ND](https://www.digikey.com/products/en?keywords=255-3075-ND) - PIR motion sensor
- [458-1526-ND](https://www.digikey.com/products/en?keywords=458-1526-ND) - Audio Alarm
- [1528-1093-ND](https://www.digikey.com/products/en?keywords=1528-1093-ND)- NEOPIXEL 16 ring shape
- [1528-1297-ND](https://www.digikey.com/products/en?keywords=1528-1297-ND) - Gemma - small wearable MCU
- [MTP3055VLFS-ND](https://www.digikey.com/products/en?keywords=MTP3055VLFS-ND) - MOSFET
- [L7805CV](https://www.digikey.com/products/en?keywords=L7805CV) - 5 Volt regulator
- [EG2350-ND](https://www.digikey.com/products/en?keywords=EG2350-ND) - Toggle Switch
- [EJ501B-ND](https://www.digikey.com/products/en?keywords=EJ501B-ND)- Panel mount 2.5 mm power jack
- [1528-1101-ND](https://www.digikey.com/products/en?keywords=1528-1101-ND) - Perf board
- [102-3432-ND](https://www.digikey.com/products/en?keywords=102-3432-ND) - 12 volt wall transformer
- [SRW032-WB-ND](https://www.digikey.com/products/en?keywords=SRW032-WB-ND) - Box/ housing for components
- [1N4001](https://www.digikey.com/products/en?keywords=1N4001) - Diode 50V 1A
- [1.0KQBK-ND](https://www.digikey.com/products/en?keywords=1.0KQBK-ND) - 1K ohm axial leaded resistor
- [10KQBK-ND](https://www.digikey.com/products/en?keywords=10KQBK-ND) - 10K ohm axial leaded reistor
- [399-13742-1-ND](https://www.digikey.com/products/en?keywords=399-13742-1-ND) - 0.33uf ceramic capacitor
- [399-9870-1-ND](https://www.digikey.com/products/en?keywords=399-9870-1-ND) - 0.1uF ceramic capacitor
- [1528-1743-ND](https://www.digikey.com/products/en?keywords=1528-1743-ND) - hookup wire kit

 ![image](https://global.discourse-cdn.com/digikey/original/2X/2/29128ac20677177363efacb7ab8e891d0cbbf931.jpeg)

# Software Requirements

- [Arduino IDE](https://www.arduino.cc/en/Main/Software) - code for this project is listed below.

# Hardware Design

[Schematic drawn in Scheme-it](https://www.digikey.com/schemeit/project/haunted-woods-alarm-9V8LMJG30250/)

[![](https://global.discourse-cdn.com/digikey/original/2X/9/918a5b2a49ef63ac94a0ec30ac3fbbda63a39bff.jpeg)](https://www.digikey.com/schemeit/project/haunted-woods-alarm-9V8LMJG30250/)

# Example Application

```auto
#include < Adafruit_NeoPixel.h >
 
// Note 1 = pin one on Gemma
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, 1, NEO_GRB + NEO_KHZ800);
 
int Pin2 = 2;
int Pin0 = 0;
 
void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
 
  strip.setPixelColor(3, 0, 0, 127); // set color to blue
  strip.setBrightness(255); // setting brightness for Neopixel to high
 
  pinMode(Pin2, OUTPUT); // output for audio alarm
  pinMode(Pin0, INPUT); // for receiving the signal from the PIR sensor
}
  
void loop() {
 
  int z = 0;
 
  if (digitalRead(Pin0 == HIGH)) // if receives a logic one (high) then process next set of instructions
  {
    digitalWrite(Pin2, HIGH); // turn on alarm (...energize the MOSFET gate)
 
    for (int i = 0; i < 16; i++) // for turning on each Neopixel
 
    {
      strip.setPixelColor(i, 255, 0, 0); // set color to red
      strip.show();
      delay(100);
      z = 20000;
    }
 
    for (int i = 0; i < 16; i++) {
      strip.setPixelColor(i, 0, 0, 0); // turn off Neopixels
      strip.show();
    }
  }
  digitalWrite(Pin2, LOW); // turn off alarm (...turning off MOSFET)           
  delay(z); // long delay to wait for the crowd to pass
}

```

# Comments

Any questions or comments please go to our TechForum: [TechForum](https://forum.digikey.com/c/eewiki/microcontroller/67)
