Relay is working correctly, checked with multimeter. Now i'm study about debugging.
Below is the code i'm using (4 PIRs).
Problem with sleep mode?
// Enable debug prints
// #define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensors.h>
#define MY_NODE_ID AUTO
unsigned long SLEEP_TIME = 5000 ; // 120000 Sleep time between reports (in milliseconds)
#define DIGITAL_INPUT_SENSOR1 2 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define DIGITAL_INPUT_SENSOR2 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define DIGITAL_INPUT_SENSOR3 4 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define DIGITAL_INPUT_SENSOR4 5 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define CHILD_ID_PIR1 21 // Id of the sensor child
#define CHILD_ID_PIR2 22 // Id of the sensor child
#define CHILD_ID_PIR3 23 // Id of the sensor child
#define CHILD_ID_PIR4 24 // Id of the sensor child
// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE
// Initialize motion message
MyMessage msg1(CHILD_ID_PIR1, V_TRIPPED);
MyMessage msg2(CHILD_ID_PIR2, V_TRIPPED);
MyMessage msg3(CHILD_ID_PIR3, V_TRIPPED);
MyMessage msg4(CHILD_ID_PIR4, V_TRIPPED);
void setup()
{
pinMode(DIGITAL_INPUT_SENSOR1, INPUT); // sets the motion sensor digital pin as input
pinMode(DIGITAL_INPUT_SENSOR2, INPUT); // sets the motion sensor digital pin as input
pinMode(DIGITAL_INPUT_SENSOR3, INPUT); // sets the motion sensor digital pin as input
pinMode(DIGITAL_INPUT_SENSOR4, INPUT); // sets the motion sensor digital pin as input
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("PIR Sensor", "0.1");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_PIR1, S_MOTION);
present(CHILD_ID_PIR2, S_MOTION);
present(CHILD_ID_PIR3, S_MOTION);
present(CHILD_ID_PIR4, S_MOTION);
}
void loop()
{
// Read digital motion value (PIR1)
bool tripped1 = digitalRead(DIGITAL_INPUT_SENSOR1) == HIGH;
if(digitalRead(DIGITAL_INPUT_SENSOR1) == HIGH)
tripped1 = true;
else
tripped1 = false;
// Read digital motion value (PIR2)
bool tripped2 = digitalRead(DIGITAL_INPUT_SENSOR2) == HIGH;
if(digitalRead(DIGITAL_INPUT_SENSOR2) == HIGH)
tripped2 = true;
else
tripped2 = false;
// Read digital motion value (PIR3)
bool tripped3 = digitalRead(DIGITAL_INPUT_SENSOR3) == HIGH;
if(digitalRead(DIGITAL_INPUT_SENSOR3) == HIGH)
tripped3 = true;
else
tripped3 = false;
// Read digital motion value (PIR4)
bool tripped4 = digitalRead(DIGITAL_INPUT_SENSOR4) == HIGH;
if(digitalRead(DIGITAL_INPUT_SENSOR4) == HIGH)
tripped4 = true;
else
tripped4 = false;
Serial.println(tripped1);
send(msg1.set(tripped1?"1":"0")); // Send tripped value to gw
Serial.println(tripped2);
send(msg2.set(tripped2?"1":"0")); // Send tripped value to gw
Serial.println(tripped3);
send(msg3.set(tripped3?"1":"0")); // Send tripped value to gw
Serial.println(tripped4);
send(msg4.set(tripped4?"1":"0")); // Send tripped value to gw
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR1), CHANGE, SLEEP_TIME);
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR2), CHANGE, SLEEP_TIME);
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR3), CHANGE, SLEEP_TIME);
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR4), CHANGE, SLEEP_TIME);
}