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. General Discussion
  3. Help!!! Binary & Relay Compilation Not Working

Help!!! Binary & Relay Compilation Not Working

Scheduled Pinned Locked Moved General Discussion
15 Posts 4 Posters 5.1k Views 1 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.
  • jeylitesJ Offline
    jeylitesJ Offline
    jeylites
    wrote on last edited by
    #5

    This is the serial message I get

    repeater started, id 12
    send: 12-12-0-0 s=255,c=0,t=18,pt=0,l=5,st=ok:1.4.1
    send: 12-12-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    read: 0-0-12 s=255,c=3,t=6,pt=0,l=1:M
    send: 12-12-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Relay
    send: 12-12-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 12-12-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Alarm Pannel
    send: 12-12-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 12-12-0-0 s=255,c=3,t=1,pt=0,l=3,st=ok:1.0
    send: 12-12-0-0 s=0,c=0,t=0,pt=0,l=5,st=ok:1.4.1
    setup for switch: 5 complete
    send: 12-12-0-0 s=1,c=0,t=3,pt=0,l=5,st=ok:1.4.1
    read: 0-0-12 s=255,c=3,t=1,pt=0,l=10:1435918408

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

      @jeylites

      fyi, just pick one name...

      gw.sendSketchInfo("Relay", "1.0");
      gw.sendSketchInfo("Alarm Pannel", "1.0");

      What is this supposed to be doing? it looks like:

      reporting the state of three reed switches
      actuating a relay

      Why are you using the dalays? time?

      hard to really understand what you are trying to do here...

      1 Reply Last reply
      0
      • jeylitesJ Offline
        jeylitesJ Offline
        jeylites
        wrote on last edited by
        #7

        @BulldogLowell
        Essentially, I will like to combine Array Binary and Relay Actuator in one sketch.

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

          three binary switches and a single relay?

          1 Reply Last reply
          0
          • jeylitesJ Offline
            jeylitesJ Offline
            jeylites
            wrote on last edited by
            #9

            yes sir !

            1 Reply Last reply
            0
            • jeylitesJ Offline
              jeylitesJ Offline
              jeylites
              wrote on last edited by jeylites
              #10

              @BulldogLowell

              Any ideas how I can get this to work?

              Moshe LivneM B 2 Replies Last reply
              0
              • jeylitesJ jeylites

                @BulldogLowell

                Any ideas how I can get this to work?

                Moshe LivneM Offline
                Moshe LivneM Offline
                Moshe Livne
                Hero Member
                wrote on last edited by
                #11

                @jeylites it looks like you are overwriting i somewhere inside the loop. can you try to add prints of the value of i at several strategic points to see when it becomes 5? I would suggest to add one (and also print BUTTON_PIN[i]) before "msg[i].sensor = i;", one after "// Setup the button" and print i with the BUTTON_PIN[i].

                1 Reply Last reply
                0
                • jeylitesJ Offline
                  jeylitesJ Offline
                  jeylites
                  wrote on last edited by
                  #12

                  @Moshe-Livne

                  I'm going to try fix it as suggested. But the thing is it complies....

                  Moshe LivneM 1 Reply Last reply
                  0
                  • jeylitesJ jeylites

                    @Moshe-Livne

                    I'm going to try fix it as suggested. But the thing is it complies....

                    Moshe LivneM Offline
                    Moshe LivneM Offline
                    Moshe Livne
                    Hero Member
                    wrote on last edited by
                    #13

                    @jeylites Alas compiling is not a guarantee against memory overwrites....as button_pin should have shown 4 and not 5 i assume that either the index (i) got corrupt or the button_pin array.

                    1 Reply Last reply
                    0
                    • jeylitesJ jeylites

                      @BulldogLowell

                      Any ideas how I can get this to work?

                      B Offline
                      B Offline
                      BulldogLowell
                      Contest Winner
                      wrote on last edited by BulldogLowell
                      #14

                      @jeylites

                      I think this is what you want. I cannot test it right now, but it does compile:

                      #include <MySensor.h>
                      #include <SPI.h>
                      #include <Bounce2.h>
                      
                      #define NUMBER_OF_REEDS 3
                      
                      const int relayPin = 3;
                      const int reedPin[NUMBER_OF_REEDS] = {4, 5, 6};
                      
                      int reedState[NUMBER_OF_REEDS];
                      Bounce debouncer[NUMBER_OF_REEDS] = Bounce();
                      
                      MySensor gw;
                      MyMessage msg[NUMBER_OF_REEDS];
                      
                      void setup()
                      {
                        gw.begin(incomingMessage, AUTO, true);
                        gw.sendSketchInfo("Test", "1.0a");
                        gw.present(0, S_LIGHT);
                        pinMode(relayPin, OUTPUT);
                        digitalWrite(relayPin, gw.loadState(0));
                        for (int i = 0; i < NUMBER_OF_REEDS; i++)
                        {
                          debouncer[i].attach(reedPin[i]);
                          debouncer[i].interval(5);
                          pinMode(reedPin[i], INPUT_PULLUP);
                          gw.present(i, S_DOOR);
                          gw.wait(250);
                        }
                      }
                      
                      void loop()
                      {
                        gw.process();
                        for (int i = 0; i < NUMBER_OF_REEDS; i++) 
                        {
                          debouncer[i].update();
                          int value = debouncer[i].read();
                          if (value != reedState[i]) 
                          {
                            gw.send(msg[i+1].set(value), false); // device number mismatch here because of the array
                            reedState[i] = value;
                            Serial.print("updating state for switch: ");
                            Serial.print(reedPin[i]);
                            Serial.print(" state: ");
                            Serial.println(reedState[i]);
                          }
                        }
                      }
                      
                      void incomingMessage(const MyMessage &message)
                      {
                        if (message.type == V_LIGHT)
                        {
                          int newState = message.getBool();
                          digitalWrite(relayPin, newState);
                          gw.saveState(0, newState);
                          Serial.print(F("Incoming change for relay, New state: "));
                          Serial.println(newState);
                        }
                      }
                      

                      EDIT: Updated to correct debounce class errors

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

                        @jeylites

                        to turn relay off automatically after two minutes (and send the updated "off status" to controller... try something like this untested code:

                        #include <MySensor.h>
                        #include <SPI.h>
                        #include <Bounce2.h>
                        
                        #define NUMBER_OF_REEDS 3
                        
                        const int relayPin = 3;
                        const int reedPin[NUMBER_OF_REEDS] = {4, 5, 6};
                        
                        int reedState[NUMBER_OF_REEDS];
                        Bounce debouncer[NUMBER_OF_REEDS] = Bounce();
                        
                        unsigned long relayTimer;
                        
                        MySensor gw;
                        MyMessage msg[NUMBER_OF_REEDS];
                        MyMessage relayMessage(0,V_LIGHT);
                        
                        void setup()
                        {
                          gw.begin(incomingMessage, AUTO, true);
                          gw.sendSketchInfo("Test", "1.0a");
                          gw.present(0, S_LIGHT);
                          pinMode(relayPin, OUTPUT);
                          digitalWrite(relayPin, gw.loadState(0));
                          for (int i = 0; i < NUMBER_OF_REEDS; i++)
                          {
                            debouncer[i].attach(reedPin[i]);
                            debouncer[i].interval(5);
                            pinMode(reedPin[i], INPUT_PULLUP);
                            gw.present(i, S_DOOR);
                            gw.wait(250);
                          }
                        }
                        
                        void loop()
                        {
                          gw.process();
                          for (int i = 0; i < NUMBER_OF_REEDS; i++) 
                          {
                            debouncer[i].update();
                            int value = debouncer[i].read();
                            if (value != reedState[i]) 
                            {
                              gw.send(msg[i+1].set(value), false); // device number mismatch here because of the array
                              reedState[i] = value;
                              Serial.print("updating state for switch: ");
                              Serial.print(reedPin[i]);
                              Serial.print(" state: ");
                              Serial.println(reedState[i]);
                            }
                          }
                          if (millis() - relayTimer > 2 * 60 * 1000UL && digitalRead(relayPin)) // two minute timer
                          {
                            digitalWrite(relayPin, LOW);
                            gw.saveState(0, false);
                            gw.send(relayMessage.set(false), true);
                          }
                        }
                        
                        void incomingMessage(const MyMessage &message)
                        {
                          if (message.type == V_LIGHT)
                          {
                            int newState = message.getBool();
                            digitalWrite(relayPin, newState);
                            gw.saveState(0, newState);
                            if (newState)
                            {
                              relayTimer = millis();
                            }
                            Serial.print(F("Incoming change for relay, New state: "));
                            Serial.println(newState);
                          }
                        }
                        
                        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


                        20

                        Online

                        12.0k

                        Users

                        11.2k

                        Topics

                        113.4k

                        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