Skip to content
  • 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. Development
  3. Low power battery Door/Window sketch nrf24l01
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Low power battery Door/Window sketch nrf24l01

Scheduled Pinned Locked Moved Development
21 Posts 7 Posters 10.2k Views 5 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.
  • L LastSamurai

    @warmaniac said in Low power battery Door/Window sketch nrf24l01:

    I'm not having problem with my hardware with other sensors which sleeps every 2 minutes. Same hardware lasts on 1 % battery for 2 weeks , it is good result for me . I only want to know if is better sketch for battery powered door sensor which is based on interrupts wake up from sleep. It will be much better for battery.

    Then why don't you just use the sketch I linked to? Or simply add the parts you need (mainly sleep()) to your sketch?

    warmaniacW Offline
    warmaniacW Offline
    warmaniac
    wrote on last edited by
    #12

    @LastSamurai

    I tryied , many times and changes in sketch but im failed, not waking up on interrupts , im not programmer maybe if I know better C langauge. :( Im using DIGITAL PIN 3 for magnetic sensor input.

    1 Reply Last reply
    0
    • warmaniacW Offline
      warmaniacW Offline
      warmaniac
      wrote on last edited by
      #13

      I don't know if this is correct sketch but now working on interrupts , take a look please

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * DESCRIPTION
       *
       * Simple binary switch example 
       * Connect button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND.
       * http://www.mysensors.org/build/binary
       */
      
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define CHILD_ID 3
      #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
      
      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()  
      {  
        // 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);
      
      }
      
      void presentation() {
        // 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.
        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
           send(msg.set(value==HIGH ? 1 : 0));
           oldValue = value;
        }
      sleep(digitalPinToInterrupt(BUTTON_PIN)-2, CHANGE, 0);
      }```
      AWIA 1 Reply Last reply
      0
      • M Offline
        M Offline
        mortommy
        wrote on last edited by
        #14

        Hi,
        I have some Door/window sensors, powered by a cr2032 coin battery and I was able to run them for 1 year. The sketch above it seems ok, but the secret it's not only the software, it depends on hardware too:

        • remove voltage regulator and led from the arduino
        • choose a ceramic decoupling capacitor for your radio module, and avoid electrolytic capacitors (they have a bigger leakage current)
        • I don't use any step-up converter, and use the battery to power both the radio module and arduino (reported both to work at 3V)
        • a capacitor (again ceramic) of 100uF across the cell’s terminals could sustain a peak current load.

        It's also better to avoid messages sending in a short time, and put some sleep in the middle, but I don't see that situation in the sketch.

        warmaniacW 1 Reply Last reply
        2
        • M mortommy

          Hi,
          I have some Door/window sensors, powered by a cr2032 coin battery and I was able to run them for 1 year. The sketch above it seems ok, but the secret it's not only the software, it depends on hardware too:

          • remove voltage regulator and led from the arduino
          • choose a ceramic decoupling capacitor for your radio module, and avoid electrolytic capacitors (they have a bigger leakage current)
          • I don't use any step-up converter, and use the battery to power both the radio module and arduino (reported both to work at 3V)
          • a capacitor (again ceramic) of 100uF across the cell’s terminals could sustain a peak current load.

          It's also better to avoid messages sending in a short time, and put some sleep in the middle, but I don't see that situation in the sketch.

          warmaniacW Offline
          warmaniacW Offline
          warmaniac
          wrote on last edited by
          #15

          @mortommy

          Thanks for you reply !
          Apologize me, if I mistaken , but ceramic capacitors in values 100 uF was only SMD? That can't I solder yet. :(

          Nca78N 1 Reply Last reply
          0
          • warmaniacW warmaniac

            I don't know if this is correct sketch but now working on interrupts , take a look please

            /**
             * The MySensors Arduino library handles the wireless radio link and protocol
             * between your home built sensors/actuators and HA controller of choice.
             * The sensors forms a self healing radio network with optional repeaters. Each
             * repeater and gateway builds a routing tables in EEPROM which keeps track of the
             * network topology allowing messages to be routed to nodes.
             *
             * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
             * Copyright (C) 2013-2015 Sensnology AB
             * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
             *
             * Documentation: http://www.mysensors.org
             * Support Forum: http://forum.mysensors.org
             *
             * This program is free software; you can redistribute it and/or
             * modify it under the terms of the GNU General Public License
             * version 2 as published by the Free Software Foundation.
             *
             *******************************
             *
             * DESCRIPTION
             *
             * Simple binary switch example 
             * Connect button or door/window reed switch between 
             * digitial I/O pin 3 (BUTTON_PIN below) and GND.
             * http://www.mysensors.org/build/binary
             */
            
            
            // Enable debug prints to serial monitor
            #define MY_DEBUG 
            
            // Enable and select radio type attached
            #define MY_RADIO_NRF24
            //#define MY_RADIO_RFM69
            
            #include <SPI.h>
            #include <MySensors.h>
            #include <Bounce2.h>
            
            #define CHILD_ID 3
            #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
            
            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()  
            {  
              // 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);
            
            }
            
            void presentation() {
              // 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.
              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
                 send(msg.set(value==HIGH ? 1 : 0));
                 oldValue = value;
              }
            sleep(digitalPinToInterrupt(BUTTON_PIN)-2, CHANGE, 0);
            }```
            AWIA Offline
            AWIA Offline
            AWI
            Hero Member
            wrote on last edited by
            #16

            @warmaniac Using debounce with a sleeping node is rather useless. Sleep() halts the millis() timer which is used by debounce. You can just sleep(100) a few ms before entering the interrupt sleep.

            warmaniacW 1 Reply Last reply
            0
            • AWIA AWI

              @warmaniac Using debounce with a sleeping node is rather useless. Sleep() halts the millis() timer which is used by debounce. You can just sleep(100) a few ms before entering the interrupt sleep.

              warmaniacW Offline
              warmaniacW Offline
              warmaniac
              wrote on last edited by
              #17

              @AWI

              if I understand correctly you mean like this ?

              void loop() 
              {
                debouncer.update();
                // Get the update value
                int value = debouncer.read();
              
                if (value != oldValue) {
                   // Send in the new value
                   send(msg.set(value==HIGH ? 1 : 0));
                   oldValue = value;
                }
              sleep(200);
              sleep(digitalPinToInterrupt(BUTTON_PIN)-2, CHANGE, 0);
              }
              
              

              Wouldn't be delay(200) doing same function ?

              AWIA 1 Reply Last reply
              0
              • warmaniacW warmaniac

                @AWI

                if I understand correctly you mean like this ?

                void loop() 
                {
                  debouncer.update();
                  // Get the update value
                  int value = debouncer.read();
                
                  if (value != oldValue) {
                     // Send in the new value
                     send(msg.set(value==HIGH ? 1 : 0));
                     oldValue = value;
                  }
                sleep(200);
                sleep(digitalPinToInterrupt(BUTTON_PIN)-2, CHANGE, 0);
                }
                
                

                Wouldn't be delay(200) doing same function ?

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

                @warmaniac delay() does the same thing but does not turn down the power. You can just skip the debouncer stuff.

                1 Reply Last reply
                0
                • warmaniacW warmaniac

                  @mortommy

                  Thanks for you reply !
                  Apologize me, if I mistaken , but ceramic capacitors in values 100 uF was only SMD? That can't I solder yet. :(

                  Nca78N Offline
                  Nca78N Offline
                  Nca78
                  Hardware Contributor
                  wrote on last edited by Nca78
                  #19

                  @warmaniac said in Low power battery Door/Window sketch nrf24l01:

                  Apologize me, if I mistaken , but ceramic capacitors in values 100 uF was only SMD? That can't I solder yet. :(

                  Honestly it's really not a problem to solder those, not long ago (just over a couple of months :) ) I was afraid of SMD soldering and now after only a bit of training it's very easy if you stick to "big" sized SMD components or radios with castellated pins.
                  But even smaller size gets easy when you learn the right method, I soldered my first SMD atmega328 a few weeks ago and it is running fine :)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mortommy
                    wrote on last edited by
                    #20

                    I want also to specify that my sensor was running under library 1.5.4. At the moment I'm experiencing an issue under the library 2.1.1 that makes the sensor continuously wake up, so the battery discharges itself after few hours. Better under library 2.0.0 but the initialization process has many transmissions failure that give to the battery a heavy blow.

                    warmaniacW 1 Reply Last reply
                    1
                    • M mortommy

                      I want also to specify that my sensor was running under library 1.5.4. At the moment I'm experiencing an issue under the library 2.1.1 that makes the sensor continuously wake up, so the battery discharges itself after few hours. Better under library 2.0.0 but the initialization process has many transmissions failure that give to the battery a heavy blow.

                      warmaniacW Offline
                      warmaniacW Offline
                      warmaniac
                      wrote on last edited by warmaniac
                      #21

                      @mortommy

                      YES !!! That's it !!! But it is fatal error , because i use step up booster and when battery goes down , It caused that arduino start / shutdown quickly , it spams my Gateway I must disconnect it .

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


                      15

                      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
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular