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. Troubleshooting
  3. 2 Reed Switches 1 Arduino Nano

2 Reed Switches 1 Arduino Nano

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 3 Posters 2.5k Views 3 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.
  • DdawmeD Offline
    DdawmeD Offline
    Ddawme
    wrote on last edited by
    #1

    Hoping for some help from the MySensors experts. Im running a home automation system using Domoticz as my controller and MySensors 2.0 Library for my nodes. I noticed the close proximity of my front door and my garage door and wanted to save a microcontroller and radio by having it handle the reed switches for both doors. First off I do not consider myself a coder Im much more of a hardware kind of guy. I ended up cobbling this sketch together by looking at an example I found in the forums and looking at the included binary switch sketch.

    My issue is when I open the front door, both the garage door and front door indicators on my Domoticz dashboard change state. When I open and close the garage door only the garage door indicator changes state. I suspect it has something to do with how the pin ID's are assigned but I just am not very strong in that department. Any help would be appreciated.

    /**

    • 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_1 3
    #define BUTTON_PIN_1 3 // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID_2 4
    #define BUTTON_PIN_2 4 // Arduino Digital I/O pin for button/reed switch

    Bounce debouncer1 = Bounce();
    Bounce debouncer2 = Bounce();

    int oldValue1=-1;
    int oldValue2=-1;

    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg1(CHILD_ID_1,V_TRIPPED);
    MyMessage msg2(CHILD_ID_2,V_TRIPPED);

    void setup()
    {
    // Setup the button
    pinMode(BUTTON_PIN_1,INPUT);
    pinMode(BUTTON_PIN_2,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN_1,HIGH);
    digitalWrite(BUTTON_PIN_2,HIGH);

    // After setting up the button, setup debouncer
    debouncer1.attach(BUTTON_PIN_1);
    debouncer1.interval(5);
    debouncer2.attach(BUTTON_PIN_2);
    debouncer2.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_1, S_DOOR);
    present(CHILD_ID_2, S_DOOR);
    }

    // Check if digital input has changed and send in new value
    void loop()
    {
    {
    debouncer1.update();
    // Get the update value
    int value1 = debouncer1.read();

    if (value1 != oldValue1) {
      // Send in the new value
      send(msg1.set(value1==HIGH ? 1 : 0));
      oldValue1 = value1;
    

    }
    }

    {
    debouncer2.update();
    // Get the update value
    int value2 = debouncer2.read();

    if (value2 != oldValue2) {
      // Send in the new value
      send(msg2.set(value2==HIGH ? 1 : 0));
      oldValue2 = value2;
    

    }
    }
    }

    mfalkviddM 1 Reply Last reply
    0
    • DickD Offline
      DickD Offline
      Dick
      wrote on last edited by
      #2

      The compiler is unable to find out what "value" is, since it has not been used before.
      Try this

      gw.send(msg.set(HIGH));
      
      1 Reply Last reply
      0
      • DdawmeD Ddawme

        Hoping for some help from the MySensors experts. Im running a home automation system using Domoticz as my controller and MySensors 2.0 Library for my nodes. I noticed the close proximity of my front door and my garage door and wanted to save a microcontroller and radio by having it handle the reed switches for both doors. First off I do not consider myself a coder Im much more of a hardware kind of guy. I ended up cobbling this sketch together by looking at an example I found in the forums and looking at the included binary switch sketch.

        My issue is when I open the front door, both the garage door and front door indicators on my Domoticz dashboard change state. When I open and close the garage door only the garage door indicator changes state. I suspect it has something to do with how the pin ID's are assigned but I just am not very strong in that department. Any help would be appreciated.

        /**

        • 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_1 3
        #define BUTTON_PIN_1 3 // Arduino Digital I/O pin for button/reed switch
        #define CHILD_ID_2 4
        #define BUTTON_PIN_2 4 // Arduino Digital I/O pin for button/reed switch

        Bounce debouncer1 = Bounce();
        Bounce debouncer2 = Bounce();

        int oldValue1=-1;
        int oldValue2=-1;

        // Change to V_LIGHT if you use S_LIGHT in presentation below
        MyMessage msg1(CHILD_ID_1,V_TRIPPED);
        MyMessage msg2(CHILD_ID_2,V_TRIPPED);

        void setup()
        {
        // Setup the button
        pinMode(BUTTON_PIN_1,INPUT);
        pinMode(BUTTON_PIN_2,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_1,HIGH);
        digitalWrite(BUTTON_PIN_2,HIGH);

        // After setting up the button, setup debouncer
        debouncer1.attach(BUTTON_PIN_1);
        debouncer1.interval(5);
        debouncer2.attach(BUTTON_PIN_2);
        debouncer2.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_1, S_DOOR);
        present(CHILD_ID_2, S_DOOR);
        }

        // Check if digital input has changed and send in new value
        void loop()
        {
        {
        debouncer1.update();
        // Get the update value
        int value1 = debouncer1.read();

        if (value1 != oldValue1) {
          // Send in the new value
          send(msg1.set(value1==HIGH ? 1 : 0));
          oldValue1 = value1;
        

        }
        }

        {
        debouncer2.update();
        // Get the update value
        int value2 = debouncer2.read();

        if (value2 != oldValue2) {
          // Send in the new value
          send(msg2.set(value2==HIGH ? 1 : 0));
          oldValue2 = value2;
        

        }
        }
        }

        mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by mfalkvidd
        #3

        @Ddawme the code looks good, except that it is hard to read. Use the auto format tool in the Arduino IDE to format it, that will make it much readable. Use the code button in the forum to mark the code as code.

        How is your wiring? Are both switches connected to ground? Does the same problem appear if you physically disconnect the garage door switch and open the front door?

        Next step could be to enable debug on the node to get information on what it does. You can also add Serial.println statements to see which parts of the code is executed and what values the variables have.

        Here is the code in a tidier presentation:

        /**
        
            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_1 3
        #define BUTTON_PIN_1 3 // Arduino Digital I/O pin for button/reed switch
        #define CHILD_ID_2 4
        #define BUTTON_PIN_2 4 // Arduino Digital I/O pin for button/reed switch
        
        Bounce debouncer1 = Bounce();
        Bounce debouncer2 = Bounce();
        
        int oldValue1 = -1;
        int oldValue2 = -1;
        
        // Change to V_LIGHT if you use S_LIGHT in presentation below
        MyMessage msg1(CHILD_ID_1, V_TRIPPED);
        MyMessage msg2(CHILD_ID_2, V_TRIPPED);
        
        void setup()
        {
          // Setup the button
          pinMode(BUTTON_PIN_1, INPUT);
          pinMode(BUTTON_PIN_2, INPUT);
          // Activate internal pull-up
          digitalWrite(BUTTON_PIN_1, HIGH);
          digitalWrite(BUTTON_PIN_2, HIGH);
        
          // After setting up the button, setup debouncer
          debouncer1.attach(BUTTON_PIN_1);
          debouncer1.interval(5);
          debouncer2.attach(BUTTON_PIN_2);
          debouncer2.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_1, S_DOOR);
          present(CHILD_ID_2, S_DOOR);
        }
        
        // Check if digital input has changed and send in new value
        void loop()
        {
          debouncer1.update();
          // Get the update value
          int value1 = debouncer1.read();
        
          if (value1 != oldValue1) {
            // Send in the new value
            send(msg1.set(value1 == HIGH ? 1 : 0));
            oldValue1 = value1;
          }
        
          debouncer2.update();
          // Get the update value
          int value2 = debouncer2.read();
        
          if (value2 != oldValue2) {
            // Send in the new value
            send(msg2.set(value2 == HIGH ? 1 : 0));
            oldValue2 = value2;
          }
        }
        
        DdawmeD 2 Replies Last reply
        0
        • mfalkviddM mfalkvidd

          @Ddawme the code looks good, except that it is hard to read. Use the auto format tool in the Arduino IDE to format it, that will make it much readable. Use the code button in the forum to mark the code as code.

          How is your wiring? Are both switches connected to ground? Does the same problem appear if you physically disconnect the garage door switch and open the front door?

          Next step could be to enable debug on the node to get information on what it does. You can also add Serial.println statements to see which parts of the code is executed and what values the variables have.

          Here is the code in a tidier presentation:

          /**
          
              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_1 3
          #define BUTTON_PIN_1 3 // Arduino Digital I/O pin for button/reed switch
          #define CHILD_ID_2 4
          #define BUTTON_PIN_2 4 // Arduino Digital I/O pin for button/reed switch
          
          Bounce debouncer1 = Bounce();
          Bounce debouncer2 = Bounce();
          
          int oldValue1 = -1;
          int oldValue2 = -1;
          
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          MyMessage msg1(CHILD_ID_1, V_TRIPPED);
          MyMessage msg2(CHILD_ID_2, V_TRIPPED);
          
          void setup()
          {
            // Setup the button
            pinMode(BUTTON_PIN_1, INPUT);
            pinMode(BUTTON_PIN_2, INPUT);
            // Activate internal pull-up
            digitalWrite(BUTTON_PIN_1, HIGH);
            digitalWrite(BUTTON_PIN_2, HIGH);
          
            // After setting up the button, setup debouncer
            debouncer1.attach(BUTTON_PIN_1);
            debouncer1.interval(5);
            debouncer2.attach(BUTTON_PIN_2);
            debouncer2.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_1, S_DOOR);
            present(CHILD_ID_2, S_DOOR);
          }
          
          // Check if digital input has changed and send in new value
          void loop()
          {
            debouncer1.update();
            // Get the update value
            int value1 = debouncer1.read();
          
            if (value1 != oldValue1) {
              // Send in the new value
              send(msg1.set(value1 == HIGH ? 1 : 0));
              oldValue1 = value1;
            }
          
            debouncer2.update();
            // Get the update value
            int value2 = debouncer2.read();
          
            if (value2 != oldValue2) {
              // Send in the new value
              send(msg2.set(value2 == HIGH ? 1 : 0));
              oldValue2 = value2;
            }
          }
          
          DdawmeD Offline
          DdawmeD Offline
          Ddawme
          wrote on last edited by
          #4

          @mfalkvidd thank you. I was disappointed when I sat how it formatted. I will check your suggestions today.

          1 Reply Last reply
          1
          • mfalkviddM mfalkvidd

            @Ddawme the code looks good, except that it is hard to read. Use the auto format tool in the Arduino IDE to format it, that will make it much readable. Use the code button in the forum to mark the code as code.

            How is your wiring? Are both switches connected to ground? Does the same problem appear if you physically disconnect the garage door switch and open the front door?

            Next step could be to enable debug on the node to get information on what it does. You can also add Serial.println statements to see which parts of the code is executed and what values the variables have.

            Here is the code in a tidier presentation:

            /**
            
                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_1 3
            #define BUTTON_PIN_1 3 // Arduino Digital I/O pin for button/reed switch
            #define CHILD_ID_2 4
            #define BUTTON_PIN_2 4 // Arduino Digital I/O pin for button/reed switch
            
            Bounce debouncer1 = Bounce();
            Bounce debouncer2 = Bounce();
            
            int oldValue1 = -1;
            int oldValue2 = -1;
            
            // Change to V_LIGHT if you use S_LIGHT in presentation below
            MyMessage msg1(CHILD_ID_1, V_TRIPPED);
            MyMessage msg2(CHILD_ID_2, V_TRIPPED);
            
            void setup()
            {
              // Setup the button
              pinMode(BUTTON_PIN_1, INPUT);
              pinMode(BUTTON_PIN_2, INPUT);
              // Activate internal pull-up
              digitalWrite(BUTTON_PIN_1, HIGH);
              digitalWrite(BUTTON_PIN_2, HIGH);
            
              // After setting up the button, setup debouncer
              debouncer1.attach(BUTTON_PIN_1);
              debouncer1.interval(5);
              debouncer2.attach(BUTTON_PIN_2);
              debouncer2.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_1, S_DOOR);
              present(CHILD_ID_2, S_DOOR);
            }
            
            // Check if digital input has changed and send in new value
            void loop()
            {
              debouncer1.update();
              // Get the update value
              int value1 = debouncer1.read();
            
              if (value1 != oldValue1) {
                // Send in the new value
                send(msg1.set(value1 == HIGH ? 1 : 0));
                oldValue1 = value1;
              }
            
              debouncer2.update();
              // Get the update value
              int value2 = debouncer2.read();
            
              if (value2 != oldValue2) {
                // Send in the new value
                send(msg2.set(value2 == HIGH ? 1 : 0));
                oldValue2 = value2;
              }
            }
            
            DdawmeD Offline
            DdawmeD Offline
            Ddawme
            wrote on last edited by
            #5

            @mfalkvidd

            Sorry to leave you hanging for so long. Was finally able to start my troubleshooting of the node today. Turns out it did end up being a wiring issue, filed as "Technician Error". Rather than having both the reed switches share a common ground, I had one sensor grounding to the data pin of the other.

            mfalkviddM 1 Reply Last reply
            1
            • DdawmeD Ddawme

              @mfalkvidd

              Sorry to leave you hanging for so long. Was finally able to start my troubleshooting of the node today. Turns out it did end up being a wiring issue, filed as "Technician Error". Rather than having both the reed switches share a common ground, I had one sensor grounding to the data pin of the other.

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #6

              @Ddawme great that you found the problem. Thanks for reporting back!

              Need to keep an extra eye on those pesky technicians ;-)

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


              26

              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