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.
  • EuromirE Offline
    EuromirE Offline
    Euromir
    wrote on last edited by
    #46

    Another newbie sorry.
    Trying to use this as a simple doorbell, just to send a trigger to Domoticz.

    I connect doorbell button to digital pin 3, the Node appears in Domoticz ok as a "security sensor" but shows as state "ON". However pressing the button appears to do nothing sadly, switch status stays as on, and log shows no activity at all?

    Using a Uno (clone) and wondering if somethings up with it? :(

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

      What does the nodes and/or the gateways log say?
      It might not change in domoticz if you just send on but no off signals but it should still be visible in the nodes log (arduino and in domotizc)

      1 Reply Last reply
      0
      • EuromirE Offline
        EuromirE Offline
        Euromir
        wrote on last edited by Euromir
        #48

        Hold that thought, embarrassingly it might just be a bad connection! Oops
        Just took it all apart in frustration, had a cuppa and put it back together.
        And something is triggering now, need to play some more, but first hurdle looks like possibly a simply connection maybe.
        I'll let you know.

        1 Reply Last reply
        1
        • B Offline
          B Offline
          bluezr1
          wrote on last edited by
          #49

          Not sure what I'm doing wrong but I tried to add more than one sensor and didn't get very far. Was hoping to do a motion and a door sensor from the same arduino.

          1 Reply Last reply
          0
          • skywatchS Offline
            skywatchS Offline
            skywatch
            wrote on last edited by
            #50

            As doors and windows are usually not near power sources would it not be better to have this sketch with a SLEEP function and trigger on interupt?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Psilin
              wrote on last edited by Psilin
              #51

              what is the logic of the variable "V_TRIPPED"to use? I just messed a little with the MyController application, and by using the V_TRIPPED the value changes from off to on,and stays on,even if the button is released? ( simular to close an opened door)
              Should the variable not be of a binary type with according sensor type?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Slimz
                wrote on last edited by
                #52

                Hi,
                I have my sensor working well, Arduino pro mini with an Ethernet gateway using Home Assistant. .This is the first sensor I'm actually using a battery, so I've never really needed it, I see the battery level in HA as 0, how do I turn that on and use the battery level? Any pointers?
                Thanks!
                Jim

                1 Reply Last reply
                0
                • Steve HadleyS Offline
                  Steve HadleyS Offline
                  Steve Hadley
                  wrote on last edited by
                  #53

                  Dumb question, but how would I set this sketch to have an array of 5 switches? I’ve tried a couple of things but I’m lost

                  1 Reply Last reply
                  0
                  • Mitja BlazinsekM Offline
                    Mitja BlazinsekM Offline
                    Mitja Blazinsek
                    wrote on last edited by
                    #54

                    https://forum.mysensors.org/topic/7249/simple-binary-switch-example-trying-to-add-second-switch

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      rodaman
                      wrote on last edited by rodaman
                      #55

                      Hi,
                      I rewrite sketch for doors/window/buttons to work with multiple buttons (no rellays) .It shows up in Domoticz but it did not change status buttons if pressed.
                      Can someone look for the skech what I am doing wrong

                      /**
                        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 updated  for 2 switches
                        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
                      #define MY_GATEWAY_SERIAL
                      
                      //#include <SPI.h>
                      #include <MySensors.h>
                      #include <Bounce2.h>
                      
                      #define FIRST_PIN  8  // Arduino Digital I/O pin for button/reed switch
                      #define noButtons 4
                      const int buttonPin[noButtons];
                      
                      Bounce debouncer[noButtons] = Bounce();
                      
                      int oldValue[noButtons];
                      
                      MyMessage msg[noButtons];
                      
                      void setup() {
                      
                       for (int i = 0; i < noButtons; i++) {
                      
                         msg[i].sensor = i;                                   // initialize messages
                         msg[i].type = V_TRIPPED; //
                      
                         pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);
                         digitalWrite(buttonPin[i + FIRST_PIN], HIGH);
                         debouncer[i] = Bounce();                        // initialize debouncer
                         debouncer[i].attach(buttonPin[i + FIRST_PIN]);
                         debouncer[i].interval(30);
                       }
                      }
                      
                      void presentation() {
                       sendSketchInfo("Doors", "1.0");
                       for (int i = 0; i < noButtons; i++)
                         present(i, S_DOOR);                               // present sensor to gateway
                      
                      
                      }
                      
                      
                      //  Check if digital input has changed and send in new value
                      void loop()
                      {
                       for (int i = 0; i < noButtons; i++) {
                         debouncer[i].update();
                      
                         int value = debouncer[i].read();
                         if (value != oldValue[i]) {
                      
                           // Send in the new value
                           send(msg[i].set(value == HIGH ? 1 : 0));
                           oldValue[i] = value;
                         }
                      
                       }
                      }
                      
                      mfalkviddM 1 Reply Last reply
                      0
                      • R rodaman

                        Hi,
                        I rewrite sketch for doors/window/buttons to work with multiple buttons (no rellays) .It shows up in Domoticz but it did not change status buttons if pressed.
                        Can someone look for the skech what I am doing wrong

                        /**
                          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 updated  for 2 switches
                          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
                        #define MY_GATEWAY_SERIAL
                        
                        //#include <SPI.h>
                        #include <MySensors.h>
                        #include <Bounce2.h>
                        
                        #define FIRST_PIN  8  // Arduino Digital I/O pin for button/reed switch
                        #define noButtons 4
                        const int buttonPin[noButtons];
                        
                        Bounce debouncer[noButtons] = Bounce();
                        
                        int oldValue[noButtons];
                        
                        MyMessage msg[noButtons];
                        
                        void setup() {
                        
                         for (int i = 0; i < noButtons; i++) {
                        
                           msg[i].sensor = i;                                   // initialize messages
                           msg[i].type = V_TRIPPED; //
                        
                           pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);
                           digitalWrite(buttonPin[i + FIRST_PIN], HIGH);
                           debouncer[i] = Bounce();                        // initialize debouncer
                           debouncer[i].attach(buttonPin[i + FIRST_PIN]);
                           debouncer[i].interval(30);
                         }
                        }
                        
                        void presentation() {
                         sendSketchInfo("Doors", "1.0");
                         for (int i = 0; i < noButtons; i++)
                           present(i, S_DOOR);                               // present sensor to gateway
                        
                        
                        }
                        
                        
                        //  Check if digital input has changed and send in new value
                        void loop()
                        {
                         for (int i = 0; i < noButtons; i++) {
                           debouncer[i].update();
                        
                           int value = debouncer[i].read();
                           if (value != oldValue[i]) {
                        
                             // Send in the new value
                             send(msg[i].set(value == HIGH ? 1 : 0));
                             oldValue[i] = value;
                           }
                        
                         }
                        }
                        
                        mfalkviddM Online
                        mfalkviddM Online
                        mfalkvidd
                        Mod
                        wrote on last edited by mfalkvidd
                        #56

                        @rodaman 0_1474354717994_upload-0e56e228-365f-4d94-90b3-5cf1305c6fae

                        I fixed it for you.

                        R 1 Reply Last reply
                        0
                        • mfalkviddM mfalkvidd

                          @rodaman 0_1474354717994_upload-0e56e228-365f-4d94-90b3-5cf1305c6fae

                          I fixed it for you.

                          R Offline
                          R Offline
                          rodaman
                          wrote on last edited by
                          #57

                          @mfalkvidd
                          thank you, i hope will be good soul who fix my sketch itself to work... :-)

                          1 Reply Last reply
                          0
                          • hekH Offline
                            hekH Offline
                            hek
                            Admin
                            wrote on last edited by
                            #58

                            @rodaman said in 💬 Door, Window and Push-button Sensor:

                            What is the purpose of the buttonPin-array?

                            E.g.

                            pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);

                            This will fetch a random (probably 0-initialised) value from the array and set pinmode on that value...

                            R 2 Replies Last reply
                            0
                            • hekH hek

                              @rodaman said in 💬 Door, Window and Push-button Sensor:

                              What is the purpose of the buttonPin-array?

                              E.g.

                              pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);

                              This will fetch a random (probably 0-initialised) value from the array and set pinmode on that value...

                              R Offline
                              R Offline
                              rodaman
                              wrote on last edited by
                              #59

                              @hek
                              That part was in original sketch for establish internal pullup as I understand. I used array to do it for each pins.

                              1 Reply Last reply
                              0
                              • hekH hek

                                @rodaman said in 💬 Door, Window and Push-button Sensor:

                                What is the purpose of the buttonPin-array?

                                E.g.

                                pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);

                                This will fetch a random (probably 0-initialised) value from the array and set pinmode on that value...

                                R Offline
                                R Offline
                                rodaman
                                wrote on last edited by
                                #60

                                @hek
                                I have changed

                                pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);
                                

                                to

                                pinMode(buttonPin[i + FIRST_PIN], INPUT);
                                

                                thanks, but sadlly still does not work...

                                1 Reply Last reply
                                0
                                • hekH Offline
                                  hekH Offline
                                  hek
                                  Admin
                                  wrote on last edited by
                                  #61

                                  @rodaman said in 💬 Door, Window and Push-button Sensor:

                                  http://www.mysensors.org/build/binary

                                  I don't get the buttonPin array thing at all?

                                  Why not just:
                                  pinMode(i + FIRST_PIN, INPUT_PULLUP);

                                  mfalkviddM R 2 Replies Last reply
                                  0
                                  • hekH hek

                                    @rodaman said in 💬 Door, Window and Push-button Sensor:

                                    http://www.mysensors.org/build/binary

                                    I don't get the buttonPin array thing at all?

                                    Why not just:
                                    pinMode(i + FIRST_PIN, INPUT_PULLUP);

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

                                    @hek if the array was initialized, it could be used to set arbitrary pins. So pin 4,5,6,7,8,A0,A1,A2,A3 could be used for example (to avoid conflicts with the standard nrf24 wiring but still allow a lot of buttons). But as you mentioned before, without initializing the array the behavior will be strange.

                                    1 Reply Last reply
                                    0
                                    • hekH hek

                                      @rodaman said in 💬 Door, Window and Push-button Sensor:

                                      http://www.mysensors.org/build/binary

                                      I don't get the buttonPin array thing at all?

                                      Why not just:
                                      pinMode(i + FIRST_PIN, INPUT_PULLUP);

                                      R Offline
                                      R Offline
                                      rodaman
                                      wrote on last edited by
                                      #63

                                      @hek said in 💬 Door, Window and Push-button Sensor:

                                      pinMode(i + FIRST_PIN, INPUT_PULLUP);

                                      Big Thanks!
                                      I have changed all array parts in setup in the same manner like above and it works :-)

                                      R 1 Reply Last reply
                                      1
                                      • R rodaman

                                        @hek said in 💬 Door, Window and Push-button Sensor:

                                        pinMode(i + FIRST_PIN, INPUT_PULLUP);

                                        Big Thanks!
                                        I have changed all array parts in setup in the same manner like above and it works :-)

                                        R Offline
                                        R Offline
                                        rodaman
                                        wrote on last edited by rodaman
                                        #64

                                        @rodaman
                                        Hi,
                                        Here is a sketch for multi buttons (no relays, no repeated parts of code for each buttons) just enter number of buttons and first digital pin where buttons are attached.
                                        Thanks to @hek for help...

                                        /**
                                           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 updated  for multi switches
                                           Connect buttons or door/window reed switches between
                                           digitial I/O choosen pin  (FIRST_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
                                        #define MY_GATEWAY_SERIAL
                                        
                                        //#include <SPI.h>
                                        #include <MySensors.h>
                                        #include <Bounce2.h>
                                        
                                        #define FIRST_PIN  2  // Arduino Digital I/O pin for button/reed switch
                                        #define noButtons 6
                                        
                                        
                                        Bounce debouncer[noButtons] = Bounce();
                                        
                                        int oldValue[noButtons];
                                        int value;
                                        MyMessage msg[noButtons];
                                        
                                        void setup() {
                                        
                                          for (int i = 0; i < noButtons; i++) {
                                        
                                            oldValue[i] = -1;
                                            
                                            msg[i].sensor = i;                                   // initialize messages
                                            msg[i].type = V_TRIPPED; //
                                            pinMode(i + FIRST_PIN, INPUT_PULLUP);
                                            digitalWrite(i + FIRST_PIN, HIGH);
                                          
                                            debouncer[i] = Bounce();                        // initialize debouncer
                                            debouncer[i].attach(i + FIRST_PIN);
                                            debouncer[i].interval(3);
                                          }
                                        }
                                        
                                        void presentation() {
                                          sendSketchInfo("Doors", "1.0");
                                          for (int i = 0; i < noButtons; i++)
                                            present(i, S_DOOR);                               // present sensor to gateway
                                        }
                                        
                                        
                                        //  Check if digital input has changed and send in new value
                                        void loop()
                                        {
                                          for (int i = 0; i < noButtons; i++) {
                                            debouncer[i].update();
                                        
                                            value = debouncer[i].read();
                                            if (value != oldValue[i]) {
                                            // Send in the new value
                                              send(msg[i].set(value == HIGH ? 1 : 0));
                                              oldValue[i] = value;
                                            }
                                         }
                                        }
                                        
                                        
                                        1 Reply Last reply
                                        1
                                        • gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #65

                                          Could these reed switches be used in the NC configuration for door/window sensor to save more battery?

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


                                          12

                                          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