thanks @fets have I specified the wait time at the wrong location? In the sketch below, everything works, BUT the PIR triggers 0 over and over and over again.....
#define MY_GW_ID 50
// Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
#include <Bounce2.h>
//Constants
#define SKETCH_NAME "3 in 1 Sensor"
#define SKETCH_VERSION "1.0"
#define CHILD_ID_TEMP 11 // Child id for Temperature
#define CHILD_ID_HUM 10 // Child id for Humidity
#define CHILD_ID_MOT 2 // Child id for Motion
#define HUMIDITY_SENSOR_DIGITAL_PIN 7 // Where is my DHT22 data pin connected to
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define CHILD_ID_SW 3 // Child id for Reed Switch
#define BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch
#define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
int node_id=50; // What is my node id
MySensor gw;
Bounce debouncer = Bounce();
int oldValue=-1;
DHT dht;
//Store last values
float lastTemp = 0 ;
float lastHum = 0 ;
;
boolean lastTripped = false ;
boolean metric = true;
boolean gwsend = true; // to determine if data has to be sent
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
MyMessage msgsw(CHILD_ID_SW,V_TRIPPED);
void setup()
{
gw.begin(NULL,node_id,false);
gw.wait(5);
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("3 in 1 Sensor", "1.0",true);
// - NEW Setup the button
pinMode(BUTTON_PIN,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);
// After setting up the button, setup debouncer
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
// - NEW Setup the button END
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_HUM, S_HUM,"Garage Humidity");
gw.present(CHILD_ID_TEMP, S_TEMP,"Garage Temperature");
gw.present(CHILD_ID_SW, S_DOOR,"Garage Door");
metric = gw.getConfig().isMetric;
}
void loop()
// Read Reed switch value
{
debouncer.update();
// Get the update value
int value = debouncer.read();
if (value != oldValue) {
// Send in the new value
gw.send(msgsw.set(value==HIGH ? 1 : 0));
oldValue = value;
}
// Read Temp - Humidity Value
{
delay(dht.getMinimumSamplingPeriod());
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT");
} else if (temperature != lastTemp) {
lastTemp = temperature;
if (!metric) {
temperature = dht.toFahrenheit(temperature);
}
gw.send(msgTemp.set(temperature, 1));
Serial.print("T: ");
Serial.println(temperature);
}
float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT");
} else if (humidity != lastHum) {
lastHum = humidity;
gw.send(msgHum.set(humidity, 1));
Serial.print("H: ");
Serial.println(humidity);
}
{
// Read digital motion PIR value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
Serial.println(tripped);
gw.send(msgMot.set(tripped?"1":"0")); // Send tripped value to gw
}
}
}
Thanks