Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. 3-in-1 Humidity Temp and Motion

3-in-1 Humidity Temp and Motion

Scheduled Pinned Locked Moved My Project
motion3 in 1temphumidity
47 Posts 28 Posters 43.1k Views 22 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Konrad Walsh
    wrote on last edited by Konrad Walsh
    #1

    I am wanted to share my 3-in-1 sensor in case its of use to anyone
    Its really just a combination of what's already available

    I used the following hardware:

    Arduino Nano LINK - Gave me both 3.3v and 5v output without having to mess with extra hardware(steppers)
    1 x Motion Sensor LINK
    1 x DHT22 LINK

    Connections is as all other guides except:
    Motion Sensor digital to Pin D3
    and the DHT to Pin D4

    Here is my code

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>  
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_MOT 2   // Id of the sensor child
    #define HUMIDITY_SENSOR_DIGITAL_PIN 4
    
    #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)
    
    
    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 msgMot(CHILD_ID_MOT, V_TRIPPED);
    
    void setup()  
    { 
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Humidity/Motion", "1.0");
    
    
     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);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_MOT, S_MOTION);
       
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    
    {  
      // Read digital motion value
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
            
      Serial.println(tripped);
      gw.send(msgMot.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);
      }
    
      
     
      // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
      gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    }
    
    
    

    If anyone wants more info please ask.. I will put up pictures or diagrams if needed

    RJ_MakeR M A 3 Replies Last reply
    4
    • K Konrad Walsh

      I am wanted to share my 3-in-1 sensor in case its of use to anyone
      Its really just a combination of what's already available

      I used the following hardware:

      Arduino Nano LINK - Gave me both 3.3v and 5v output without having to mess with extra hardware(steppers)
      1 x Motion Sensor LINK
      1 x DHT22 LINK

      Connections is as all other guides except:
      Motion Sensor digital to Pin D3
      and the DHT to Pin D4

      Here is my code

      #include <SPI.h>
      #include <MySensor.h>  
      #include <DHT.h>  
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_MOT 2   // Id of the sensor child
      #define HUMIDITY_SENSOR_DIGITAL_PIN 4
      
      #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)
      
      
      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 msgMot(CHILD_ID_MOT, V_TRIPPED);
      
      void setup()  
      { 
        gw.begin();
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Humidity/Motion", "1.0");
      
      
       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);
        gw.present(CHILD_ID_TEMP, S_TEMP);
        gw.present(CHILD_ID_MOT, S_MOTION);
         
        metric = gw.getConfig().isMetric;
      }
      
      void loop()      
      
      {  
        // Read digital motion value
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
              
        Serial.println(tripped);
        gw.send(msgMot.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);
        }
      
        
       
        // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      }
      
      
      

      If anyone wants more info please ask.. I will put up pictures or diagrams if needed

      RJ_MakeR Offline
      RJ_MakeR Offline
      RJ_Make
      Hero Member
      wrote on last edited by
      #2

      @Konrad-Walsh
      Battery powered?

      RJ_Make

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Konrad Walsh
        wrote on last edited by
        #3

        no. usb charger powered. No idea where to start with battery powering this stuff

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chilump
          wrote on last edited by
          #4

          Very cool. Could you list the hardware you used for this project?

          K 1 Reply Last reply
          0
          • C chilump

            Very cool. Could you list the hardware you used for this project?

            K Offline
            K Offline
            Konrad Walsh
            wrote on last edited by Konrad Walsh
            #5

            @chilump
            Yes of course... I'll update the original post shortly..

            EDIT: UPDATED

            1 Reply Last reply
            0
            • AtomicGrogA Offline
              AtomicGrogA Offline
              AtomicGrog
              wrote on last edited by
              #6

              Interested in how you will package this? will the recorded temp be affected by the duino if it's enclosed?

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Konrad Walsh
                wrote on last edited by
                #7

                No its not affected as the temp sensor is on the outside of the case along with the motion sensor

                1 Reply Last reply
                0
                • bobnataleB Offline
                  bobnataleB Offline
                  bobnatale
                  wrote on last edited by
                  #8

                  Do you have a picture of it in the case? Pictures rule =)

                  1 Reply Last reply
                  0
                  • NuubiN Offline
                    NuubiN Offline
                    Nuubi
                    wrote on last edited by
                    #9

                    I found out quite marked difference between different setups! On the surface of the enclosure there's >3C warmer than few centimeters further from the enclosure, see pictures :-)

                    First picture: temp, light level, door sensor, movement, patio PWM led lightning. DS sensor on the bottom of the enclosure
                    WP_20141024_14_37_41_Pro.jpg (temp, light level, movement)

                    Second: temp, light, movement
                    WP_20141024_14_37_58_Pro.jpg

                    RJ_MakeR 1 Reply Last reply
                    0
                    • NuubiN Nuubi

                      I found out quite marked difference between different setups! On the surface of the enclosure there's >3C warmer than few centimeters further from the enclosure, see pictures :-)

                      First picture: temp, light level, door sensor, movement, patio PWM led lightning. DS sensor on the bottom of the enclosure
                      WP_20141024_14_37_41_Pro.jpg (temp, light level, movement)

                      Second: temp, light, movement
                      WP_20141024_14_37_58_Pro.jpg

                      RJ_MakeR Offline
                      RJ_MakeR Offline
                      RJ_Make
                      Hero Member
                      wrote on last edited by
                      #10

                      @Nuubi Where did you get those cases?

                      RJ_Make

                      1 Reply Last reply
                      0
                      • NuubiN Offline
                        NuubiN Offline
                        Nuubi
                        wrote on last edited by
                        #11

                        Upper picture: a repurposed old movement alarm unit, was on sale for 2€ several years ago on a local store.
                        Lower one: from dx.com (http://www.dx.com/p/wall-mount-pir-motion-detector-with-80db-alarm-siren-7-10-meter-110-degrees-15278), just swapped the internals. A bit small for my spider net constructions, though.

                        1 Reply Last reply
                        0
                        • O Offline
                          O Offline
                          Opus40
                          wrote on last edited by
                          #12

                          Hi,

                          I am trying out your 3-in-1 Humidity Temp and Motion sensor with a DHT11 and get the following in the serial out put

                          sensor started, id 5
                          send: 5-5-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
                          send: 5-5-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
                          read: 0-0-5 s=255,c=3,t=6,pt=0,l=1:M
                          send: 5-5-0-0 s=255,c=3,t=11,pt=0,l=15,st=ok:Humidity/Motion
                          send: 5-5-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
                          send: 5-5-0-0 s=0,c=0,t=7,pt=0,l=5,st=ok:1.4.1
                          send: 5-5-0-0 s=1,c=0,t=6,pt=0,l=5,st=ok:1.4.1
                          send: 5-5-0-0 s=2,c=0,t=1,pt=0,l=5,st=ok:1.4.1
                          1
                          send: 5-5-0-0 s=2,c=1,t=16,pt=0,l=1,st=ok:1
                          Failed reading temperature from DHT
                          Failed reading humidity from DHT
                          1
                          send: 5-5-0-0 s=2,c=1,t=16,pt=0,l=1,st=ok:1
                          Failed reading temperature from DHT
                          Failed reading humidity from DHT
                          0
                          so the motion is working but not the temp or humidity, do I have to do some thing different in the scetch for the DHT11 over the DHT22?

                          Thanks for any help.

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            Konrad Walsh
                            wrote on last edited by
                            #13

                            Hey

                            From what I just read it shouldnt matter.. you I would double check you wiring of the DHT11. Your output should be on PIN 4.. Also, have you placed the resistor on the DHT1`1

                            1 Reply Last reply
                            0
                            • O Offline
                              O Offline
                              Opus40
                              wrote on last edited by
                              #14

                              hi,

                              thanks I did some reading my self and realised I needed the resistor works a treat now. thanks for the reply.

                              K 1 Reply Last reply
                              0
                              • O Opus40

                                hi,

                                thanks I did some reading my self and realised I needed the resistor works a treat now. thanks for the reply.

                                K Offline
                                K Offline
                                Konrad Walsh
                                wrote on last edited by
                                #15

                                @Opus40 Great!

                                I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic

                                NuubiN 1 Reply Last reply
                                0
                                • K Konrad Walsh

                                  @Opus40 Great!

                                  I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic

                                  NuubiN Offline
                                  NuubiN Offline
                                  Nuubi
                                  wrote on last edited by Nuubi
                                  #16

                                  @Konrad-Walsh said:

                                  I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic

                                  Hum-temp-motion-light-???

                                  K 1 Reply Last reply
                                  0
                                  • NuubiN Nuubi

                                    @Konrad-Walsh said:

                                    I am currently finalising a 5 in 1 sensor... just testing and so far its working fantastic

                                    Hum-temp-motion-light-???

                                    K Offline
                                    K Offline
                                    Konrad Walsh
                                    wrote on last edited by
                                    #17

                                    @Nuubi LOL.. its a secret!!!

                                    and I will share my carefully guarded secret... Air quality sensor!! or in other words.. smoke and gas detector...

                                    1 Reply Last reply
                                    0
                                    • N Offline
                                      N Offline
                                      NotYetRated
                                      wrote on last edited by
                                      #18

                                      Did you mount your PIR behind the rounded screen area on those cases? It works through that?

                                      I have yet to get to integrating PIR's in to my sensors, but do plan to, and was curious how to effectively mount them. Need to offer protection from the circuitry, but visibility to the sensor itself.

                                      1 Reply Last reply
                                      0
                                      • C4VetteC Offline
                                        C4VetteC Offline
                                        C4Vette
                                        wrote on last edited by C4Vette
                                        #19

                                        Question about a minor detail:
                                        Wouldn't a motionsenser trip be missed during:
                                        delay(dht.getMinimumSamplingPeriod()); ?
                                        For a DHT22 this is 2 seconds... or does the interrupt still has precedence?

                                        BulldogLowellB 1 Reply Last reply
                                        0
                                        • C4VetteC C4Vette

                                          Question about a minor detail:
                                          Wouldn't a motionsenser trip be missed during:
                                          delay(dht.getMinimumSamplingPeriod()); ?
                                          For a DHT22 this is 2 seconds... or does the interrupt still has precedence?

                                          BulldogLowellB Offline
                                          BulldogLowellB Offline
                                          BulldogLowell
                                          Contest Winner
                                          wrote on last edited by
                                          #20

                                          @C4Vette you could just use a non-blocking method to read the temperature instead of the delay.

                                          The delay is method is in the library and used so that multiple reads to the sensor don't affect the reading (overheating the sensor).

                                          since SLEEP_TIME is 30s in the code above... I'd just read the temperature each time the sensor was awakened.

                                          you could just timestamp the last reading and check that at least the 2 seconds elapsed since the last reading before you take a new one (in the case that motion was detected.

                                          C4VetteC 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          7

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular