2 pir sensor >> 2x interrupt on arduino pro mini

I want to make a portable pir (2x) sensor connected to arduino pro mini and than transmit some data ( via 433mhz transmitter ) to another arduino. To save power I would like to make arduino sleep and only be waken up by pir. The problem is I can’t make the code to work with two pirs on two interrupts. I was able to make it work with one pir. So my question is if it is doable (2 pirs on 2 interrupts) or if not can I combine data-output from both pirs to one interrupt?

My not working code:

#include <VirtualWire.h>
#include <avr/sleep.h>

//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 10;        

int pirPin1 = 2;    //the digital pin connected to the PIR sensor's output
int pirPin2 = 3;    //the digital pin connected to the PIR sensor's output

int ledPin = 13;
int transmit_pin = 4;

int t = 1;


int pow1 = 7;   //pir 1 power / just temporary
int pow2 = 8;   //pir 2 power / just temporary
int pow3 = 9;   //trans power / just temporary

boolean unique = false;
boolean ready_to_sleep = false;
char msg[6] = {'s','1','A','C','T','V'};
int fired_by_sensor = 0;

void setup() {
pinMode(pow1, OUTPUT);
pinMode(pow2, OUTPUT);
pinMode(pow3, OUTPUT);


digitalWrite(pow1, HIGH);
digitalWrite(pow2, HIGH);
digitalWrite(pow3, HIGH);



  
pinMode(ledPin, OUTPUT);
pinMode(pirPin1, INPUT);
pinMode(pirPin2, INPUT);

digitalWrite(pirPin1, LOW);
digitalWrite(pirPin2, LOW);

//pinMode(transmit_pin, OUTPUT);


digitalWrite(ledPin, LOW);
Serial.begin(9600);
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000);   // Bits per sec

//give the sensor some time to calibrate
Serial.print("Calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" Calibration Done!");
vw_send((uint8_t *)msg, 6);
vw_wait_tx(); // Wait until the whole message is gone     
delay(50);
sleepNow();
}

void loop() {
if(unique == true){
char msg[6] = {'x','s','0','t','m','#'};
msg[5] = fired_by_sensor;
msg[5] = t;
vw_send((uint8_t *)msg, 6);
vw_wait_tx(); // Wait until the whole message is gone
delay(50);
unique = false;
}



Serial.println(ready_to_sleep);
Serial.println(digitalRead(pirPin1));
if ( (ready_to_sleep == true) && (digitalRead(pirPin1) == LOW) ){
  Serial.println("Sleep now fired from loop.");
  sleepNow();
  }
delay (1000);

Serial.println("Loop.");
}


void pir1() {

Serial.begin(9600);
Serial.println(" ");
Serial.print("Motion detected: Sensor 1x");
Serial.println(t);
digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state

t++;
unique = true;
fired_by_sensor = 1;
ready_to_sleep = true;
}

void pir2() {
Serial.begin(9600);
Serial.println(" ");
Serial.print("Motion detected: Sensor 2x");
Serial.println(t);
digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state

t++;
unique = true;
fired_by_sensor = 2;
ready_to_sleep = true;
}


void sleepNow()         // here we put the arduino to sleep
{
Serial.println("Going to sleep!");
for(int i = 0; i < 3; i++){
Serial.print(".");
delay(1000);
}
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here

    sleep_enable();          // enables the sleep bit in the mcucr register
                             // so sleep is possible. just a safety pin

    attachInterrupt(digitalPinToInterrupt(pirPin1), pir1, RISING);
    attachInterrupt(digitalPinToInterrupt(pirPin2), pir2, RISING);

    sleep_mode();            // here the device is actually put to sleep!!
                             // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP

    sleep_disable();         // first thing after waking from sleep:
                             // disable sleep...
detachInterrupt(digitalPinToInterrupt(pirPin1));
detachInterrupt(digitalPinToInterrupt(pirPin2));     // disables interrupt 0 on pin 2 so the
                             // wakeUpNow code will not be executed
                             // during normal running time.

}

