Merge DHT11 Humidity/Temp sketch into Motion Sensor sketch

Has anyone done this yet?

I finally received the DHT11 sensors I ordered and I wanted to include them with my current motion sensors…each room will have a motion sensor so I want to piggyback a Temp/Humidity sensor too.

Looking for a bit of guidance here since I need the motion sensor to respond immediately, but the temp/humidity can update every 30 seconds or so.

Also need to make sure the Child IDs for the various sensors all correspond back to their respective Vera module for display/control functions.

Thanks!
Ross

This is a good problem. Nice to add capability to a sensor you are always using and the arduino has the capability to do more.

if you are using it powered, then you could keep the motion sketch and edit out the radio sleep, being careful not to flood the radio network by TX too often.

or if you want to use battery power, you could use a timer (without a delay) embedded into the the motion sketch using the millis() to count the time and then send updates of the Temp/Humidity values. Look at BlinkWithoutDelay example sketch in Arduino.

I just did something similar with the Relay sketch. I’m happy to give it a go if you need help with the code.

[quote=“Bulldoglowell, post:2, topic:180778”]This is a good problem. Nice to add capability to a sensor you are always using and the arduino has the capability to do more.

if you are using it powered, then you could keep the motion sketch and edit out the radio sleep, being careful not to flood the radio network by TX too often.

or if you want to use battery power, you could use a timer (without a delay) embedded into the the motion sketch using the millis() to count the time and then send updates of the Temp/Humidity values. Look at BlinkWithoutDelay example sketch in Arduino.

I just did something similar with the Relay sketch. I’m happy to to it a go if you need help with the code.[/quote]

Everything so far will be powered…so honestly sleep is unnecessary for most of what I plan.

Right now I’m just trying to get the DHT11 to work again with a normal sketch…seems like the sensor isn’t reading anything now.

Maybe when my PCBs arrive and I get all the other wiring out of the way I can focus on a clean connection and test of the sensor itself.

I think I had to download a new library for my humidistat/thermostats but I went with the DHT22’s, I can’t recall at this point; so many sketches, so many libraries. It is all a bit convoluted (outside of the MySensors world) in the Arduino space, yeah?

I have an early flight tomorrow am, so I will try to work on a few approaches in the air :wink:

Cool…thanks!

I have the sensor working in its own sketch…but when I try the code meshed into the motion sketch I get failures to read the Humidity and Temp. The CHILD_ID for each of the sensors is ok…motion works. And using the DHT_TEST sketch with the same RADIO and CHILD_IDs they transmit to the Vera properly also.

So I know it has to be something in the timing with the reading and all.

Ultimately I’ll have the vent fans in the bathrooms and the laundry room on Z-Wave switches, and if the temp or humidity gets too high in the room, have PLEG kick the vent fans on.

Also I have some of my ceiling fans controlled by ON/OFF switches and I’ll put logic in for temperatures there too.

Not too worried about the less precise DHT11 overall…a +/- 2 degree window is tolerable.

nothing against the 11’s, I just got the 22’s cheap in an auction; pure ebay luck.

They both do a great job on humidity spikes, just blow on them slowly for a few seconds and watch them climb. They will work great in that application, I’m sure.

Hi Ross,

Post your sketch so we can have a look/test it…

I had a similar idea with the vent/fan…but for my laundry.
I had to replace the fan a few months ago and the new one is super powerful ( could suck a golf ball through a hosepipe! )but unfortunately also loud!

This got me thinking about controlling my clothes dryer which my wife likes to fill with clothes and run during peak electricity hours! grrr…
So i thought i could build a controller to:

  1. Only run the dryer during off-peak hours - so needs to know the time. ( easy )
  2. Show on the lcd the current month cost of running it. (easyish)
  3. Use humidity sensors to turn off the dryer when the clothes are dry ( bit harder to calibrate…and also hack the dryer to run in cool-down mode for a few mins
  4. Turn on/off the vent fan 5 mins after dryer is done…

One of these days…

Ross,

I have not debugged it

Check it out and let me know…

// Get the libraries
#include <Sleep_n0m1.h>
#include <SPI.h>
#include <EEPROM.h>  
#include <RF24.h>
#include <Sensor.h>  
#include <DHT.h>
//
// Setup the pins
#define HUMIDITY_SENSOR_DIGITAL_PIN 6//***Note different than reguar HumiditySensor sketch pinout
#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)
// Make the babies
#define CHILD_ID 0      // ID of the Motion Sensor
#define CHILD_ID_HUM 1  // ID of the Hygrometer
#define CHILD_ID_TEMP 2 // ID of the Thermometer
// Add a Brometer????
//
//
Sensor gw;
DHT dht;
Sleep sleep;
float lastTemp;
float temperature;
float lastHum;
float humidity;
int led = 13;// &&**&& Remark these out to stop LED from lighting when motion sensor is tripped.
// It is only in there so you know Sensor is changing states without having to use Serial Monitor
boolean metric = false; // *** Change to true for Celcius temperture
//
//
void setup()  
{  
  pinMode(led, OUTPUT);// &&**&&
  EEPROM.write(EEPROM_RELAY_ID_ADDRESS, 0);
  gw.begin();
  // Send the sketch version information to the gateway and Controller
  gw.sendSketchInfo("Multi-Sensor", "1.0b");
  //
  pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
  dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
  //
  // Register all sensors to gw (they will be created as child devices)
  gw.sendSensorPresentation(CHILD_ID, S_MOTION);
  gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
  gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);
  //
  metric = gw.isMetricSystem();
}
//
//
void loop()     
{     
  //Check for Temperaure change
  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);
    }
    sendTemperature();
  }
  //Check for Humidity change
  float humidity = dht.getHumidity();
  if (isnan(humidity)) {
      Serial.println("Failed reading humidity from DHT");
  } else if (humidity != lastHum) {
      lastHum = humidity;
      sendHumidity();
  }
  //
  // Read digital motion value
  boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
  //    
  Serial.println(tripped);
  if (tripped==true)         // &&**&&
    digitalWrite (led,HIGH); // &&**&&
  else                       // &&**&&
    digitalWrite (led,LOW);  // &&**&&
  //
  gw.sendVariable(CHILD_ID, V_TRIPPED, tripped?"1":"0");  // Send tripped value to gw 
  //
  // Power down the radio.  Note that the radio will get powered back up
  // on the next write() call.
  delay(200); //delay to allow serial to fully print before sleep
  gw.powerDown();
  sleep.pwrDownMode(); //set sleep mode
  sleep.sleepInterrupt(INTERRUPT,CHANGE);
}
//
void sendTemperature() {
     gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1);
     Serial.print("Temp: ");
     Serial.println(temperature);     
}
//
void sendHumidity() {
     gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
     Serial.print("RH%: ");
     Serial.println(humidity);
}

Hi Guys,

I was wondering if you’ve managed to make this work? If so, can you please kindly post your latest sketch?
I’m trying to do something similar, but I’m very new to Arduino…

Many thanks,
James

Ross, did you ever get the Ethernet Gateway PCB resolved? If so, how can I get one? I hope the Ethernet module I sent was useful :slight_smile:

Did I read this post correctly that you are working on PCBs for a sensor , motion+ temp/hum? Pretty much the combination I’m looking to put at least one in every room. I’ve worked on a sketch for it but absent hardware (on order) I can’t go on right now.