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. Door, Motion and Temperature Sensor

Door, Motion and Temperature Sensor

Scheduled Pinned Locked Moved My Project
63 Posts 11 Posters 42.4k Views 4 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.
  • BulldogLowellB Offline
    BulldogLowellB Offline
    BulldogLowell
    Contest Winner
    wrote on last edited by BulldogLowell
    #53

    @petoulachi said:

    this will sleep the device until the interrupt triggers it to awaken...

    gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    

    you are correct that it seems that the sleep(750) function will block your device, I don't think you want that.

    1 Reply Last reply
    0
    • CaptainZapC Offline
      CaptainZapC Offline
      CaptainZap
      wrote on last edited by
      #54

      @petoulachi @BulldogLowell Glad to hear there is some progress, in regards to my issue and hopefully this is step in the right direction. I'm positive that we're not alone in our need to create multisensors, both powered and battery operated, as arduinos offer too many possibilities to limit yourself to just a single type of device :)

      BulldogLowellB 1 Reply Last reply
      0
      • CaptainZapC CaptainZap

        @petoulachi @BulldogLowell Glad to hear there is some progress, in regards to my issue and hopefully this is step in the right direction. I'm positive that we're not alone in our need to create multisensors, both powered and battery operated, as arduinos offer too many possibilities to limit yourself to just a single type of device :)

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

        @CaptainZap said:

        hopefully this is step in the right direction

        you don't have a working sketch?

        CaptainZapC 1 Reply Last reply
        0
        • BulldogLowellB BulldogLowell

          @CaptainZap said:

          hopefully this is step in the right direction

          you don't have a working sketch?

          CaptainZapC Offline
          CaptainZapC Offline
          CaptainZap
          wrote on last edited by
          #56

          @BulldogLowell Temperature isn't working, and is never updated on the Vera interface :|

          1 Reply Last reply
          0
          • BulldogLowellB Offline
            BulldogLowellB Offline
            BulldogLowell
            Contest Winner
            wrote on last edited by BulldogLowell
            #57

            try something like this, which is untested.

            #include <MySensor.h>
            #include <SPI.h>
            #include <DallasTemperature.h>
            #include <OneWire.h>
            
            //myPins
            const int PIR_PIN = 3;
            const int INTERRUPT = 1;
            const int DALLAS_PIN = 4;
            
            //myDevices
            const int PIR_SENSOR = 1;
            const int DALLAS_SENSOR = 2;
            
            OneWire oneWire(DALLAS_SENSOR);
            DallasTemperature DallasSensors(&oneWire);
            
            int lastTemperature = -99;
            unsigned long readTempInterval = 60 * 60 * 1000UL;  // One Hour Sleep time between reports (in milliseconds)
            unsigned long sleepTime = readTempInterval; 
            boolean lastTripped = 0;
            boolean sendTemp = true;
            
            MySensor gw;
            
            MyMessage motionMsg(PIR_SENSOR, V_TRIPPED);
            MyMessage tempMsg(DALLAS_SENSOR, V_TEMP);
            
            void setup()
            {
              DallasSensors.begin();
              //DallasSensors.setWaitForConversion(false);  /I could not get this to compile
              gw.begin();
              gw.sendSketchInfo("Multi-Sensor", "1.0alpha");
              pinMode(PIR_PIN, INPUT);      // sets the motion sensor digital pin as input
              gw.present(PIR_SENSOR, S_MOTION);
              gw.present(DALLAS_SENSOR, S_TEMP);
            }
            
            void loop()
            {
              //gw.process(); don't need this, it is a one-way device.
              boolean tripped = digitalRead(PIR_PIN);
              if (lastTripped != tripped )
              {
                Serial.println(tripped? "Tripped" : "Not Tripped");
                gw.send(motionMsg.set(tripped)); // Send tripped value to gw
                lastTripped = tripped;
              }
              if (sendTemp)
              {
                DallasSensors.requestTemperatures();
                int tempC = (int) DallasSensors.getTempCByIndex(1);
                gw.send(tempMsg.set(tempC));
                lastTemperature = tempC;
                sendTemp = false;
              }
              unsigned long startSleepTime = millis();
              gw.sleep(INTERRUPT, CHANGE, sleepTime);
              unsigned long endSleepTime = millis();
              if (endSleepTime - startSleepTime >= sleepTime)
              {
                sleepTime = readTempInterval;
                sendTemp = true;
              }
              else
              {
                sleepTime = max(sleepTime -= (endSleepTime - startSleepTime), 1000UL);
              }
            }
            

            It will send temp to controller once an hour... you can change that for testing;

            also will detect motion...

            it may need debouncing.

            CaptainZapC 2 Replies Last reply
            0
            • BulldogLowellB BulldogLowell

              try something like this, which is untested.

              #include <MySensor.h>
              #include <SPI.h>
              #include <DallasTemperature.h>
              #include <OneWire.h>
              
              //myPins
              const int PIR_PIN = 3;
              const int INTERRUPT = 1;
              const int DALLAS_PIN = 4;
              
              //myDevices
              const int PIR_SENSOR = 1;
              const int DALLAS_SENSOR = 2;
              
              OneWire oneWire(DALLAS_SENSOR);
              DallasTemperature DallasSensors(&oneWire);
              
              int lastTemperature = -99;
              unsigned long readTempInterval = 60 * 60 * 1000UL;  // One Hour Sleep time between reports (in milliseconds)
              unsigned long sleepTime = readTempInterval; 
              boolean lastTripped = 0;
              boolean sendTemp = true;
              
              MySensor gw;
              
              MyMessage motionMsg(PIR_SENSOR, V_TRIPPED);
              MyMessage tempMsg(DALLAS_SENSOR, V_TEMP);
              
              void setup()
              {
                DallasSensors.begin();
                //DallasSensors.setWaitForConversion(false);  /I could not get this to compile
                gw.begin();
                gw.sendSketchInfo("Multi-Sensor", "1.0alpha");
                pinMode(PIR_PIN, INPUT);      // sets the motion sensor digital pin as input
                gw.present(PIR_SENSOR, S_MOTION);
                gw.present(DALLAS_SENSOR, S_TEMP);
              }
              
              void loop()
              {
                //gw.process(); don't need this, it is a one-way device.
                boolean tripped = digitalRead(PIR_PIN);
                if (lastTripped != tripped )
                {
                  Serial.println(tripped? "Tripped" : "Not Tripped");
                  gw.send(motionMsg.set(tripped)); // Send tripped value to gw
                  lastTripped = tripped;
                }
                if (sendTemp)
                {
                  DallasSensors.requestTemperatures();
                  int tempC = (int) DallasSensors.getTempCByIndex(1);
                  gw.send(tempMsg.set(tempC));
                  lastTemperature = tempC;
                  sendTemp = false;
                }
                unsigned long startSleepTime = millis();
                gw.sleep(INTERRUPT, CHANGE, sleepTime);
                unsigned long endSleepTime = millis();
                if (endSleepTime - startSleepTime >= sleepTime)
                {
                  sleepTime = readTempInterval;
                  sendTemp = true;
                }
                else
                {
                  sleepTime = max(sleepTime -= (endSleepTime - startSleepTime), 1000UL);
                }
              }
              

              It will send temp to controller once an hour... you can change that for testing;

              also will detect motion...

              it may need debouncing.

              CaptainZapC Offline
              CaptainZapC Offline
              CaptainZap
              wrote on last edited by
              #58

              @BulldogLowell Thanks, I'll try it tonight once I get home.

              1 Reply Last reply
              0
              • BulldogLowellB BulldogLowell

                try something like this, which is untested.

                #include <MySensor.h>
                #include <SPI.h>
                #include <DallasTemperature.h>
                #include <OneWire.h>
                
                //myPins
                const int PIR_PIN = 3;
                const int INTERRUPT = 1;
                const int DALLAS_PIN = 4;
                
                //myDevices
                const int PIR_SENSOR = 1;
                const int DALLAS_SENSOR = 2;
                
                OneWire oneWire(DALLAS_SENSOR);
                DallasTemperature DallasSensors(&oneWire);
                
                int lastTemperature = -99;
                unsigned long readTempInterval = 60 * 60 * 1000UL;  // One Hour Sleep time between reports (in milliseconds)
                unsigned long sleepTime = readTempInterval; 
                boolean lastTripped = 0;
                boolean sendTemp = true;
                
                MySensor gw;
                
                MyMessage motionMsg(PIR_SENSOR, V_TRIPPED);
                MyMessage tempMsg(DALLAS_SENSOR, V_TEMP);
                
                void setup()
                {
                  DallasSensors.begin();
                  //DallasSensors.setWaitForConversion(false);  /I could not get this to compile
                  gw.begin();
                  gw.sendSketchInfo("Multi-Sensor", "1.0alpha");
                  pinMode(PIR_PIN, INPUT);      // sets the motion sensor digital pin as input
                  gw.present(PIR_SENSOR, S_MOTION);
                  gw.present(DALLAS_SENSOR, S_TEMP);
                }
                
                void loop()
                {
                  //gw.process(); don't need this, it is a one-way device.
                  boolean tripped = digitalRead(PIR_PIN);
                  if (lastTripped != tripped )
                  {
                    Serial.println(tripped? "Tripped" : "Not Tripped");
                    gw.send(motionMsg.set(tripped)); // Send tripped value to gw
                    lastTripped = tripped;
                  }
                  if (sendTemp)
                  {
                    DallasSensors.requestTemperatures();
                    int tempC = (int) DallasSensors.getTempCByIndex(1);
                    gw.send(tempMsg.set(tempC));
                    lastTemperature = tempC;
                    sendTemp = false;
                  }
                  unsigned long startSleepTime = millis();
                  gw.sleep(INTERRUPT, CHANGE, sleepTime);
                  unsigned long endSleepTime = millis();
                  if (endSleepTime - startSleepTime >= sleepTime)
                  {
                    sleepTime = readTempInterval;
                    sendTemp = true;
                  }
                  else
                  {
                    sleepTime = max(sleepTime -= (endSleepTime - startSleepTime), 1000UL);
                  }
                }
                

                It will send temp to controller once an hour... you can change that for testing;

                also will detect motion...

                it may need debouncing.

                CaptainZapC Offline
                CaptainZapC Offline
                CaptainZap
                wrote on last edited by CaptainZap
                #59

                @BulldogLowell I just managed to test this and I have some questions :

                1. Motion doesn't seem to work that great - meaning that it takes at least one minute after being untripped to be tripped again
                2. Door/window doesn't seem to work - I think I have to add this part, but I'm a bit overwhelmed
                3. Temperature starts with temperature of -127C and doesn't update at all (I held my finger on it for 2 minutes) plus I think I need something to avoid -127 temps, like :
                if (lastTemperature != tempC && tempC != -127.00)
                

                For your info I used these pins to connect my sensors :

                const int PIR_PIN = 3; - PIR sensor
                const int INTERRUPT = 4; - Door/Window
                const int DALLAS_PIN = 5; - Temperature sensor
                [...]
                unsigned long readTempInterval = 1 * 60 * 1000UL; - modified read interval to 1 minute for testing purposes
                

                Also I get this output of the serial monitor once I compile and upload the sketch to my nano after 2 minutes and multiple tries to trip PIR sensor :

                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=12,st=ok:Multi-Sensor
                send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=8,st=ok:1.0alpha
                send: 2-2-0-0 s=1,c=0,t=1,pt=0,l=0,st=ok:
                send: 2-2-0-0 s=2,c=0,t=6,pt=0,l=0,st=ok:
                send: 2-2-0-0 s=2,c=1,t=0,pt=2,l=2,st=ok:-127
                Tripped
                send: 2-2-0-0 s=1,c=1,t=16,pt=2,l=2,st=ok:1
                Not Tripped
                send: 2-2-0-0 s=1,c=1,t=16,pt=2,l=2,st=ok:0
                Tripped
                send: 2-2-0-0 s=1,c=1,t=16,pt=2,l=2,st=ok:1
                
                

                I would appreciate any help I can get to get this started... this project has been on hold for at least 1 year and I would like to implement it now since I have all the parts I need, including 5 cases for the motion detectors (I will need to have at least two variations for them). My focus right now is getting a working sketch, with repeating functions or not, I can place repeaters if needed that is not a problem.

                Moshe LivneM 1 Reply Last reply
                0
                • CaptainZapC CaptainZap

                  @BulldogLowell I just managed to test this and I have some questions :

                  1. Motion doesn't seem to work that great - meaning that it takes at least one minute after being untripped to be tripped again
                  2. Door/window doesn't seem to work - I think I have to add this part, but I'm a bit overwhelmed
                  3. Temperature starts with temperature of -127C and doesn't update at all (I held my finger on it for 2 minutes) plus I think I need something to avoid -127 temps, like :
                  if (lastTemperature != tempC && tempC != -127.00)
                  

                  For your info I used these pins to connect my sensors :

                  const int PIR_PIN = 3; - PIR sensor
                  const int INTERRUPT = 4; - Door/Window
                  const int DALLAS_PIN = 5; - Temperature sensor
                  [...]
                  unsigned long readTempInterval = 1 * 60 * 1000UL; - modified read interval to 1 minute for testing purposes
                  

                  Also I get this output of the serial monitor once I compile and upload the sketch to my nano after 2 minutes and multiple tries to trip PIR sensor :

                  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=12,st=ok:Multi-Sensor
                  send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=8,st=ok:1.0alpha
                  send: 2-2-0-0 s=1,c=0,t=1,pt=0,l=0,st=ok:
                  send: 2-2-0-0 s=2,c=0,t=6,pt=0,l=0,st=ok:
                  send: 2-2-0-0 s=2,c=1,t=0,pt=2,l=2,st=ok:-127
                  Tripped
                  send: 2-2-0-0 s=1,c=1,t=16,pt=2,l=2,st=ok:1
                  Not Tripped
                  send: 2-2-0-0 s=1,c=1,t=16,pt=2,l=2,st=ok:0
                  Tripped
                  send: 2-2-0-0 s=1,c=1,t=16,pt=2,l=2,st=ok:1
                  
                  

                  I would appreciate any help I can get to get this started... this project has been on hold for at least 1 year and I would like to implement it now since I have all the parts I need, including 5 cases for the motion detectors (I will need to have at least two variations for them). My focus right now is getting a working sketch, with repeating functions or not, I can place repeaters if needed that is not a problem.

                  Moshe LivneM Offline
                  Moshe LivneM Offline
                  Moshe Livne
                  Hero Member
                  wrote on last edited by
                  #60

                  @CaptainZap The motion detector (if you are using one like in the store) has two little dials on it. One is sensitivity and the other is time delay (see http://www.mpja.com/download/31227sc.pdf). Try to play with these until you get the effect you are looking for

                  CaptainZapC 1 Reply Last reply
                  0
                  • Moshe LivneM Moshe Livne

                    @CaptainZap The motion detector (if you are using one like in the store) has two little dials on it. One is sensitivity and the other is time delay (see http://www.mpja.com/download/31227sc.pdf). Try to play with these until you get the effect you are looking for

                    CaptainZapC Offline
                    CaptainZapC Offline
                    CaptainZap
                    wrote on last edited by CaptainZap
                    #61

                    @Moshe-Livne That's not the problem... The previous code had the same pir sensor working, it has a couple of seconds timeout.
                    At this time I'll take another look at my very first sketch, and remove the repeating part, maybe I can get somewhere...
                    Looking back 1 year ago this was a nice idea, however I've put more time than I would have hoped for into it and I still don't have something that I can call reliable. I know this is a labor of love, and not perfect in any way, I just expected it to be a bit easier to do...

                    1 Reply Last reply
                    0
                    • ThomasDecockT Offline
                      ThomasDecockT Offline
                      ThomasDecock
                      wrote on last edited by ThomasDecock
                      #62

                      Did you manage to get this working?
                      if yes, can you share your script?
                      I am also having trouble with the dallas temp sensor, if your code works i think it can help me a lot!
                      (i am trying to make a 'motion - temperature - 3 pwm dimmer' sensor

                      CaptainZapC 1 Reply Last reply
                      0
                      • ThomasDecockT ThomasDecock

                        Did you manage to get this working?
                        if yes, can you share your script?
                        I am also having trouble with the dallas temp sensor, if your code works i think it can help me a lot!
                        (i am trying to make a 'motion - temperature - 3 pwm dimmer' sensor

                        CaptainZapC Offline
                        CaptainZapC Offline
                        CaptainZap
                        wrote on last edited by
                        #63

                        @ThomasDecock No I wasn't, I was able to get the standard dallas temperature working(because I thought the sensors no longer work), but unfortunately my time on this is pretty limited. I hoped I got it working until I go on vacation, but probably will look into it after.
                        I would appreciate if someone could help with it, I think everyone would.

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


                        20

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.1k

                        Posts


                        Copyright 2025 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