Created by John LeDuc, last modified on Oct 27, 2017
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
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.
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)
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.
Hardware Requirements
This alarm project was created with the following part numbers from Digi-Key:
- 255-3075-ND - PIR motion sensor
- 458-1526-ND - Audio Alarm
- 1528-1093-ND - NEOPIXEL 16 ring shape
- 1528-1297-ND - Gemma - small wearable MCU
- MTP3055VLFS-ND - MOSFET
- L7805CV - 5 Volt regulator
- EG2350-ND - Toggle Switch
- EJ501B-ND - Panel mount 2.5 mm power jack
- 1528-1101-ND - Perf board
- 102-3432-ND - 12 volt wall transformer
- SRW032-WB-ND - Box/ housing for components
- 1N4001 - Diode 50V 1A
- 1.0KQBK-ND - 1K ohm axial leaded resistor
- 10KQBK-ND - 10K ohm axial leaded reistor
- 399-13742-1-ND - 0.33uf ceramic capacitor
- 399-9870-1-ND - 0.1uF ceramic capacitor
- 1528-1743-ND - hookup wire kit
Software Requirements
- Arduino IDE - code for this project is listed below.
Hardware Design
Example Application
#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