Trouble combining sketches for temp and motion control
-
Here is a sketch I use myself. A combination of hum/temp (DHT) and motion.
It reports motion status on motion or every 30 sec.
#include <SPI.h> #include <MySensor.h> #include <DHT.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MOTION 3 #define HUMIDITY_SENSOR_DIGITAL_PIN 6 #define MOTION_SENSOR_PIN 3 #define INTERRUPT MOTION_SENSOR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway) unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) MySensor gw; DHT dht; float lastTemp; float lastHum; boolean metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgMotion(CHILD_ID_MOTION, V_TRIPPED); void setup() { gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Multi Motion+Hum", "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); pinMode(MOTION_SENSOR_PIN, 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_MOTION, S_MOTION); metric = gw.getConfig().isMetric; } void loop() { // Read digital motion value boolean tripped = digitalRead(MOTION_SENSOR_PIN) == HIGH; Serial.print("Tripped: "); Serial.println(tripped); gw.send(msgMotion.set(tripped?"1":"0")); // Send tripped value to gw 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); } gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); } -
Here is a sketch I use myself. A combination of hum/temp (DHT) and motion.
It reports motion status on motion or every 30 sec.
#include <SPI.h> #include <MySensor.h> #include <DHT.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MOTION 3 #define HUMIDITY_SENSOR_DIGITAL_PIN 6 #define MOTION_SENSOR_PIN 3 #define INTERRUPT MOTION_SENSOR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway) unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) MySensor gw; DHT dht; float lastTemp; float lastHum; boolean metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgMotion(CHILD_ID_MOTION, V_TRIPPED); void setup() { gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Multi Motion+Hum", "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); pinMode(MOTION_SENSOR_PIN, 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_MOTION, S_MOTION); metric = gw.getConfig().isMetric; } void loop() { // Read digital motion value boolean tripped = digitalRead(MOTION_SENSOR_PIN) == HIGH; Serial.print("Tripped: "); Serial.println(tripped); gw.send(msgMotion.set(tripped?"1":"0")); // Send tripped value to gw 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); } gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); } -
Do you have a bare DHT that needs a resistor?
link text
What does the serial say? -
It doesnt give a reading for temperature or humidity. Sensor works. Yeah it's the solder free module dht 22 that has the three pronges
-
@davvvvvo Did you re-include the node after changing the sketch? What controller are you using? Post your sketch using the </> tool.
@Dwalt yes I removed the node off Vera U7 and re added it as instructions say. Using Nana serial controller. The motion sensor works perfectly. I'm using hek sketch, I just cut and paste the sketch into to program and compiled and uploaded. Do I need a resistor with the dht 22 temp sensor because I don't have one on it at the moment.
-
@Dwalt yes I removed the node off Vera U7 and re added it as instructions say. Using Nana serial controller. The motion sensor works perfectly. I'm using hek sketch, I just cut and paste the sketch into to program and compiled and uploaded. Do I need a resistor with the dht 22 temp sensor because I don't have one on it at the moment.
@davvvvvo If you used Hek's sketch above and your DHT is connected to pin 6 and the PIR on pin 3, it should work. How are you powering the DHT and PIR? You should be using the nano's 5v. You do not need a separate resistor on the DHT module (3 pins), it has one onboard the module. Are you seeing the temp and hum child devices in Vera? If so, try powering the node off-on and reloading the Vera page.
-
@davvvvvo If you used Hek's sketch above and your DHT is connected to pin 6 and the PIR on pin 3, it should work. How are you powering the DHT and PIR? You should be using the nano's 5v. You do not need a separate resistor on the DHT module (3 pins), it has one onboard the module. Are you seeing the temp and hum child devices in Vera? If so, try powering the node off-on and reloading the Vera page.
@Dwalt I'm powering both sensors off the 5v pin on the board so they are sharing the power. Temp is on pin 6. All three nodes added to Vera. I can arm or bypass the motion and this works, the temp and humidity node are on Vera but not showing any numbers. Temp is at 0 degrees and humidity is at 0%. I tried cycling the nodes off and on a few times. With no results.
-
@Dwalt I'm powering both sensors off the 5v pin on the board so they are sharing the power. Temp is on pin 6. All three nodes added to Vera. I can arm or bypass the motion and this works, the temp and humidity node are on Vera but not showing any numbers. Temp is at 0 degrees and humidity is at 0%. I tried cycling the nodes off and on a few times. With no results.
-
@davvvvvo If you eliminate any wiring mistakes, I assume you must have a bad DHT sensor. You could try it without the PIR and load up the basic temp/hum sketch to see if it works or see if you can see anything through the serial log.
@Dwalt Just used the DHT sensor on its own and loaded the humidity sketch and it works perfectly. did try and load the dallas temp sketch and that didnt work on its own. Question will i need to upload if there is one someting like a dallas.JSON or or another XML onto vera for hek's sketch to work possibly?
-
@Dwalt Just used the DHT sensor on its own and loaded the humidity sketch and it works perfectly. did try and load the dallas temp sketch and that didnt work on its own. Question will i need to upload if there is one someting like a dallas.JSON or or another XML onto vera for hek's sketch to work possibly?
@davvvvvo The Dallas sensor is completely different from the DHT and does not factor into your setup. The DHT provides both temp and humidity. The Dallas temp sensor uses a separate library for pulling data from that particular sensor. Can you post your serial log from your sensor with both DHT and PIR connected using the sketch Hek provided above? That would tell us what is happening at the communication level between the sensor node and gateway.
-
@davvvvvo The Dallas sensor is completely different from the DHT and does not factor into your setup. The DHT provides both temp and humidity. The Dallas temp sensor uses a separate library for pulling data from that particular sensor. Can you post your serial log from your sensor with both DHT and PIR connected using the sketch Hek provided above? That would tell us what is happening at the communication level between the sensor node and gateway.
-
@davvvvvo The Dallas sensor is completely different from the DHT and does not factor into your setup. The DHT provides both temp and humidity. The Dallas temp sensor uses a separate library for pulling data from that particular sensor. Can you post your serial log from your sensor with both DHT and PIR connected using the sketch Hek provided above? That would tell us what is happening at the communication level between the sensor node and gateway.
-
@davvvvvo The Dallas sensor is completely different from the DHT and does not factor into your setup. The DHT provides both temp and humidity. The Dallas temp sensor uses a separate library for pulling data from that particular sensor. Can you post your serial log from your sensor with both DHT and PIR connected using the sketch Hek provided above? That would tell us what is happening at the communication level between the sensor node and gateway.
@Dwalt
sensor started, id 2
send: 2-2-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=16,st=ok:Multi Motion+Hum
send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 2-2-0-0 s=0,c=0,t=7,pt=0,l=0,st=ok:
send: 2-2-0-0 s=1,c=0,t=6,pt=0,l=0,st=ok:
send: 2-2-0-0 s=3,c=0,t=1,pt=0,l=0,st=ok:
Tripped: 0
send: 2-2-0-0 s=3,c=1,t=16,pt=0,l=1,st=ok:0
Failed reading temperature from DHT
Failed reading humidity from DHT
Tripped: 0
send: 2-2-0-0 s=3,c=1,t=16,pt=0,l=1,st=ok:0
Failed reading temperature from DHT
Failed reading humidity from DHT
Tripped: 0
send: 2-2-0-0 s=3,c=1,t=16,pt=0,l=1,st=ok:0
Failed reading temperature from DHT
Failed reading humidity from DHT -
Its a problem with the DHT, the setup between Arduino and DHT sensor i think...
-Tried another DHT-Sensor or bare DHT code?
-Tried another inputpin on the arduino (i got this message when i didnt solder the pin properly)
-Check/change wiring.Also try the delay(dht.getMinimumSamplingPeriod()); before the motion sensor code and see if this changes anything.