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. gw.sleep on battery powered magnet door switch

gw.sleep on battery powered magnet door switch

Scheduled Pinned Locked Moved My Project
42 Posts 13 Posters 16.9k Views 16 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.
  • AWIA AWI

    @Chakkie Good to hear. Using "-3" makes the interrupt number the same for _Deur and _Post. Using -2 activates both interrupt 0 and 1.
    You'r ready for the next project..

    ChakkieC
    ChakkieC
    Chakkie
    wrote on last edited by
    #12

    @AWI Thanks. By the way would you care to explain the interrupt index number? or may be a link for explanation?

    Raspberry Pi 2
    Domoticz
    RFXCOM
    ZWAVE Aeon stick
    Coming soon Arduino mysensors GW

    AWIA 1 Reply Last reply
    0
    • ChakkieC Chakkie

      @AWI Thanks. By the way would you care to explain the interrupt index number? or may be a link for explanation?

      AWIA
      AWIA
      AWI
      Hero Member
      wrote on last edited by AWI
      #13

      @Chakkie In a few words.. The ATMEGA has two external interrupts 0 and 1 which are connected to pins 2 and 3. ("-2" translates the pin number to the interrupt number, which is rather confusing as @mfalkvidd meant)

      ChakkieC 1 Reply Last reply
      0
      • mfalkviddM mfalkvidd

        We should really get rid of the confusing "- 2" stuff in the examples and start using DigtalPinToInterrupt instead.
        I'm annoyed enough to see if I can create a pull request later this week.

        ChakkieC
        ChakkieC
        Chakkie
        wrote on last edited by
        #14

        @mfalkvidd Thanks for the info. Does DigitalPinTolnterrupt works better?

        Raspberry Pi 2
        Domoticz
        RFXCOM
        ZWAVE Aeon stick
        Coming soon Arduino mysensors GW

        1 Reply Last reply
        0
        • AWIA AWI

          @Chakkie In a few words.. The ATMEGA has two external interrupts 0 and 1 which are connected to pins 2 and 3. ("-2" translates the pin number to the interrupt number, which is rather confusing as @mfalkvidd meant)

          ChakkieC
          ChakkieC
          Chakkie
          wrote on last edited by
          #15

          @AWI Thanks this clear thinks up but at the same time also confusing too.

          So "-2" activates both 0 and 1 on pin 2 or pin 3 as you mentioned earlier. I always though it represents a pin number.

          Raspberry Pi 2
          Domoticz
          RFXCOM
          ZWAVE Aeon stick
          Coming soon Arduino mysensors GW

          AWIA 1 Reply Last reply
          0
          • ChakkieC Chakkie

            @AWI Thanks this clear thinks up but at the same time also confusing too.

            So "-2" activates both 0 and 1 on pin 2 or pin 3 as you mentioned earlier. I always though it represents a pin number.

            AWIA
            AWIA
            AWI
            Hero Member
            wrote on last edited by
            #16

            @Chakkie The function digitalPinToInterrupt(pin) translates the pin number to the attached interrupt like "-2" does but in a reliable and more understandable way.

            ChakkieC 1 Reply Last reply
            0
            • AWIA AWI

              @Chakkie The function digitalPinToInterrupt(pin) translates the pin number to the attached interrupt like "-2" does but in a reliable and more understandable way.

              ChakkieC
              ChakkieC
              Chakkie
              wrote on last edited by
              #17

              @AWI thanks. this looks like more promising.

              Raspberry Pi 2
              Domoticz
              RFXCOM
              ZWAVE Aeon stick
              Coming soon Arduino mysensors GW

              1 Reply Last reply
              0
              • mfalkviddM
                mfalkviddM
                mfalkvidd
                Mod
                wrote on last edited by
                #18

                Pull request done for the development version: https://github.com/mysensors/Arduino/pull/441

                1 Reply Last reply
                3
                • siodS
                  siodS
                  siod
                  wrote on last edited by
                  #19

                  I would like to build the same but I am still very confused now. Could you upload some pictures so I can make myself an image of how you wirde things together?

                  Also I don´t really understand what happens here: gw.sleep(BUTTON_PIN_Deur - 2, CHANGE, BUTTON_PIN_Post - 2, CHANGE, 86400000);

                  still learning...

                  AWIA 1 Reply Last reply
                  0
                  • siodS siod

                    I would like to build the same but I am still very confused now. Could you upload some pictures so I can make myself an image of how you wirde things together?

                    Also I don´t really understand what happens here: gw.sleep(BUTTON_PIN_Deur - 2, CHANGE, BUTTON_PIN_Post - 2, CHANGE, 86400000);

                    AWIA
                    AWIA
                    AWI
                    Hero Member
                    wrote on last edited by AWI
                    #20

                    @siod If you are using a "standard" Atmega328 (pro-mini, etc.) don't make it hard for yourself. This processor has two external interrupts (0 & 1) connected to pins 2 & 3. Taking your line of code gw.sleep(BUTTON_PIN_Deur - 2, CHANGE, BUTTON_PIN_Post - 2, CHANGE, 86400000); the arguments are respectively:

                    1. Use interrupt "0" (connected to pin 2 is BUTTON_PIN_Deur)
                    2. Have is fired on change (i.e Rising and Falling)
                    3. Use interrupt "1" (connected to pin 3 is BUTTON_PIN_Post)
                    4. Have is fired on change (i.e Rising and Falling)
                    5. Wake after every 86400000 ms (24 hrs) if no interrupt fired. To be safe you should use 86400000UL (the UL indicating that it is an Unsigned long type)
                    siodS 1 Reply Last reply
                    0
                    • AWIA AWI

                      @siod If you are using a "standard" Atmega328 (pro-mini, etc.) don't make it hard for yourself. This processor has two external interrupts (0 & 1) connected to pins 2 & 3. Taking your line of code gw.sleep(BUTTON_PIN_Deur - 2, CHANGE, BUTTON_PIN_Post - 2, CHANGE, 86400000); the arguments are respectively:

                      1. Use interrupt "0" (connected to pin 2 is BUTTON_PIN_Deur)
                      2. Have is fired on change (i.e Rising and Falling)
                      3. Use interrupt "1" (connected to pin 3 is BUTTON_PIN_Post)
                      4. Have is fired on change (i.e Rising and Falling)
                      5. Wake after every 86400000 ms (24 hrs) if no interrupt fired. To be safe you should use 86400000UL (the UL indicating that it is an Unsigned long type)
                      siodS
                      siodS
                      siod
                      wrote on last edited by
                      #21

                      @AWI
                      Ok thx for explanation, but that means he is using 2 reed switches, right (interrupt at pin2 and int pin3)?

                      still learning...

                      AWIA 1 Reply Last reply
                      0
                      • siodS siod

                        @AWI
                        Ok thx for explanation, but that means he is using 2 reed switches, right (interrupt at pin2 and int pin3)?

                        AWIA
                        AWIA
                        AWI
                        Hero Member
                        wrote on last edited by
                        #22

                        @siod I guess so. But don't ask me why. One should be sufficient to detect if the door is open :smile:

                        In addition (and for what it is worth). If you use a real low power circuit you can save around a factor 3 on battery lifetime when you get rid of the timed wakeup. The arduino sleeps a lot better when it doesn't have to look at the alarm clock every few ms :zzz:

                        siodS ChakkieC 2 Replies Last reply
                        0
                        • AWIA AWI

                          @siod I guess so. But don't ask me why. One should be sufficient to detect if the door is open :smile:

                          In addition (and for what it is worth). If you use a real low power circuit you can save around a factor 3 on battery lifetime when you get rid of the timed wakeup. The arduino sleeps a lot better when it doesn't have to look at the alarm clock every few ms :zzz:

                          siodS
                          siodS
                          siod
                          wrote on last edited by
                          #23

                          @AWI
                          yes, makes sense, but how should you do this wihout the wakeup ? I guess this is just the disadvantage one must accept...

                          still learning...

                          AWIA 1 Reply Last reply
                          0
                          • siodS siod

                            @AWI
                            yes, makes sense, but how should you do this wihout the wakeup ? I guess this is just the disadvantage one must accept...

                            AWIA
                            AWIA
                            AWI
                            Hero Member
                            wrote on last edited by
                            #24

                            @siod The wakeup function can be disabled by setting the timer values to 0 (or omitting it). There is no purpose in the sketch above for what I can see. If you want to have a kind of "hey I am still alive"/heartbeat feature you need to do a little more (e.g. sending battery level)

                            172pilot1 1 Reply Last reply
                            0
                            • AWIA AWI

                              @siod The wakeup function can be disabled by setting the timer values to 0 (or omitting it). There is no purpose in the sketch above for what I can see. If you want to have a kind of "hey I am still alive"/heartbeat feature you need to do a little more (e.g. sending battery level)

                              172pilot1
                              172pilot1
                              172pilot
                              wrote on last edited by
                              #25

                              @AWI I was going to ask about that.. I dont see any reason to wake up every 24 hours just to go back to sleep again.. I assume the radio doesn't have any reason to send a keepalive or anything? So, you can omit that number, and it will sleep until interrupted? That's cool..

                              -Steve

                              AWIA 1 Reply Last reply
                              0
                              • 172pilot1 172pilot

                                @AWI I was going to ask about that.. I dont see any reason to wake up every 24 hours just to go back to sleep again.. I assume the radio doesn't have any reason to send a keepalive or anything? So, you can omit that number, and it will sleep until interrupted? That's cool..

                                -Steve

                                AWIA
                                AWIA
                                AWI
                                Hero Member
                                wrote on last edited by
                                #26

                                @172pilot yes, no reason to wake up. Especially if there is a regular wake-up from interrupt to let the controller know it it is alive

                                1 Reply Last reply
                                0
                                • AWIA AWI

                                  @siod I guess so. But don't ask me why. One should be sufficient to detect if the door is open :smile:

                                  In addition (and for what it is worth). If you use a real low power circuit you can save around a factor 3 on battery lifetime when you get rid of the timed wakeup. The arduino sleeps a lot better when it doesn't have to look at the alarm clock every few ms :zzz:

                                  ChakkieC
                                  ChakkieC
                                  Chakkie
                                  wrote on last edited by Chakkie
                                  #27

                                  @AWI

                                  Thanks for the info. I thought you always have to add the sleep time to the gw.sleep. I will disable the a wake timer by removing the 86400000.

                                  @siod I use one switch for the letterbox and one for the door.

                                  Raspberry Pi 2
                                  Domoticz
                                  RFXCOM
                                  ZWAVE Aeon stick
                                  Coming soon Arduino mysensors GW

                                  1 Reply Last reply
                                  0
                                  • siodS
                                    siodS
                                    siod
                                    wrote on last edited by
                                    #28

                                    well, as you can see, if you don´t know the libraries exactly you accept things as they are or as they seem to be. I wasn´t aware that you can just set the wakeup function to 0. So this said I would like to thank you @AWI for your patience and your willingness of explaining also the most obvious things! :thumbsup:

                                    still learning...

                                    1 Reply Last reply
                                    1
                                    • T
                                      T
                                      treb0r
                                      wrote on last edited by
                                      #29

                                      The sketch works with both reeds switches (2 windows) but how to integreate it with DS18B20 temp sensor? I also power it with battery, so I would like to check the temp eg every 5min and if it is changed then send the new value to the controler. How to wake up arduino only if any window is opened or temp is changed (after 5 min)
                                      Thanks
                                      treb0r

                                      dynamiteD 172pilot1 2 Replies Last reply
                                      0
                                      • T treb0r

                                        The sketch works with both reeds switches (2 windows) but how to integreate it with DS18B20 temp sensor? I also power it with battery, so I would like to check the temp eg every 5min and if it is changed then send the new value to the controler. How to wake up arduino only if any window is opened or temp is changed (after 5 min)
                                        Thanks
                                        treb0r

                                        dynamiteD
                                        dynamiteD
                                        dynamite
                                        wrote on last edited by
                                        #30

                                        @treb0r You can either wake up on the interrupt or on a time period:

                                        bool sleep(int interrupt, int mode, unsigned long ms=0);

                                        interrupt - Interrupt that should trigger the wakeup.
                                        mode - RISING, FALLING, CHANGE
                                        ms - Number of milliseconds to sleep (or 0 to sleep forever).

                                        The sleep method returns true if wake up was triggered by pin change and false means timer woke it up.

                                        1 Reply Last reply
                                        0
                                        • T treb0r

                                          The sketch works with both reeds switches (2 windows) but how to integreate it with DS18B20 temp sensor? I also power it with battery, so I would like to check the temp eg every 5min and if it is changed then send the new value to the controler. How to wake up arduino only if any window is opened or temp is changed (after 5 min)
                                          Thanks
                                          treb0r

                                          172pilot1
                                          172pilot1
                                          172pilot
                                          wrote on last edited by
                                          #31

                                          @treb0r the problem is, you need to wake up the arduino to tell the temp sensor to take a new reading, so the best you can do is to trigger on the interrupts for the Windows and then use the timer to wake up and take the temperature reading, and then you'll have to compare to your saved value to decide whether it has been 5 degrees or not, so you can't completely sleep until that happens..

                                          1 Reply Last reply
                                          0

                                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                          With your input, this post could be even better 💗

                                          Register Login
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          13

                                          Online

                                          12.4k

                                          Users

                                          11.2k

                                          Topics

                                          113.5k

                                          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