Components used:
Arduino pro mini
2x pir
433mhz transmitter + receiver
power source is cheap power bank…

And I am new to C/C++ programing…

If you don’t need to know which PIR was triggered, it’s easy to connect two PIR detectors to one interrupt pin, using a wired diode OR configuration.

This assumes that your PIR detectors go high when triggered:-
Diode OR.JPG

That will work on a 3.3volt ProMini, but not on a 5volt ProMini. A 5volt Arduino needs 3volt (VCC * 0.6) for a digital pin to register HIGH. 3.3volt from a PIR sensor is just ok. A diode drop less is probably not. A solution could be a transistor based OR, or an opto coupler OR. Leo..

Edit. A common/cheap PIR has current limited outputs, so two can be joined/connected directly to the base of an NPN transistor. Emitter to ground, collector to the Arduino pin. Internal pullup resistor enabled.

Wawa: That will work on a 3.3volt ProMini, but not on a 5volt ProMini. A 5volt Arduino needs 3volt (VCC * 0.6) for a digital pin to register HIGH. 3.3volt from a PIR sensor is just ok. A diode drop less is probably not. A solution could be a transistor based OR, or an opto coupler OR. Leo..

Thank you both for reply. But these components sound a little to complicated for me... If I would wire them without diode will they (pirs) get damaged or stop working correctly?

Or does somebody have some sample code where both (two) interrupts are used?....

Wawa: That will work on a 3.3volt ProMini, but not on a 5volt ProMini. A 5volt Arduino needs 3volt (VCC * 0.6) for a digital pin to register HIGH. 3.3volt from a PIR sensor is just ok. A diode drop less is probably not. A solution could be a transistor based OR, or an opto coupler OR. Leo..

Edit. A common/cheap PIR has current limited outputs, so two can be joined/connected directly to the base of an NPN transistor. Emitter to ground, collector to the Arduino pin. Internal pullup resistor enabled.

Good point. I forgot that the most common PIR detectors only have 3.3V output. It's been quite a while since I used one. A transistor is probably the best/simplest option, assuming the outputs are current limited. (I didn't know that, and probably would have used two diodes and a transistor.)

@JohnnSy, if you just connect the two PIR outputs together, when one is high and the other is low, only 1.6V will probably be presented to the Arduino interrupt pin, (assuming the PIR has a push-pull output). You can't get any simpler than a transistor, or the two diode method if your Pro Mini is the 3.3V version. To design circuits using Arduinos, you need to learn at least a minimal amount of electronic design, or you won't get very far.

OldSteve: A common/cheap PIR has current limited outputs, so two can be joined/connected directly to the base of an NPN transistor. Emitter to ground, collector to the Arduino pin. Internal pullup resistor enabled.

This seems doable and easy. I will try this. Thank you.

This is kind of hobby project... The arduino is 5v version

JohnnSy: ...assuming the outputs are current limited.

The PIR sensors I have dissected had a 1k5 (or 1k8) resistor between chip and output. The chip was powered by an onboard 3.3volt regulator. If one PIR is active, the base of the adding transistor would receive ((3.3-0.6)/1500)-(0.6/1500)= 1.4mA. Leo..

Wawa: The PIR sensors I have dissected had a 1k5 (or 1k8) resistor between chip and output. The chip was powered by an onboard 3.3volt regulator. If one PIR is active, the base of the adding transistor would receive ((3.3-0.6)/1500)-(0.6/1500)= 1.4mA. Leo..

Thanks. I haven't dissected one, (can barely even see SMD components), just used them.

|500x236

Paul__B: |500x236

Thank you, but this is too advanced...

i just wanna make two pir sensors to work with arduino pro mini ( ideally waking up from sleep using two interrupts ). It would be great if someone have same generic code where both interrupts are used (pin2,3). If I can not use both interrupts than I will try to combine outputs to one interrupt.