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. Announcements
  3. 💬 Door, Window and Push-button Sensor

💬 Door, Window and Push-button Sensor

Scheduled Pinned Locked Moved Announcements
110 Posts 36 Posters 22.5k Views 32 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.
  • siodS Offline
    siodS Offline
    siod
    wrote on last edited by
    #7

    what is "debouncer" for? I removed it from my sketch and it still works...

    still learning...

    mfalkviddM 1 Reply Last reply
    0
    • siodS siod

      what is "debouncer" for? I removed it from my sketch and it still works...

      mfalkviddM Online
      mfalkviddM Online
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #8

      @siod when a switch is pressed it can bounce, which can look like several presses to the mcu. More information is available at http://www.allaboutcircuits.com/textbook/digital/chpt-4/contact-bounce/

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LastSamurai
        Hardware Contributor
        wrote on last edited by LastSamurai
        #9

        I did just build a similar sensor based on my small sensor node. I think the example code here isn't really perfect though (although its very basic, perhaps that was the only goal).

        As I wanted to use this with batteries I used an interrupt and sleep(). The deboucing library isn't really need, a short gw.wait(50); did it for me too.
        Here is my code (not yet updated to mysensors 2). Any comments? Perhaps we could update the example code too.

        1 Reply Last reply
        0
        • janvier123J Offline
          janvier123J Offline
          janvier123
          wrote on last edited by
          #10

          Dont forget to add a 10K resistor between GND and your PIN (in this example pin3)

          L 1 Reply Last reply
          0
          • janvier123J janvier123

            Dont forget to add a 10K resistor between GND and your PIN (in this example pin3)

            L Offline
            L Offline
            LastSamurai
            Hardware Contributor
            wrote on last edited by
            #11

            @janvier123 Do you really need that? Shouldn't the internal pullups be enough?

            pinMode(BUTTON_PIN,INPUT);
            // Activate internal pull-up
            digitalWrite(BUTTON_PIN,HIGH);
            
            1 Reply Last reply
            0
            • janvier123J Offline
              janvier123J Offline
              janvier123
              wrote on last edited by
              #12

              for some reason the value was always "1" untill i "pushed the button" => then i got "0"
              however ive added an 10K resistors between the pin and gnd, and now it works fine :)

              maybe because its not an official UNO board?

              1 Reply Last reply
              0
              • Meshx86M Offline
                Meshx86M Offline
                Meshx86
                wrote on last edited by
                #13

                i don't why, but debouncer.read(); always return 1, i was never able to send the status of the door, however, digitalRead(BUTTON_PIN) returns the actual value.

                since i am using this for reed switch, i believe i don't need the debouncing functionality do i ?

                Nca78N 1 Reply Last reply
                0
                • Meshx86M Meshx86

                  i don't why, but debouncer.read(); always return 1, i was never able to send the status of the door, however, digitalRead(BUTTON_PIN) returns the actual value.

                  since i am using this for reed switch, i believe i don't need the debouncing functionality do i ?

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

                  @Meshx86 said:

                  i don't why, but debouncer.read(); always return 1, i was never able to send the status of the door, however, digitalRead(BUTTON_PIN) returns the actual value.

                  since i am using this for reed switch, i believe i don't need the debouncing functionality do i ?

                  Hello,

                  yes you can get rid of the debouncing stuff for your reed switch (or any physical switch) if you are sleeping and waking up on interrupt, just add a little wait before you read the value to let the switch settle.
                  If you are running at 1MHz then the time to wake up from sleep is longer (45ms if I remember well) and you don't even need the sleep.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    thomas schneider
                    wrote on last edited by
                    #15

                    What is the way to put the sketch on a sensebender with battery powered ?

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      thomas schneider
                      wrote on last edited by
                      #16

                      Is the BinarySwitchSleepSensor a good answer ?

                      1 Reply Last reply
                      0
                      • JicJ Offline
                        JicJ Offline
                        Jic
                        wrote on last edited by
                        #17

                        @Meshx86

                        I have the same problem, when I use the bounce library to read my reed switch I always read "1". If I use digitalRead I get an bounce error.
                        I have an arduino compatible, configure it for 1Mhz, 1M resistor for the reed switch and 2 AA battery.
                        Someone has a similar one working?

                        Meshx86M 1 Reply Last reply
                        0
                        • JicJ Jic

                          @Meshx86

                          I have the same problem, when I use the bounce library to read my reed switch I always read "1". If I use digitalRead I get an bounce error.
                          I have an arduino compatible, configure it for 1Mhz, 1M resistor for the reed switch and 2 AA battery.
                          Someone has a similar one working?

                          Meshx86M Offline
                          Meshx86M Offline
                          Meshx86
                          wrote on last edited by
                          #18

                          @Jic i was wondering what's the purpose of the 1 M resistor on the reed switch ?
                          i used 2 x AA battery, digitalRead, 8 MHz stock clock and no resistor, i know this might not be the most optimized power consumption setup

                          1 Reply Last reply
                          0
                          • meanmrgreenM Offline
                            meanmrgreenM Offline
                            meanmrgreen
                            wrote on last edited by
                            #19

                            Nuub here..
                            Thinking about building this in my mailbox..
                            AND if possible set a green light diode to start light when box is opened and stop when its opened again.

                            That way i would see when i come home if someone has opened the mailbox or not.. Sure push notifications work aswell but it would be a nice touch for the wifey

                            Nca78N 1 Reply Last reply
                            2
                            • meanmrgreenM meanmrgreen

                              Nuub here..
                              Thinking about building this in my mailbox..
                              AND if possible set a green light diode to start light when box is opened and stop when its opened again.

                              That way i would see when i come home if someone has opened the mailbox or not.. Sure push notifications work aswell but it would be a nice touch for the wifey

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

                              @meanmrgreen if you use a led it will draw a few mA when on and battery life will be poor.
                              At best you could wake up every few seconds and flash it briefly (like 100ms or less). In that case use a low value current limiting resistor to have an intense flash, and probably a red LED is better.
                              To stop the blinking why not use a button (or touch button, check TTP223 in AliExpress) inside the mailbox ?

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

                                Not sure if it more battery friendly, but maybe sending a bluetooth low energy beacon is better than a led? Higher nerd factor for sure, but maybe less spouse friendly (depending on how good the ble app on the phone is).

                                Seems like it would be possible by using an extra nrf24: https://github.com/floe/BTLE/blob/master/examples/send/send.ino

                                On the other hand, if a smartphone is required you might as well open the app for your controller and check the status there :)

                                Maybe use a battery-friendly PIR and only light/blink the led when motion is detected?

                                1 Reply Last reply
                                0
                                • meanmrgreenM Offline
                                  meanmrgreenM Offline
                                  meanmrgreen
                                  wrote on last edited by
                                  #22

                                  You lost me at bluetooth beacon? :)

                                  Me personally is using the app but wifey and kids ain't really as interested as i am ;)

                                  So therefore I would need a indicator of some sorts around the mailbox that is about 30 meters from the house in the road up to the house.

                                  Maybe a solar led light or similar to light up? Or a flag on a servo?

                                  Will start with building the switch and figure out the indicator later.

                                  1 Reply Last reply
                                  1
                                  • AteszA Offline
                                    AteszA Offline
                                    Atesz
                                    wrote on last edited by
                                    #23

                                    Hi Everyone
                                    Be carefull a newby here... :-)

                                    I have ordered all the parts for my sensor network. My plan is to have battery powered sensor sensing the following: Door/window status AND temp/humidity. Doing all this in a low power fashion.

                                    My question is: Would these code in the build section be easily combined (dooe switch and temp/hum) in a way that it measures the temp/hum regurarly (every 15-30 min) and if during the sleep a door event happens it sends the door event to the gateway (and probably since we are awake do a temp/hum measurement as well)?

                                    Every piece of direction, advice is appreciated.

                                    Atesz

                                    1 Reply Last reply
                                    0
                                    • AteszA Offline
                                      AteszA Offline
                                      Atesz
                                      wrote on last edited by
                                      #24

                                      Like I said..newby here. Hold back your horses for a moment, I did a deep search and found some interesting forum topics here :-)

                                      mfalkviddM 1 Reply Last reply
                                      0
                                      • AteszA Atesz

                                        Like I said..newby here. Hold back your horses for a moment, I did a deep search and found some interesting forum topics here :-)

                                        mfalkviddM Online
                                        mfalkviddM Online
                                        mfalkvidd
                                        Mod
                                        wrote on last edited by
                                        #25

                                        @Atesz very welcome to the MySensors community!
                                        "easily" is in the eye of the beholder, but I'd say yes. https://forum.mysensors.org/topic/2597/combining-mysensors-examples is a great starting poing for combining sketches.

                                        AteszA 1 Reply Last reply
                                        0
                                        • mfalkviddM mfalkvidd

                                          @Atesz very welcome to the MySensors community!
                                          "easily" is in the eye of the beholder, but I'd say yes. https://forum.mysensors.org/topic/2597/combining-mysensors-examples is a great starting poing for combining sketches.

                                          AteszA Offline
                                          AteszA Offline
                                          Atesz
                                          wrote on last edited by
                                          #26

                                          @mfalkvidd Thank you very much, it is almost what I've been looking for !

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