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.
  • CaptainZapC CaptainZap

    That was the version I was using when I first encountered the issues... anyways I'll remove arduino IDE with everything and reinstall it. Thanks.

    @hek I also LOL-ed :D Gotta love the helping spirit in the community you guys built.

    R Offline
    R Offline
    robosensor
    wrote on last edited by
    #19

    @CaptainZap also try to backup and clean C:\Users***\Documents\Arduino\ directory :)

    1 Reply Last reply
    0
    • hekH hek

      @robosensor

      LOL :)

      R Offline
      R Offline
      robosensor
      wrote on last edited by
      #20

      @hek as I said before, Dallas library is bit outdated. Is it possible to update dallas and onewire libraries? I provided links for newer versions of this libraries in this thread. I can do PR in github myself, but I don't know how to do it :) I need to read github manuals first :)

      requestTemperatures() is can be non-blocking in newer version of dallas library, so code can deep sleep (better for batteries) or process messages (better for repeaters and msg-receiving nodes) about 750 ms.

      hekH 1 Reply Last reply
      0
      • R robosensor

        @hek as I said before, Dallas library is bit outdated. Is it possible to update dallas and onewire libraries? I provided links for newer versions of this libraries in this thread. I can do PR in github myself, but I don't know how to do it :) I need to read github manuals first :)

        requestTemperatures() is can be non-blocking in newer version of dallas library, so code can deep sleep (better for batteries) or process messages (better for repeaters and msg-receiving nodes) about 750 ms.

        hekH Offline
        hekH Offline
        hek
        Admin
        wrote on last edited by
        #21

        @robosensor

        Using github is quite easy (when you get a hang of it). We can use this as a "training session" if you want?

        I did a quick getting-started guide here:
        http://forum.mysensors.org/topic/330/how-to-contribute-code-to-the-mysensors-project

        Basically you need to

        • Fork the mysensors project on github
        • Clone your fork from your computer.
        • Replace the libraries that is outdated.
        • Commit as push the changes back to your fork of github.
        • Create a pull-request (see above instructions) which I'll review and merge.

        Easy peasy.. :)

        R 1 Reply Last reply
        0
        • hekH hek

          @robosensor

          Using github is quite easy (when you get a hang of it). We can use this as a "training session" if you want?

          I did a quick getting-started guide here:
          http://forum.mysensors.org/topic/330/how-to-contribute-code-to-the-mysensors-project

          Basically you need to

          • Fork the mysensors project on github
          • Clone your fork from your computer.
          • Replace the libraries that is outdated.
          • Commit as push the changes back to your fork of github.
          • Create a pull-request (see above instructions) which I'll review and merge.

          Easy peasy.. :)

          R Offline
          R Offline
          robosensor
          wrote on last edited by
          #22

          @hek thank you, I'll read and try on dallas&onewire :)

          hekH 1 Reply Last reply
          0
          • R robosensor

            @hek thank you, I'll read and try on dallas&onewire :)

            hekH Offline
            hekH Offline
            hek
            Admin
            wrote on last edited by
            #23

            @robosensor

            Great, just ask (or open a chat) if you run into trouble.

            R 1 Reply Last reply
            0
            • hekH hek

              @robosensor

              Great, just ask (or open a chat) if you run into trouble.

              R Offline
              R Offline
              robosensor
              wrote on last edited by
              #24

              @hek I have forked MySensors project, added 3 commits into master branch with updated libraries and updated dallas sensors example (lower power usage).

              I'm using similar code in my own version of MySensors 1.5-dev in my home, but I havn't tested this committed 1.4.1 github code on real hardware, so I will make PR after test on real hardware.

              https://github.com/mysensors/Arduino/compare/master...roboprint:master?diff=split&name=master

              1 Reply Last reply
              0
              • hekH Offline
                hekH Offline
                hek
                Admin
                wrote on last edited by
                #25

                Sounds good!

                R 1 Reply Last reply
                0
                • hekH hek

                  Sounds good!

                  R Offline
                  R Offline
                  robosensor
                  wrote on last edited by robosensor
                  #26

                  @hek It seems that I did it. If this push request is correct, what I should patch? Development branch, master branch or both?

                  1 Reply Last reply
                  0
                  • hekH Offline
                    hekH Offline
                    hek
                    Admin
                    wrote on last edited by
                    #27

                    Good!
                    You can create pull request on master (and I'll merge it to development later).

                    1 Reply Last reply
                    0
                    • hekH Offline
                      hekH Offline
                      hek
                      Admin
                      wrote on last edited by
                      #28

                      @robosensor

                      Thanks and congrats! You've made your first contribution to the MySensors project. :)

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

                        Guys, I had some free time tonight and tried to apply this fix... I ended up re-installing the arduino IDE + downloading the latest version, which now is 1.4.1 as opposed to the 1.4 that I used to have ?

                        Anyways I had to upgrade my ethernet gateway (ENC28J60) and it's no longer working now... any hints will be golden.
                        LE: I was too tired to check the sketch... I forgot to include the correct library and went to all debugging first, reset router config to default, but in the end I did notice the issue :) So I learned a valuable lesson, never work on this if it's late or you're tired.

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

                          Hello guys,

                          I really need an expert's opinion on this because I'm experiencing some trouble... I've tried to include suggestions from all you guys, except the delay part, but so far it works partially... in my original code the temperature worked, and now it doesn't. The rest works ok, sensor and motion, so I would be grateful if anyone could take a look at my code and help me with it... I kind of need to get it in place soon, as I intend to leave my house for some time.

                          Thank you.

                          //This sketch is for Door & Motion & Temp Sensor
                          
                          
                          #include <MySensor.h>
                          #include <SPI.h>
                          #include <DallasTemperature.h>
                          #include <OneWire.h>
                          #include <Bounce2.h>
                          
                          #define CLIENT_ID AUTO  // Sets MYSensors client id
                          #define RADIO_CH 76  // Sets MYSensors to use Radio Channel
                          #define TRIGGER	3	// used to connect motion sensor
                          #define BUTTON_PIN  4 // used to connect door/window sensor
                          
                          //Temp Sensor bits
                          #define ONE_WIRE_BUS 14 // Pin where dallas sensor is connected
                          OneWire oneWire(ONE_WIRE_BUS);
                          DallasTemperature DallasSensors(&oneWire);
                          float lastTemperature ;
                          #define CHILD_ID_T1 3 //CHILD ID for temp
                          
                          
                          //Door/Window bits
                          
                          #define CHILD_ID_D1 1 //CHILD ID for door/window
                          
                          //Trigger Sensor Bits
                          #define CHILD_ID_S1 2 //CHILD ID for Motion sensor
                          boolean lastTripped = 0;
                          
                          MySensor gw;
                          
                          Bounce debouncer = Bounce(); 
                          int oldValue=-1;
                          
                          // Change to V_LIGHT if you use S_LIGHT in presentation below
                          MyMessage msg(CHILD_ID_D1,V_TRIPPED);
                          MyMessage triggerMsg(CHILD_ID_S1,V_TRIPPED);
                          MyMessage tempMsg(CHILD_ID_T1,V_TEMP);
                          
                          void setup()
                          {
                          	// Startup OneWire Temp Sensors
                              DallasSensors.begin();
                              DallasSensors.setWaitForConversion(false);
                          
                          	// Initialize library and add callback for incoming messages
                          	 gw.begin(NULL, AUTO, true);
                          	
                          	// Send the sketch version information to the gateway and Controller
                          	gw.sendSketchInfo("Multi Sensor", "1.1");
                          
                          	// Register all sensors to gw (they will be created as child devices)
                          	gw.present(CHILD_ID_D1, S_DOOR);
                          	gw.present(CHILD_ID_T1, S_TEMP);
                          	gw.present(CHILD_ID_S1, S_MOTION);
                          
                          	// Setup the button
                                  pinMode(BUTTON_PIN,INPUT);
                                  // Activate internal pull-up
                                  digitalWrite(BUTTON_PIN,HIGH);
                            
                                  // After setting up the button, setup debouncer
                                  debouncer.attach(BUTTON_PIN);
                                  debouncer.interval(5);
                            
                                  // Register binary input sensor to gw (they will be created as child devices)
                                  // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                                  // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                          	
                          }
                          
                          
                          void loop()
                          {
                          	// Alway process incoming messages whenever possible
                          	gw.process();
                          	
                          	
                          	// Check for motion change value
                          		boolean tripped = digitalRead(TRIGGER) == HIGH; 
                          
                          		if (lastTripped != tripped ) {
                          			gw.send(triggerMsg.set(tripped?"1":"0")); // Send new state and request ack back
                          			Serial.println("Tripped");
                          			lastTripped=tripped;
                          		}
                          		
                          	//  Check if digital input has changed and send in new value
                                          debouncer.update();
                                        // Get the update value
                                          int value = debouncer.read();
                           
                                          if (value != oldValue) {
                                              // Send in the new value
                                               gw.send(msg.set(value==HIGH ? 1 : 0));
                                               oldValue = value;
                                          }
                                          
                              DallasSensors.requestTemperatures(); // no delay here
                              gw.wait(750); // insert another value for non-12-bit resolution
                              float tempC = DallasSensors.getTempCByIndex(1);
                              
                              // Only send data if temperature has changed and no error
                              if (lastTemperature != tempC && tempC != -127.00) {
                                
                                // Send in the new temperature
                                gw.send(tempMsg.set(tempC,1));
                                lastTemperature=tempC;
                                             }    		
                          
                          }
                          
                          1 Reply Last reply
                          0
                          • BulldogLowellB Offline
                            BulldogLowellB Offline
                            BulldogLowell
                            Contest Winner
                            wrote on last edited by
                            #31

                            @CaptainZap

                            what does the Serial output show during execution of the sketch?

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

                              @BulldogLowell Unfortunately I don't have a way to test that yet... I'm uploading the sketch using an arduino uno, and I have no idea how to do that with it. I do have an FTDI serial adapter but is not picked up by the IDE, it was at some point but no longer... probably fake :|

                              1 Reply Last reply
                              0
                              • m26872M Offline
                                m26872M Offline
                                m26872
                                Hardware Contributor
                                wrote on last edited by
                                #33

                                I don't know what's the issue, but I'd still prefer a normal timing code instead of just the gw.wait(). The fetching of temperatures in every loop makes no sense to me.

                                CaptainZapC 1 Reply Last reply
                                0
                                • m26872M m26872

                                  I don't know what's the issue, but I'd still prefer a normal timing code instead of just the gw.wait(). The fetching of temperatures in every loop makes no sense to me.

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

                                  @m26872 If you have time, could you please tell me how to do that, I know you've posted a link a few post back but I didn't do much with it :(

                                  R 1 Reply Last reply
                                  0
                                  • CaptainZapC CaptainZap

                                    @m26872 If you have time, could you please tell me how to do that, I know you've posted a link a few post back but I didn't do much with it :(

                                    R Offline
                                    R Offline
                                    robosensor
                                    wrote on last edited by robosensor
                                    #35

                                    @CaptainZap You should not query dallas sensor temperature every 750 ms. This heats up sensor itself and quite useless.

                                    Use something like this:

                                    unsigned long SLEEP_TIME = 30000; // Sleep time between reports (in milliseconds)
                                    unsigned long lastRefreshTime = 0;
                                    
                                    void loop()
                                    {
                                    	gw.wait(100);
                                      
                                    	boolean bNeedRefresh = (millis() - lastRefreshTime) > SLEEP_TIME;
                                    	if (bNeedRefresh)
                                    	{
                                    		lastRefreshTime = millis();
                                    
                                    		DallasSensors.requestTemperatures();
                                    		gw.wait(750);
                                    		float tempC = DallasSensors.getTempCByIndex(1);
                                    		float difference = lastTemperature - tempC;
                                    		if (tempC != -127.00 && abs(difference) > 0.5)
                                    		{
                                    			// Send in the new temperature
                                    			gw.send(tempMsg.set(tempC, 1));
                                    			lastTemperature = tempC;
                                    		}
                                    	}
                                    }
                                    
                                    CaptainZapC 1 Reply Last reply
                                    0
                                    • R robosensor

                                      @CaptainZap You should not query dallas sensor temperature every 750 ms. This heats up sensor itself and quite useless.

                                      Use something like this:

                                      unsigned long SLEEP_TIME = 30000; // Sleep time between reports (in milliseconds)
                                      unsigned long lastRefreshTime = 0;
                                      
                                      void loop()
                                      {
                                      	gw.wait(100);
                                        
                                      	boolean bNeedRefresh = (millis() - lastRefreshTime) > SLEEP_TIME;
                                      	if (bNeedRefresh)
                                      	{
                                      		lastRefreshTime = millis();
                                      
                                      		DallasSensors.requestTemperatures();
                                      		gw.wait(750);
                                      		float tempC = DallasSensors.getTempCByIndex(1);
                                      		float difference = lastTemperature - tempC;
                                      		if (tempC != -127.00 && abs(difference) > 0.5)
                                      		{
                                      			// Send in the new temperature
                                      			gw.send(tempMsg.set(tempC, 1));
                                      			lastTemperature = tempC;
                                      		}
                                      	}
                                      }
                                      
                                      CaptainZapC Offline
                                      CaptainZapC Offline
                                      CaptainZap
                                      wrote on last edited by
                                      #36

                                      @robosensor Thanks so much, I highly appreciate your comments. Will test this tomorrow, and hopefully, soon share my hardware designs :D

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

                                        Just uploaded the new sketch to my nodes, one built on a pro mini, and one built on a nano (got one to view serial output), however both nodes have the same behavior when added to the Vera unit... the repeater node doesn't show up (is this somehow related to UI7 ?), and the weird thing is that temperature value is never populated.

                                        Regarding the repeater, looking into the user_data output I can see that a repeater node is created, but it's not used as a parent device for the sensors... as all sensors have as parent the gateway. I'm using this version of the plugin :
                                        https://github.com/mysensors/Vera/tree/UI7

                                        This is the serial monitor output from the nano :

                                        repeater started, id 13
                                        send: 13-13-1-0 s=255,c=0,t=18,pt=0,l=5,st=ok:1.4.1
                                        send: 13-13-1-0 s=255,c=3,t=6,pt=1,l=1,st=ok:1
                                        send: 13-13-1-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Multi Sensor
                                        send: 13-13-1-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.1
                                        send: 13-13-1-0 s=1,c=0,t=0,pt=0,l=0,st=ok:
                                        send: 13-13-1-0 s=3,c=0,t=6,pt=0,l=0,st=ok:
                                        send: 13-13-1-0 s=2,c=0,t=1,pt=0,l=0,st=ok:
                                        send: 13-13-1-0 s=1,c=1,t=16,pt=2,l=2,st=ok:0
                                        

                                        This is the updated sketch:

                                        //This sketch is for Door & Motion & Temp Sensor
                                        //rev3 - changed temp pin to 5 & temperature logic re-worked
                                        
                                        
                                        #include <MySensor.h>
                                        #include <SPI.h>
                                        #include <DallasTemperature.h>
                                        #include <OneWire.h>
                                        #include <Bounce2.h>
                                        
                                        #define CLIENT_ID AUTO  // Sets MYSensors client id
                                        #define RADIO_CH 76  // Sets MYSensors to use Radio Channel
                                        #define TRIGGER	3	// used to connect motion sensor
                                        #define BUTTON_PIN  4 // used to connect door/window sensor
                                        
                                        //Temp Sensor bits
                                        #define ONE_WIRE_BUS 5 // Pin where dallas sensor is connected - on Rboard this is A0(D14)
                                        OneWire oneWire(ONE_WIRE_BUS);
                                        DallasTemperature DallasSensors(&oneWire);
                                        float lastTemperature ;
                                        #define CHILD_ID_T1 3 //CHILD ID for temp
                                        
                                        
                                        //Door/Window bits
                                        
                                        #define CHILD_ID_D1 1 //CHILD ID for door/window
                                        
                                        //Trigger Sensor Bits
                                        #define CHILD_ID_S1 2 //CHILD ID for Motion sensor
                                        boolean lastTripped = 0;
                                        
                                        unsigned long SLEEP_TIME = 30000; // Sleep time between reports (in milliseconds)
                                        unsigned long lastRefreshTime = 0;
                                        
                                        MySensor gw;
                                        
                                        Bounce debouncer = Bounce(); 
                                        int oldValue=-1;
                                        
                                        // Change to V_LIGHT if you use S_LIGHT in presentation below
                                        MyMessage msg(CHILD_ID_D1,V_TRIPPED);
                                        MyMessage triggerMsg(CHILD_ID_S1,V_TRIPPED);
                                        MyMessage tempMsg(CHILD_ID_T1,V_TEMP);
                                        
                                        void setup()
                                        {
                                        	// Startup OneWire Temp Sensors
                                            DallasSensors.begin();
                                            DallasSensors.setWaitForConversion(false);
                                        
                                        	// Initialize library and add callback for incoming messages
                                        	 gw.begin(NULL, AUTO, true);
                                        	
                                        	// Send the sketch version information to the gateway and Controller
                                        	gw.sendSketchInfo("Multi Sensor", "1.1");
                                        
                                        	// Register all sensors to gw (they will be created as child devices)
                                        	gw.present(CHILD_ID_D1, S_DOOR);
                                        	gw.present(CHILD_ID_T1, S_TEMP);
                                        	gw.present(CHILD_ID_S1, S_MOTION);
                                        
                                        	// Setup the button
                                                pinMode(BUTTON_PIN,INPUT);
                                                // Activate internal pull-up
                                                digitalWrite(BUTTON_PIN,HIGH);
                                          
                                                // After setting up the button, setup debouncer
                                                debouncer.attach(BUTTON_PIN);
                                                debouncer.interval(5);
                                          
                                                // Register binary input sensor to gw (they will be created as child devices)
                                                // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                                                // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                                        	
                                        }
                                        
                                        
                                        void loop()
                                        {
                                        	// Alway process incoming messages whenever possible
                                        	gw.process();
                                        	
                                        	
                                        	// Check for motion change value
                                        		boolean tripped = digitalRead(TRIGGER) == HIGH; 
                                        
                                        		if (lastTripped != tripped ) {
                                        			gw.send(triggerMsg.set(tripped?"1":"0")); // Send new state and request ack back
                                        			Serial.println("Tripped");
                                        			lastTripped=tripped;
                                        		}
                                        		
                                        	//  Check if digital input has changed and send in new value
                                                        debouncer.update();
                                                      // Get the update value
                                                        int value = debouncer.read();
                                         
                                                        if (value != oldValue) {
                                                            // Send in the new value
                                                             gw.send(msg.set(value==HIGH ? 1 : 0));
                                                             oldValue = value;
                                                        }
                                                        
                                            gw.wait(100);
                                          
                                            boolean bNeedRefresh = (millis() - lastRefreshTime) > SLEEP_TIME;
                                            if (bNeedRefresh)
                                            {
                                                lastRefreshTime = millis();
                                        
                                                DallasSensors.requestTemperatures();
                                                gw.wait(750);
                                                float tempC = DallasSensors.getTempCByIndex(1);
                                                float difference = lastTemperature - tempC;
                                                if (tempC != -127.00 && abs(difference) > 0.5)
                                                {
                                                    // Send in the new temperature
                                                    gw.send(tempMsg.set(tempC, 1));
                                                    lastTemperature = tempC;
                                                }
                                            }  		
                                        
                                        }
                                        

                                        Any feedback will be appreciated. Thanks.

                                        1 Reply Last reply
                                        0
                                        • hekH Offline
                                          hekH Offline
                                          hek
                                          Admin
                                          wrote on last edited by
                                          #38

                                          All devices has the gateway as parent (Vera does not support a multi-level device hierarchy).

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


                                          19

                                          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