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.
  • 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
            • CaptainZapC Offline
              CaptainZapC Offline
              CaptainZap
              wrote on last edited by
              #39

              Can anyone share their thoughts ? I've been running two identical nodes, with no temperature output for a few days now :(

              DwaltD 1 Reply Last reply
              0
              • CaptainZapC CaptainZap

                Can anyone share their thoughts ? I've been running two identical nodes, with no temperature output for a few days now :(

                DwaltD Offline
                DwaltD Offline
                Dwalt
                wrote on last edited by
                #40

                @CaptainZap Did you delete the original devices from Vera after you changed the code? I had something similar happen when I rewrote a sketch to modify battery monitoring and Vera would not show the new data. I deleted the node and child devices and reincluded them from scratch and then it worked.

                Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

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

                  I think you have to redo inclusion of the sensors if you want them to use the repater in their routing. At least it looks like this when I setup my Vera and sensors.

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

                    @Dwalt @m26872 Thanks for the feedback, I did do that on the Vera unit. I've even removed the plugin files and re-did everything. I even, and this is a bit extreme, cleared the eprom on the gateway and reflashed it. None of it worked, I really have no clue what to do next. I'm open to every suggestion :D

                    DwaltD 1 Reply Last reply
                    0
                    • CaptainZapC CaptainZap

                      @Dwalt @m26872 Thanks for the feedback, I did do that on the Vera unit. I've even removed the plugin files and re-did everything. I even, and this is a bit extreme, cleared the eprom on the gateway and reflashed it. None of it worked, I really have no clue what to do next. I'm open to every suggestion :D

                      DwaltD Offline
                      DwaltD Offline
                      Dwalt
                      wrote on last edited by
                      #43

                      @CaptainZap It your sketch you have this line:
                      #define ONE_WIRE_BUS 14

                      What pin is your Dallas sensor connected to?

                      Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

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

                        First make sure a pure repeater node is working. With only the gw.process() to run, it should be fast to enough catch any new inlusion before the gateway. With a proper range of course. Clear the sensors eeprom and Vera-device before reinclusion, but you should not need to do anything with the gateway.

                        1 Reply Last reply
                        0
                        • DwaltD Dwalt

                          @CaptainZap It your sketch you have this line:
                          #define ONE_WIRE_BUS 14

                          What pin is your Dallas sensor connected to?

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

                          @Dwalt said:

                          @CaptainZap It your sketch you have this line:
                          #define ONE_WIRE_BUS 14

                          What pin is your Dallas sensor connected to?

                          One sensor is connected to A0(14) the other is connected to D5 as it can be seen in my last sketch. Temperature reporting worked on, in my original sketch, however the sketch wasn't perfect so I improved it based on feedback.

                          @m26872 The sensor is on a breadboard 5cm from the gateway, and I'm not sure about the repeater part...

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

                            Well since nobody knew what the problem is I thought I would re-flash my first sketch which was working properly... however after doing it it no longer works... this is blowing my mind away. I don't understand why that would be, as the only changes I've done are listed in this thread, major one was that I upgraded lib to 1.4.1 from 1.4. Anyone has any ideas cause this is driving me crazy now :(

                            Moshe LivneM 1 Reply Last reply
                            0
                            • CaptainZapC CaptainZap

                              Well since nobody knew what the problem is I thought I would re-flash my first sketch which was working properly... however after doing it it no longer works... this is blowing my mind away. I don't understand why that would be, as the only changes I've done are listed in this thread, major one was that I upgraded lib to 1.4.1 from 1.4. Anyone has any ideas cause this is driving me crazy now :(

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

                              @CaptainZap would suggest to clear the eeprom

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

                                Did you ever get a repeater-only node to work in your mys network ?

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

                                  @Moshe-Livne @m26872 : I did clear the eprom, I've tried everything I could think of... I'm not quite sure if the repeater works, so far everything is at the breadboard state, so I was pretty much prototyping.

                                  Moshe LivneM 1 Reply Last reply
                                  0
                                  • CaptainZapC CaptainZap

                                    @AWI Yes I want all my nodes to be repeaters, and that's exactly what I want to do :) However I use a Vera as my controller, and there you are supposed to have a parent node for your arduino sensor, followed by child devices for sensors/relays etc. Right now I have 3 child devices for the My Sensors plugin which isn't right.

                                    m26872M Offline
                                    m26872M Offline
                                    m26872
                                    Hardware Contributor
                                    wrote on last edited by
                                    #50

                                    @CaptainZap said:

                                    @AWI Yes I want all my nodes to be repeaters,

                                    Why?
                                    Unless you plan expand your network in the near future, think the increased complexity just will give you trouble.

                                    1 Reply Last reply
                                    0
                                    • CaptainZapC CaptainZap

                                      @Moshe-Livne @m26872 : I did clear the eprom, I've tried everything I could think of... I'm not quite sure if the repeater works, so far everything is at the breadboard state, so I was pretty much prototyping.

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

                                      @CaptainZap did you clear the eeprom before loading the sketch that used to work?

                                      1 Reply Last reply
                                      0
                                      • petoulachiP Offline
                                        petoulachiP Offline
                                        petoulachi
                                        wrote on last edited by petoulachi
                                        #52

                                        Hello,

                                        I've read this thread with interest because I want to make my Motion/Temp sensor using Dallas.

                                        Adapting the given code was quite easy (well I guess as I have not tested it for now :D ), I only have changed gw.wait with gw.sleep, because if I understand it correctly, gw.sleep put the sensor in sleep mode which is a bit better for battery :

                                        #include <MySensor.h>  
                                        #include <SPI.h>
                                        #include <DallasTemperature.h>
                                        #include <OneWire.h>
                                        
                                        #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)
                                        #define CHILD_ID_S1 1   // Id of the sensor child
                                        
                                        
                                        #define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected 
                                        #define CHILD_ID_T1 2 //CHILD ID for temp
                                        
                                        
                                        OneWire oneWire(ONE_WIRE_BUS);
                                        DallasTemperature DallasSensors(&oneWire);
                                        float lastTemperature ;
                                        unsigned long SLEEP_TIME = 30000; // Sleep time between reports (in milliseconds)
                                        unsigned long lastRefreshTime = 0;
                                        boolean lastTripped = 0;
                                        
                                        MySensor gw;
                                        // Initialize motion message
                                        MyMessage motionMsg(CHILD_ID_S1, V_TRIPPED);
                                        MyMessage tempMsg(CHILD_ID_T1,V_TEMP);
                                        
                                        void setup()  
                                        {  
                                           // Startup OneWire Temp Sensors
                                            DallasSensors.begin();
                                            DallasSensors.setWaitForConversion(false);
                                        
                                          gw.begin();
                                        
                                          // Send the sketch version information to the gateway and Controller
                                          gw.sendSketchInfo("Motion and Temperature Sensor", "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_S1, S_MOTION);
                                          gw.present(CHILD_ID_T1, S_TEMP);
                                          
                                        }
                                        
                                        void loop()     
                                        {
                                        	// Process incoming messages (like config from server)
                                        	gw.process();
                                        	
                                        	// Read digital motion value
                                        	boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                                        
                                        	if (lastTripped != tripped ) 
                                        	{
                                        		Serial.println("Tripped");
                                        		gw.send(motionMsg.set(tripped?"1":"0")); // Send tripped value to gw 
                                        		lastTripped=tripped;
                                        	}
                                        
                                        	boolean bNeedRefresh = (millis() - lastRefreshTime) > SLEEP_TIME;
                                        	if (bNeedRefresh)
                                        	{
                                        		lastRefreshTime = millis();
                                        		DallasSensors.requestTemperatures();
                                        		
                                        		gw.sleep(750);
                                        		float tempC = DallasSensors.getTempCByIndex(1);
                                        		float difference = lastTemperature - tempC;
                                        		if (tempC != -127.00 && abs(difference) > 0.1)
                                        		{
                                        			// Send in the new temperature
                                        			gw.send(tempMsg.set(tempC, 1));
                                        			lastTemperature = tempC;
                                        		}
                                        	}
                                        	else
                                        	{
                                        		gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
                                        	}
                                        }
                                        
                                        
                                        

                                        But I'm concerned about thoses particular lines :

                                        lastRefreshTime = millis();
                                        		DallasSensors.requestTemperatures();
                                        		
                                        		gw.sleep(750);
                                        		float tempC = DallasSensors.getTempCByIndex(1);
                                        

                                        Why do we need gw.sleep(750) ? My concern is, when the sensor tries to pull temperature, it could not trigger new motion state for at least 750ms ? This is a problem for me, as I want to use these sensor to trigger light when I come in the room, so I need it to be fast.

                                        Thanks !

                                        1 Reply Last reply
                                        0
                                        • 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
                                          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