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. Troubleshooting
  3. Door Window sensor consuming more power when closed

Door Window sensor consuming more power when closed

Scheduled Pinned Locked Moved Troubleshooting
10 Posts 2 Posters 7.3k Views 2 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.
  • I Offline
    I Offline
    iask
    wrote on last edited by
    #1

    I have a Door/Window/Switch sensor setup with a reed switch and magnet assembly. When open (magnet moved away) the device consumes 0.20mA, however, when closed the device consumes 0.97mA (uA). Is this normal?

    I modified the example to include an INTERRUPT.

    // Simple binary switch example 
    // Connect button or door/window reed switch between 
    // digitial I/O pin 3 (BUTTON_PIN below) and GND.
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define CHILD_ID 3
    #define BUTTON_PIN 3  // Arduino Digital I/O pin for button/reed switch
    #define INTERRUPT BUTTON_PIN-2
    
    MySensor gw;
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    void setup()  
    {  
      
      gw.begin();
    
     // 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.
      gw.present(CHILD_ID, S_DOOR);  
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      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.sleep(INTERRUPT,CHANGE, 0);
      }
     
    } ```
    AWIA 1 Reply Last reply
    0
    • I iask

      I have a Door/Window/Switch sensor setup with a reed switch and magnet assembly. When open (magnet moved away) the device consumes 0.20mA, however, when closed the device consumes 0.97mA (uA). Is this normal?

      I modified the example to include an INTERRUPT.

      // Simple binary switch example 
      // Connect button or door/window reed switch between 
      // digitial I/O pin 3 (BUTTON_PIN below) and GND.
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      #define CHILD_ID 3
      #define BUTTON_PIN 3  // Arduino Digital I/O pin for button/reed switch
      #define INTERRUPT BUTTON_PIN-2
      
      MySensor gw;
      Bounce debouncer = Bounce(); 
      int oldValue=-1;
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID,V_TRIPPED);
      
      void setup()  
      {  
        
        gw.begin();
      
       // 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.
        gw.present(CHILD_ID, S_DOOR);  
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop() 
      {
        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.sleep(INTERRUPT,CHANGE, 0);
        }
       
      } ```
      AWIA Offline
      AWIA Offline
      AWI
      Hero Member
      wrote on last edited by
      #2

      @iask (probable cause) You are using the internal pull-up of the Arduino. This is a resistor of around 20 k ohm link. If this is pulled to ground by the reed contact. I = U/R = 5/20.000 = 250 uA = 0.250 mA..

      Also: debouncer combined with sleep is guaranteed to give trouble. Sleep does also sleep the internal clock which is used by the debouncer class/ library.

      I 1 Reply Last reply
      0
      • I Offline
        I Offline
        iask
        wrote on last edited by iask
        #3

        @AWI thanks for responding. I will look into the internal pull-up. I did had some doubts with the debouncer. For example, putting the line gw.sleep(INTERRUPT,CHANGE, 0); outside of the IF statement caused the sensor to randomly drop messages to the GATEWAY. I did come across a post whereby someone used a delay instead of debouncing

        // Short delay to allow buttons to properly settle
         sensor_node.sleep(5);
        1 Reply Last reply
        0
        • AWIA AWI

          @iask (probable cause) You are using the internal pull-up of the Arduino. This is a resistor of around 20 k ohm link. If this is pulled to ground by the reed contact. I = U/R = 5/20.000 = 250 uA = 0.250 mA..

          Also: debouncer combined with sleep is guaranteed to give trouble. Sleep does also sleep the internal clock which is used by the debouncer class/ library.

          I Offline
          I Offline
          iask
          wrote on last edited by
          #4

          @AWI You are right about that internal pull-up. It got even worse when I added an external pull-up. I placed a 10k between pin 3 and GND (for the Door, Window example) and disabled the internal pull-up. When the reed contact is open the sensor pulls only 008.5 uA which is great! When the reed is closed it pulls a whopping 00.32 mA.

          I don't know what else to try to bring down that 00.32mA whenever the reed is closed (which will be most of the time because the window will be closed).

          I will look into hardware debouncing to see if that will be a solution for the reed switch.

          // Simple binary switch example 
          // Connect button or door/window reed switch between 
          // digitial I/O pin 3 (BUTTON_PIN below) and GND.
          
          #include <MySensor.h>
          #include <SPI.h>
          #include <Bounce2.h>
          
          
          #define CHILD_ID 3
          #define BUTTON_PIN 3  // Arduino Digital I/O pin for button/reed switch
          #define INTERRUPT BUTTON_PIN-2
          
          MySensor gw;
          Bounce debouncer = Bounce(); 
          int oldValue=-1;
          
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          MyMessage msg(CHILD_ID,V_TRIPPED);
          
          void setup()  
          {  
            gw.begin();
          
           // Setup the button
            pinMode(BUTTON_PIN,INPUT);
            // deActivate internal pull-up
            digitalWrite(BUTTON_PIN,LOW);
            
            // 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.
            gw.present(CHILD_ID, S_DOOR);  
          }
          
          
          //  Check if digital input has changed and send in new value
          void loop() 
          {
            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;
                 
               //Sleep until interrupt comes in on motion sensor. Send update every two minute. 
               //gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
                gw.sleep(INTERRUPT,CHANGE, 0);
            }
           
          } 
          
          
          AWIA 1 Reply Last reply
          0
          • I iask

            @AWI You are right about that internal pull-up. It got even worse when I added an external pull-up. I placed a 10k between pin 3 and GND (for the Door, Window example) and disabled the internal pull-up. When the reed contact is open the sensor pulls only 008.5 uA which is great! When the reed is closed it pulls a whopping 00.32 mA.

            I don't know what else to try to bring down that 00.32mA whenever the reed is closed (which will be most of the time because the window will be closed).

            I will look into hardware debouncing to see if that will be a solution for the reed switch.

            // Simple binary switch example 
            // Connect button or door/window reed switch between 
            // digitial I/O pin 3 (BUTTON_PIN below) and GND.
            
            #include <MySensor.h>
            #include <SPI.h>
            #include <Bounce2.h>
            
            
            #define CHILD_ID 3
            #define BUTTON_PIN 3  // Arduino Digital I/O pin for button/reed switch
            #define INTERRUPT BUTTON_PIN-2
            
            MySensor gw;
            Bounce debouncer = Bounce(); 
            int oldValue=-1;
            
            // Change to V_LIGHT if you use S_LIGHT in presentation below
            MyMessage msg(CHILD_ID,V_TRIPPED);
            
            void setup()  
            {  
              gw.begin();
            
             // Setup the button
              pinMode(BUTTON_PIN,INPUT);
              // deActivate internal pull-up
              digitalWrite(BUTTON_PIN,LOW);
              
              // 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.
              gw.present(CHILD_ID, S_DOOR);  
            }
            
            
            //  Check if digital input has changed and send in new value
            void loop() 
            {
              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;
                   
                 //Sleep until interrupt comes in on motion sensor. Send update every two minute. 
                 //gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
                  gw.sleep(INTERRUPT,CHANGE, 0);
              }
             
            } 
            
            
            AWIA Offline
            AWIA Offline
            AWI
            Hero Member
            wrote on last edited by AWI
            #5

            @iask try a 1 Mohm pull up and disable the internal. Hardware debounce is the way to go. Add 100nF to ground and 10k in series with the contact.

            1 Reply Last reply
            0
            • I Offline
              I Offline
              iask
              wrote on last edited by
              #6

              I tried that with the code below but it doesn't work at all. It registers the first 0 status with the Gateway and then goes silent.

              // Simple binary switch example 
              // Connect button or door/window reed switch between 
              // digitial I/O pin 3 (BUTTON_PIN below) and GND.
              
              #include <MySensor.h>
              #include <SPI.h>
              //#include <Bounce2.h>
              
              
              #define CHILD_ID 3
              #define BUTTON_PIN 3  // Arduino Digital I/O pin for button/reed switch
              #define INTERRUPT BUTTON_PIN-2
              
              //const byte switchPin = 3;
              byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
              
              
              MySensor gw;
              
              // Change to V_LIGHT if you use S_LIGHT in presentation below
              MyMessage msg(CHILD_ID,V_TRIPPED);
              
              void setup()  
              {  
                  for (byte i = 0; i <= A5; i++)
                  {
                  pinMode (i, INPUT);
                  digitalWrite (i, LOW);
                  }
                
                gw.begin();
              
               // Setup the button
                pinMode(BUTTON_PIN,INPUT);
                // Activate internal pull-up
                //digitalWrite(BUTTON_PIN,LOW);
                
                // 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.
                gw.present(CHILD_ID, S_DOOR);  
              }
              
              
              //  Check if digital input has changed and send in new value
              void loop() 
              {
                
                
                 // see if switch is open or closed
                byte switchState = digitalRead (BUTTON_PIN);
                
                 // has it changed since last time?
                if (switchState != oldSwitchState)
                  {
                   
                     oldSwitchState =  switchState;  // remember for next time 
                     
                     if (switchState == LOW)
                        {
                         gw.send(msg.set(0));
                        } 
                     else
                        {
                        gw.send(msg.set(1));
                        }
                       
                       gw.sleep(INTERRUPT,CHANGE, 0); 
                         
                     }  
                  }
              
              AWIA 1 Reply Last reply
              0
              • I iask

                I tried that with the code below but it doesn't work at all. It registers the first 0 status with the Gateway and then goes silent.

                // Simple binary switch example 
                // Connect button or door/window reed switch between 
                // digitial I/O pin 3 (BUTTON_PIN below) and GND.
                
                #include <MySensor.h>
                #include <SPI.h>
                //#include <Bounce2.h>
                
                
                #define CHILD_ID 3
                #define BUTTON_PIN 3  // Arduino Digital I/O pin for button/reed switch
                #define INTERRUPT BUTTON_PIN-2
                
                //const byte switchPin = 3;
                byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
                
                
                MySensor gw;
                
                // Change to V_LIGHT if you use S_LIGHT in presentation below
                MyMessage msg(CHILD_ID,V_TRIPPED);
                
                void setup()  
                {  
                    for (byte i = 0; i <= A5; i++)
                    {
                    pinMode (i, INPUT);
                    digitalWrite (i, LOW);
                    }
                  
                  gw.begin();
                
                 // Setup the button
                  pinMode(BUTTON_PIN,INPUT);
                  // Activate internal pull-up
                  //digitalWrite(BUTTON_PIN,LOW);
                  
                  // 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.
                  gw.present(CHILD_ID, S_DOOR);  
                }
                
                
                //  Check if digital input has changed and send in new value
                void loop() 
                {
                  
                  
                   // see if switch is open or closed
                  byte switchState = digitalRead (BUTTON_PIN);
                  
                   // has it changed since last time?
                  if (switchState != oldSwitchState)
                    {
                     
                       oldSwitchState =  switchState;  // remember for next time 
                       
                       if (switchState == LOW)
                          {
                           gw.send(msg.set(0));
                          } 
                       else
                          {
                          gw.send(msg.set(1));
                          }
                         
                         gw.sleep(INTERRUPT,CHANGE, 0); 
                           
                       }  
                    }
                
                AWIA Offline
                AWIA Offline
                AWI
                Hero Member
                wrote on last edited by
                #7

                @iask Are you measuring a transition on the input? You need the external pull-up at minimum.

                I 2 Replies Last reply
                0
                • AWIA AWI

                  @iask Are you measuring a transition on the input? You need the external pull-up at minimum.

                  I Offline
                  I Offline
                  iask
                  wrote on last edited by iask
                  #8

                  @AWI right on! I had some time to go at this again. I realized that I had soldered the pullup on the wrong pin. Right after that my fine 898+ station stopped working. It just wont get hot. Going old school for the next few days.

                  1 Reply Last reply
                  0
                  • AWIA AWI

                    @iask Are you measuring a transition on the input? You need the external pull-up at minimum.

                    I Offline
                    I Offline
                    iask
                    wrote on last edited by iask
                    #9

                    @AWI So here is what I got. When the sensor (Reed Switch) is open, the sensor consumes 8.5uA and when closed it consumes 11.5uA.

                    • I still have the regulator on board

                    • I removed both LEDS

                    • I am using hardware debouncing

                    • Set Analog pins LOW

                    Were you able to get lower than 11.5uA, with your NRFXXXXX connected, when in sleep mode? I am trying to find a proper benchmark to work with. My sensor is powered with a 3V CR123A battery.

                    I find that the CR123A is used in sensors by some alarm companies here in the US. See page 10 here (I've seen these things last a long time...3 years in some cases) so I am using this as my battery benchmark for all my sensors. Definitely not the cheepies from China.

                    AWIA 1 Reply Last reply
                    0
                    • I iask

                      @AWI So here is what I got. When the sensor (Reed Switch) is open, the sensor consumes 8.5uA and when closed it consumes 11.5uA.

                      • I still have the regulator on board

                      • I removed both LEDS

                      • I am using hardware debouncing

                      • Set Analog pins LOW

                      Were you able to get lower than 11.5uA, with your NRFXXXXX connected, when in sleep mode? I am trying to find a proper benchmark to work with. My sensor is powered with a 3V CR123A battery.

                      I find that the CR123A is used in sensors by some alarm companies here in the US. See page 10 here (I've seen these things last a long time...3 years in some cases) so I am using this as my battery benchmark for all my sensors. Definitely not the cheepies from China.

                      AWIA Offline
                      AWIA Offline
                      AWI
                      Hero Member
                      wrote on last edited by
                      #10

                      @iask I am not able to measure anything accurate that low. I use the chargeable version of cr123 in many sensors. No long term results yet, but a lot of power

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


                      21

                      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