Passive Infrared (PIR) Sensor

Tapping into a PIR Sensor


  • 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 <>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list:
 * Documentation:
 * Support Forum:
 * 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.
 * Simple binary switch example 
 * Connect button or door/window reed switch between 
 * digitial I/O pin 3 (BUTTON_PIN below) and GND.

// 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


  // Activate internal pull-up
  // After setting up the button, setup debouncer


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() 
  // Get the update value
  int value1 =;
  int value2 =;

  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;
Last modified April 10, 2023: more content (59f5057)