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. Multi Binary Switches

Multi Binary Switches

Scheduled Pinned Locked Moved My Project
13 Posts 6 Posters 7.0k Views 2 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.
  • M Offline
    M Offline
    maltimus
    wrote on last edited by
    #2

    What is the issues you are having?

    jeylitesJ 1 Reply Last reply
    0
    • M maltimus

      What is the issues you are having?

      jeylitesJ Offline
      jeylitesJ Offline
      jeylites
      wrote on last edited by jeylites
      #3

      @maltimus

      I can't seem to get binary to work in an Array.

      1 Reply Last reply
      0
      • raditvR Offline
        raditvR Offline
        raditv
        wrote on last edited by
        #4

        you have to make an array also for debouncer

        1 Reply Last reply
        0
        • BulldogLowellB Offline
          BulldogLowellB Offline
          BulldogLowell
          Contest Winner
          wrote on last edited by BulldogLowell
          #5

          @jeylites

          have you checked this thread?

          http://forum.mysensors.org/topic/994/multi-button-relay-switch/24

          jeylitesJ 1 Reply Last reply
          0
          • BulldogLowellB BulldogLowell

            @jeylites

            have you checked this thread?

            http://forum.mysensors.org/topic/994/multi-button-relay-switch/24

            jeylitesJ Offline
            jeylitesJ Offline
            jeylites
            wrote on last edited by jeylites
            #6

            @BulldogLowell

            I'm trying to do Multi Binary switches without the relays. I tried using the Multi Button Relay sketch, but I'm afraid that if remove the relay function, it would affect the button setup.

            @Rachmat-Aditiya How do I go about doing that an array for debouncer?

            BulldogLowellB 1 Reply Last reply
            0
            • jeylitesJ jeylites

              @BulldogLowell

              I'm trying to do Multi Binary switches without the relays. I tried using the Multi Button Relay sketch, but I'm afraid that if remove the relay function, it would affect the button setup.

              @Rachmat-Aditiya How do I go about doing that an array for debouncer?

              BulldogLowellB Offline
              BulldogLowellB Offline
              BulldogLowell
              Contest Winner
              wrote on last edited by
              #7

              @jeylites said:

              How do I go about doing that an array for debouncer?

              the example of debouncing an array of sensors was in the code in the examples... was my point.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mikeones
                wrote on last edited by
                #8

                Here is one example with a few extras.

                // Simple binary switch example 
                // Connect button or door/window reed switch between 
                // digitial I/O pin 3 (BUTTON_PIN below) and GND.
                
                #include <MySensor.h>
                #include <SPI.h>
                #include <Bounce2.h>
                #include <Time.h>        //http://playground.arduino.cc/Code/Time
                #include <TimeAlarms.h>  //http://playground.arduino.cc/Code/Time
                
                MySensor gw;
                
                #define RADIO_ID 12
                #define noReeds 5
                const int BUTTON_PIN[] = {14, 15, 16, 17, 18};            // Arduino Digital I/O pin for button/reed switch, A0 - A4
                boolean reedState[] = {HIGH, HIGH, HIGH, HIGH, HIGH};
                
                
                Bounce debouncer[noReeds];
                MyMessage msg[noReeds];
                
                void setup(){
                  Serial.println("Starting setup" );
                  gw.begin(NULL, RADIO_ID, true);  //stattc RADIO_ID an enable repeater
                  Alarm.delay(250);
                  gw.sendSketchInfo("Alarm Pannel", "1.0");
                  Alarm.delay(250);
                  gw.requestTime(receiveTime);
                  // initialize Relays with corresponding buttons
                  for (int i = 0; i < noReeds; i++){
                    msg[i].sensor = i;			// initialize messages
                    msg[i].type = V_TRIPPED;
                    debouncer[i] = Bounce();		// initialize debouncer
                    debouncer[i].attach(BUTTON_PIN[i]);
                    debouncer[i].interval(5);
                    // Setup the button
                    pinMode(BUTTON_PIN[i],INPUT);
                    // Activate internal pull-up
                    digitalWrite(BUTTON_PIN[i],HIGH);
                    gw.present(i, S_DOOR);		// present sensor to gateway
                    Serial.print("setup for switch: ");
                    Serial.print(BUTTON_PIN[i]);
                    Serial.println(" complete" );
                    Alarm.timerRepeat(720, updateState); // update relay status every 2 hrs
                    Alarm.delay(250);
                  }
                  Serial.println("Setup complete" );
                }
                
                
                //  Check if digital input has changed and send in new value
                void loop() 
                {
                  gw.process();
                  for (int i = 0; i < noReeds; i++){
                    debouncer[i].update();
                    // Get the update value
                    int value = debouncer[i].read();
                    if (value != reedState[i]) {
                       // Send in the new value
                       gw.send(msg[i].set(value==HIGH ? 1 : 0), false);
                       reedState[i] = value;
                       Serial.print("updating state for swicth: ");
                       Serial.print(BUTTON_PIN[i]);
                       Serial.print(" state: ");
                       Serial.println(reedState[i]);
                    }
                  }
                }
                
                void updateState(){
                  Serial.println("Start state info");
                  for (int i = 0; i < noReeds; i++)
                  {
                      Serial.print("sending update for switch: ");
                      Serial.println(BUTTON_PIN[i]);
                      gw.present(i, S_DOOR);
                      Alarm.delay(250);
                      //MyMessage msg(relayPin[pin],V_LIGHT);
                      gw.send(msg[i].set(reedState[i]), false); // Send last state from eprom to GW
                      Alarm.delay(250);
                  }
                }
                
                // This is called when a new time value was received
                void receiveTime(unsigned long time) {
                  setTime(time);
                }```
                jeylitesJ 1 Reply Last reply
                0
                • M mikeones

                  Here is one example with a few extras.

                  // Simple binary switch example 
                  // Connect button or door/window reed switch between 
                  // digitial I/O pin 3 (BUTTON_PIN below) and GND.
                  
                  #include <MySensor.h>
                  #include <SPI.h>
                  #include <Bounce2.h>
                  #include <Time.h>        //http://playground.arduino.cc/Code/Time
                  #include <TimeAlarms.h>  //http://playground.arduino.cc/Code/Time
                  
                  MySensor gw;
                  
                  #define RADIO_ID 12
                  #define noReeds 5
                  const int BUTTON_PIN[] = {14, 15, 16, 17, 18};            // Arduino Digital I/O pin for button/reed switch, A0 - A4
                  boolean reedState[] = {HIGH, HIGH, HIGH, HIGH, HIGH};
                  
                  
                  Bounce debouncer[noReeds];
                  MyMessage msg[noReeds];
                  
                  void setup(){
                    Serial.println("Starting setup" );
                    gw.begin(NULL, RADIO_ID, true);  //stattc RADIO_ID an enable repeater
                    Alarm.delay(250);
                    gw.sendSketchInfo("Alarm Pannel", "1.0");
                    Alarm.delay(250);
                    gw.requestTime(receiveTime);
                    // initialize Relays with corresponding buttons
                    for (int i = 0; i < noReeds; i++){
                      msg[i].sensor = i;			// initialize messages
                      msg[i].type = V_TRIPPED;
                      debouncer[i] = Bounce();		// initialize debouncer
                      debouncer[i].attach(BUTTON_PIN[i]);
                      debouncer[i].interval(5);
                      // Setup the button
                      pinMode(BUTTON_PIN[i],INPUT);
                      // Activate internal pull-up
                      digitalWrite(BUTTON_PIN[i],HIGH);
                      gw.present(i, S_DOOR);		// present sensor to gateway
                      Serial.print("setup for switch: ");
                      Serial.print(BUTTON_PIN[i]);
                      Serial.println(" complete" );
                      Alarm.timerRepeat(720, updateState); // update relay status every 2 hrs
                      Alarm.delay(250);
                    }
                    Serial.println("Setup complete" );
                  }
                  
                  
                  //  Check if digital input has changed and send in new value
                  void loop() 
                  {
                    gw.process();
                    for (int i = 0; i < noReeds; i++){
                      debouncer[i].update();
                      // Get the update value
                      int value = debouncer[i].read();
                      if (value != reedState[i]) {
                         // Send in the new value
                         gw.send(msg[i].set(value==HIGH ? 1 : 0), false);
                         reedState[i] = value;
                         Serial.print("updating state for swicth: ");
                         Serial.print(BUTTON_PIN[i]);
                         Serial.print(" state: ");
                         Serial.println(reedState[i]);
                      }
                    }
                  }
                  
                  void updateState(){
                    Serial.println("Start state info");
                    for (int i = 0; i < noReeds; i++)
                    {
                        Serial.print("sending update for switch: ");
                        Serial.println(BUTTON_PIN[i]);
                        gw.present(i, S_DOOR);
                        Alarm.delay(250);
                        //MyMessage msg(relayPin[pin],V_LIGHT);
                        gw.send(msg[i].set(reedState[i]), false); // Send last state from eprom to GW
                        Alarm.delay(250);
                    }
                  }
                  
                  // This is called when a new time value was received
                  void receiveTime(unsigned long time) {
                    setTime(time);
                  }```
                  jeylitesJ Offline
                  jeylitesJ Offline
                  jeylites
                  wrote on last edited by jeylites
                  #9

                  @mikeones Thank you, The sketch is very helpful and it works. Just out of curiosity, what is the function of Time & TimeAlarm ?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mikeones
                    wrote on last edited by
                    #10

                    It forces a status update at a predefined interval.

                    Alarm.timerRepeat(720, updateState); // update relay status every 2 hrs
                    
                    jeylitesJ 1 Reply Last reply
                    0
                    • M mikeones

                      It forces a status update at a predefined interval.

                      Alarm.timerRepeat(720, updateState); // update relay status every 2 hrs
                      
                      jeylitesJ Offline
                      jeylitesJ Offline
                      jeylites
                      wrote on last edited by
                      #11

                      @mikeones Got it.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Cowboy1980
                        wrote on last edited by
                        #12

                        Much appreciated for the script but Ive been trying to get more reed switches running off the one nano, I added the extra pins to Button_Pin and changed noReeds and boonlean readstate to represent how many pins I was using. I have 12 showing up in vera and serial shows correctly the change in state of all 12 pins but in the Vera all 12 show but dont trip/show the state change. What am I missing? When I run the code youve written as is everything works fine but as soon as I even add 1 more pin Mios wont show the state change. Plz help!

                        jeylitesJ 1 Reply Last reply
                        0
                        • C Cowboy1980

                          Much appreciated for the script but Ive been trying to get more reed switches running off the one nano, I added the extra pins to Button_Pin and changed noReeds and boonlean readstate to represent how many pins I was using. I have 12 showing up in vera and serial shows correctly the change in state of all 12 pins but in the Vera all 12 show but dont trip/show the state change. What am I missing? When I run the code youve written as is everything works fine but as soon as I even add 1 more pin Mios wont show the state change. Plz help!

                          jeylitesJ Offline
                          jeylitesJ Offline
                          jeylites
                          wrote on last edited by
                          #13

                          @Cowboy1980 Can you post your script...

                          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