Passive Infrared (PIR) Sensor
Highlights
- Powered by the alarms PIR
- No contact with the PIRs actual sense circuits, so no interruptions to the alarm functionality
- Replicates where I initially used an expensive Z-Wave Fibaro Universal Binary Sensor FGBS-001 / FGBS-321
I initially set out to replace the Z-Wave unit with a similar setup. I placed an optocoupler in series with the trip circuit and calculated the various resistances etc to replace one of the standard End Of Line / Tamper resistors. This worked, but I always felt a little funny about modifying a core security feature of the house.
As part of the first build, I also attached the 3.3v Arduino’s RAW pin directly to the power of the PIR. I was positive it was only putting out 12v, but I never measured twice. Needless to say, the smoke was let out. This is why the build image above has a separate 3.3v regulator. The AMS1117-3.3 regulator can handle voltages above the 12v Arduino threshold
In the end, I opted for a simple phototransistor to report back on the status of the PIRs trigger LED. With the exception of power, this has full isolation from the PIRs core security function.
I think this is the sensor code!!! Please double check this one for your fit.
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Simple binary switch example
* Connect button or door/window reed switch between
* digitial I/O pin 3 (BUTTON_PIN below) and GND.
* http://www.mysensors.org/build/binary
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensor.h>
#include <Bounce2.h>
#define MY_NODE_ID 54
#define CHILD_ID1 3
#define CHILD_ID2 4
#define IN_1 3 // Arduino Digital I/O pin for button/reed switch
#define IN_2 4 // Arduino Digital I/O pin for button/reed switch
#define OUT_1 7 // Arduino Digital I/O pin for button/reed switch
#define OUT_2 8 // Arduino Digital I/O pin for button/reed switch
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
int oldValue1=-1;
int oldValue2=-1;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg1(CHILD_ID1,V_TRIPPED);
MyMessage msg2(CHILD_ID2,V_TRIPPED);
void setup()
{
// Setup the pins
pinMode(IN_1,INPUT);
pinMode(IN_2,INPUT);
pinMode(OUT_1,OUTPUT);
pinMode(OUT_2,OUTPUT);
// Activate internal pull-up
digitalWrite(IN_1,HIGH);
digitalWrite(IN_2,HIGH);
// After setting up the button, setup debouncer
debouncer1.attach(IN_1);
debouncer1.interval(5);
debouncer2.attach(IN_2);
debouncer2.interval(5);
}
void presentation() {
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
present(CHILD_ID1, S_DOOR);
present(CHILD_ID2, S_DOOR);
}
// Check if digital input has changed and send in new value
void loop()
{
debouncer1.update();
debouncer2.update();
// Get the update value
int value1 = debouncer1.read();
int value2 = debouncer2.read();
digitalWrite(OUT_1, value1);
digitalWrite(OUT_2, value2);
if (value1 != oldValue1) {
// Send in the new value
send(msg1.set(value1==HIGH ? 1 : 0));
oldValue1 = value1;
}
if (value2 != oldValue2) {
// Send in the new value
send(msg2.set(value2==HIGH ? 1 : 0));
oldValue2 = value2;
}
}