Door Window sensor consuming more power when closed



  • 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);
      }
     
    } ```

  • Hero Member

    @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.



  • @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);


  • @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);
      }
     
    } 
    
    

  • Hero Member

    @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.



  • 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); 
               
           }  
        }
    

  • Hero Member

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



  • @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.



  • @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.


  • Hero Member

    @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


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts