Multisensor PIR problem [solved]
-
So PIR must connect on PIN 1 and not PIN 3.
Edit: Better, how did you connect DHT and PIR?
-
So PIR must connect on PIN 1 and not PIN 3.
Edit: Better, how did you connect DHT and PIR?
@rvendrame The DHT is on pin 2 and the pir on pin 3. i use the MYS PCB.
i suspect the delay function disturb the sleep function. if i dont use the delay, the dht cant "heat up".
far as I know the interrupt is only an internal value. right?
-
Yes, it looks fine. What exactly error are you having? From your first serial monitor, it looks like your sensor woke on every 10min aprox, ( 6608 / 11148 / 15441 ).
-
Yes, it looks fine. What exactly error are you having? From your first serial monitor, it looks like your sensor woke on every 10min aprox, ( 6608 / 11148 / 15441 ).
@rvendrame
if i use this:#include <MySensor.h> #include <readVcc.h> #include <SPI.h> #include <DHT.h> #define NODE_ID 10 // ID of node unsigned long SLEEP_TIME = 600000; // Sleep time between reports (in milliseconds) #define CHILD_ID_PIR 1 // Id of the sensor PIR #define CHILD_ID_HUM 2 // Id of the sensor HUM #define CHILD_ID_TEMP 3 // Id of the sensor TEMP #define CHILD_ID_LIGHT 4 // Id of the sensor LIGHT #define PIR_SENSOR_DIGITAL 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define INTERRUPT PIR_SENSOR_DIGITAL-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define HUMIDITY_SENSOR_DIGITAL_PIN 2 #define LIGHT_SENSOR_ANALOG_PIN 0 MySensor gw; // Initialize Variables MyMessage msgPir(CHILD_ID_PIR, V_TRIPPED); MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL); DHT dht; float lastTemp; float lastHum; boolean metric = true; int oldBatteryPcnt; int lastLightLevel; int MIN_V = 2700; // empty voltage (0%) int MAX_V = 3200; // full voltage (100%) void setup() { gw.begin(NULL, NODE_ID, false); //PIR // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor", "1.0"); pinMode(PIR_SENSOR_DIGITAL, INPUT); // sets the motion sensor digital pin as input digitalWrite(PIR_SENSOR_DIGITAL, HIGH); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_PIR, S_MOTION); //DHT dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Humidity", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); metric = gw.getConfig().isMetric; //LIGHT // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Light Sensor", "1.0"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { // Measure battery float batteryV = readVcc(); int batteryPcnt = (((batteryV - MIN_V) / (MAX_V - MIN_V)) * 100 ); if (batteryPcnt > 100) { batteryPcnt = 100; } if (batteryPcnt != oldBatteryPcnt) { gw.sendBatteryLevel(batteryPcnt); // Send battery percentage oldBatteryPcnt = batteryPcnt; } Serial.print("---------- Battery: "); Serial.println(batteryPcnt); // Read digital motion value boolean tripped = digitalRead(PIR_SENSOR_DIGITAL) == HIGH; Serial.print("---------- PIR: "); Serial.println(tripped); gw.send(msgPir.set(tripped ? "1" : "0")); // Send tripped value to gw //DHT //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("---------- Temp: "); 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("---------- Humidity: "); Serial.println(humidity); } // Light int lightLevel = (1023 - analogRead(LIGHT_SENSOR_ANALOG_PIN)) / 10.23; //Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msgLight.set(lightLevel)); lastLightLevel = lightLevel; Serial.print("---------- Light: "); Serial.println(lightLevel); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME); }i get this output after starting:
sensor started, id 10
send: 10-10-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
read: 0-0-10 s=255,c=3,t=6,pt=0,l=1:M
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=13,st=ok:Motion Sensor
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=1,c=0,t=1,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=8,st=ok:Humidity
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=2,c=0,t=7,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=3,c=0,t=6,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Light Sensor
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=4,c=0,t=16,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=0,pt=1,l=1,st=ok:100
---------- Battery: 100
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
send: 10-10-0-0 s=3,c=1,t=0,pt=7,l=5,st=ok:16.6
---------- Temp: 16.60
send: 10-10-0-0 s=2,c=1,t=1,pt=7,l=5,st=ok:43.8
---------- Humidity: 43.80
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:39
---------- Light: 39
---------- Battery: 100
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:37
---------- Light: 37
---------- Battery: 100
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:34
---------- Light: 34
---------- Battery: 100
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:36
---------- Light: 36
---------- Battery: 100
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:37
---------- Light: 37
---------- Battery: 100
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:38
---------- Light: 38The DHT gives only output the first start and the pir interrupt works perfect.
When delay(dht.getMinimumSamplingPeriod()); is activated the DHT works and the pit interrupts the whole time :(
In this configuration the arduino never sleeps ..sensor started, id 10
send: 10-10-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
read: 0-0-10 s=255,c=3,t=6,pt=0,l=1:M
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=13,st=ok:Motion Sensor
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=1,c=0,t=1,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=8,st=ok:Humidity
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=2,c=0,t=7,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=3,c=0,t=6,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Light Sensor
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=4,c=0,t=16,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=0,pt=1,l=1,st=ok:100
---------- Battery: 100
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
send: 10-10-0-0 s=3,c=1,t=0,pt=7,l=5,st=ok:16.5
---------- Temp: 16.50
send: 10-10-0-0 s=2,c=1,t=1,pt=7,l=5,st=ok:43.9
---------- Humidity: 43.90
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:38
---------- Light: 38
---------- Battery: 100
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
send: 10-10-0-0 s=3,c=1,t=0,pt=7,l=5,st=ok:16.6
---------- Temp: 16.60
send: 10-10-0-0 s=2,c=1,t=1,pt=7,l=5,st=ok:43.8
---------- Humidity: 43.80
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:37
---------- Light: 37
---------- Battery: 100
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
send: 10-10-0-0 s=3,c=1,t=0,pt=7,l=5,st=ok:16.5
---------- Temp: 16.50
---------- Battery: 100
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- Battery: 100
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
send: 10-10-0-0 s=4,c=1,t=23,pt=2,l=2,st=ok:38EDIT: i have changed the sleeptime for testing to a shorter time
-
So PIR must connect on PIN 1 and not PIN 3.
Edit: Better, how did you connect DHT and PIR?
@rvendrame When the PIR is connected to PIN3 the interrupt is INT1. Pin 1 does not have an interrupt.
Only pin 2 and pin 3 have an interrupt.
Pin 2 = int0
pin 3 = int1
-
if you put the delay() inside that 'if ( mills() > mytime ) ' , what happens?
-
@rvendrame When the PIR is connected to PIN3 the interrupt is INT1. Pin 1 does not have an interrupt.
Only pin 2 and pin 3 have an interrupt.
Pin 2 = int0
pin 3 = int1
-
@rvendrame
i have posted it before this post:"What is this number? Did you print the milis()?
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=fail:0
6608 <<<<<<"in the posted sketch the delay is inside millis
-
I didn't find the if ( millis() > my time) in the last sketch you posted ...
-
if i use this
#include <MySensor.h> #include <readVcc.h> #include <SPI.h> #include <DHT.h> #define NODE_ID 10 // ID of node unsigned long SLEEP_TIME = 10000; // Sleep time between reports (in milliseconds) #define CHILD_ID_PIR 1 // Id of the sensor PIR #define CHILD_ID_HUM 2 // Id of the sensor HUM #define CHILD_ID_TEMP 3 // Id of the sensor TEMP #define CHILD_ID_LIGHT 4 // Id of the sensor LIGHT #define PIR_SENSOR_DIGITAL 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define INTERRUPT PIR_SENSOR_DIGITAL-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define HUMIDITY_SENSOR_DIGITAL_PIN 2 #define LIGHT_SENSOR_ANALOG_PIN 0 MySensor gw; // Initialize Variables MyMessage msgPir(CHILD_ID_PIR, V_TRIPPED); MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL); DHT dht; float lastTemp; float lastHum; boolean metric = true; int oldBatteryPcnt; int lastLightLevel; long mytime = 0; int MIN_V = 2700; // empty voltage (0%) int MAX_V = 3200; // full voltage (100%) void setup() { gw.begin(NULL, NODE_ID, false); //PIR // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor", "1.0"); pinMode(PIR_SENSOR_DIGITAL, INPUT); // sets the motion sensor digital pin as input digitalWrite(PIR_SENSOR_DIGITAL, HIGH); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_PIR, S_MOTION); //DHT dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Humidity", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); metric = gw.getConfig().isMetric; //LIGHT // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Light Sensor", "1.0"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { // Read digital motion value boolean tripped = digitalRead(PIR_SENSOR_DIGITAL) == HIGH; Serial.print("---------- PIR: "); Serial.println(tripped); gw.send(msgPir.set(tripped ? "1" : "0")); // Send tripped value to gw if ( millis() > mytime ) { //DHT 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("---------- Temp: "); 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("---------- Humidity: "); Serial.println(humidity); } mytime = millis() + dht.getMinimumSamplingPeriod(); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME); }i get this output:
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=13,st=ok:Motion Sensor
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=1,c=0,t=1,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=8,st=ok:Humidity
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=2,c=0,t=7,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=3,c=0,t=6,pt=0,l=5,st=ok:1.4.1
send: 10-10-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Light Sensor
send: 10-10-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 10-10-0-0 s=4,c=0,t=16,pt=0,l=5,st=ok:1.4.1
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
send: 10-10-0-0 s=3,c=1,t=0,pt=7,l=5,st=ok:17.2
---------- Temp: 17.20
send: 10-10-0-0 s=2,c=1,t=1,pt=7,l=5,st=ok:43.8
---------- Humidity: 43.80
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- PIR: 1
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:1
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0
---------- PIR: 0
send: 10-10-0-0 s=1,c=1,t=16,pt=0,l=1,st=ok:0 -
This can't work well. Your interrupt is set on pin1 - 2 = int-1?
What happens when you remove the pir and use a switch instead?
-
@n3ro , what is wrong at your last test? The PIR is reporting 0 and 1, and from time to time there is a temp/hum report as well.
@rvendrame in my last test the pir sends endless 0 and dont sleep
-
Which arduino PIN do you use to connect the PIR?
-
Perfect. If it is working fine with a switch --- Maybe your PIN is triggering false positives? Or maybe the PIR output is floating a bit, and arduino is triggering it more than it should?
-
If a switch works than the only could be the pir itself. You have enabled the pull-up resistor so an open collector should not give floats.
You already told that a sketch with a pir only worked fine?
Well, i can test what happens with my dht22 and a pir tomorrow (with your sketch).
-
If a switch works than the only could be the pir itself. You have enabled the pull-up resistor so an open collector should not give floats.
You already told that a sketch with a pir only worked fine?
Well, i can test what happens with my dht22 and a pir tomorrow (with your sketch).