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. Doorbell hack

Doorbell hack

Scheduled Pinned Locked Moved Troubleshooting
13 Posts 3 Posters 5.4k 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
    msebbe
    wrote on last edited by
    #4
    This post is deleted!
    1 Reply Last reply
    0
    • M Offline
      M Offline
      msebbe
      wrote on last edited by
      #5

      Below is my working sketch. Could somebody help clean it up? I made this sketch by combining two sketches and removing some parts from each.

      /*
      
      
       this is set up for a 4 pin recv unit GND DATA DATA VCC
       plug GND into D2, DATA into D3 and D4, and VCC into D5
      */
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #include <RCSwitch.h>
      RCSwitch mySwitch = RCSwitch();
      
      #define CHILD_ID 3
      #define VCC_PIN 5 // source 5V up to 40mA from this pin
      #define GND_PIN 2 // sink up to 40mA on this pin
      #define DATA_PIN 3 // external int 1 on Uno
      
      MySensor gw;
      int oldValue = -1;
      int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID, V_TRIPPED);
      
      void setup()
      {
        gw.begin();
      
        // 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.
        gw.present(CHILD_ID, S_DOOR);
      
        // 433mhz Part
        pinMode(DATA_PIN, INPUT);
        // just leave D4 tristated
      
        pinMode(GND_PIN, OUTPUT);
        digitalWrite(GND_PIN, LOW);
      
        pinMode(VCC_PIN, OUTPUT);
        digitalWrite(VCC_PIN, HIGH);
      
      
        mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
      
      }
      
      static unsigned long count = 0;
      
      void loop()
      {
        if (mySwitch.available()) {
      
          int value = mySwitch.getReceivedValue(); // This is where 433mhz signal are recieved
          if (value == bell) {
          // Send in the new value
          gw.send(msg.set("1"));  // Gives doorbell status tripped
          
          
          delay(5000);
          gw.send(msg.set("0"));  // Gives doorbell status not tripped
        }
      
          mySwitch.resetAvailable();
          count = 0;
        }
        else {
          if (++count == 0) Serial.println("no activity");
        }
      
        
      }
      
      
      
      1 Reply Last reply
      0
      • B Offline
        B Offline
        BulldogLowell
        Contest Winner
        wrote on last edited by BulldogLowell
        #6

        not tested, but I'd look to do it like this... with non-blocking code in case of a second press of the doorbell within the 5second timeout:

        /*
         this is set up for a 4 pin recv unit GND DATA DATA VCC
         plug GND into D2, DATA into D3 and D4, and VCC into D5
        */
        
        #include <MySensor.h>
        #include <SPI.h>
        #include <Bounce2.h>
        #include <RCSwitch.h>
        RCSwitch mySwitch = RCSwitch();
        
        #define CHILD_ID 3
        #define VCC_PIN 5 // source 5V up to 40mA from this pin
        #define GND_PIN 2 // sink up to 40mA on this pin
        #define DATA_PIN 3 // external int 1 on Uno
        
        MySensor gw;
        const int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
        boolean tripped = false;
        // Change to V_LIGHT if you use S_LIGHT in presentation below
        MyMessage msg(CHILD_ID, V_TRIPPED);
        
        void setup()
        {
          gw.begin();
        
          // 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.
          gw.present(CHILD_ID, S_DOOR);
          // 433mhz Part
          pinMode(DATA_PIN, INPUT);
          // just leave D4 tristated
          pinMode(GND_PIN, OUTPUT);
          digitalWrite(GND_PIN, LOW);
          pinMode(VCC_PIN, OUTPUT);
          digitalWrite(VCC_PIN, HIGH);
          mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
        }
        
        void loop()
        {
          if (mySwitch.available())
          {
            tripped = (mySwitch.getReceivedValue() == bell);
            if (tripped)
            {
              gw.send(msg.set("1"));
              timerStart = millis();
              Serial.println(F("Ding Dong!!"));
            }
            mySwitch.resetAvailable();  //<<<<<<<<<< I think you want this here... I looked at the library on GitHub
          }
          if (tripped && millis() - timerStart > 5000UL)
          {
            gw.send(msg.set("0"));
            Serial.println(F("no activity"));
            tripped = false;
          }
        }
        

        again, I could not test it...

        M 1 Reply Last reply
        1
        • B BulldogLowell

          not tested, but I'd look to do it like this... with non-blocking code in case of a second press of the doorbell within the 5second timeout:

          /*
           this is set up for a 4 pin recv unit GND DATA DATA VCC
           plug GND into D2, DATA into D3 and D4, and VCC into D5
          */
          
          #include <MySensor.h>
          #include <SPI.h>
          #include <Bounce2.h>
          #include <RCSwitch.h>
          RCSwitch mySwitch = RCSwitch();
          
          #define CHILD_ID 3
          #define VCC_PIN 5 // source 5V up to 40mA from this pin
          #define GND_PIN 2 // sink up to 40mA on this pin
          #define DATA_PIN 3 // external int 1 on Uno
          
          MySensor gw;
          const int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
          boolean tripped = false;
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          MyMessage msg(CHILD_ID, V_TRIPPED);
          
          void setup()
          {
            gw.begin();
          
            // 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.
            gw.present(CHILD_ID, S_DOOR);
            // 433mhz Part
            pinMode(DATA_PIN, INPUT);
            // just leave D4 tristated
            pinMode(GND_PIN, OUTPUT);
            digitalWrite(GND_PIN, LOW);
            pinMode(VCC_PIN, OUTPUT);
            digitalWrite(VCC_PIN, HIGH);
            mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
          }
          
          void loop()
          {
            if (mySwitch.available())
            {
              tripped = (mySwitch.getReceivedValue() == bell);
              if (tripped)
              {
                gw.send(msg.set("1"));
                timerStart = millis();
                Serial.println(F("Ding Dong!!"));
              }
              mySwitch.resetAvailable();  //<<<<<<<<<< I think you want this here... I looked at the library on GitHub
            }
            if (tripped && millis() - timerStart > 5000UL)
            {
              gw.send(msg.set("0"));
              Serial.println(F("no activity"));
              tripped = false;
            }
          }
          

          again, I could not test it...

          M Offline
          M Offline
          msebbe
          wrote on last edited by msebbe
          #7

          @BulldogLowell said:

          not tested, but I'd look to do it like this... with non-blocking code in case of a second press of the doorbell within the 5second timeout:

          /*
           this is set up for a 4 pin recv unit GND DATA DATA VCC
           plug GND into D2, DATA into D3 and D4, and VCC into D5
          */
          
          #include <MySensor.h>
          #include <SPI.h>
          #include <Bounce2.h>
          #include <RCSwitch.h>
          RCSwitch mySwitch = RCSwitch();
          
          #define CHILD_ID 3
          #define VCC_PIN 5 // source 5V up to 40mA from this pin
          #define GND_PIN 2 // sink up to 40mA on this pin
          #define DATA_PIN 3 // external int 1 on Uno
          
          MySensor gw;
          const int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
          boolean tripped = false;
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          MyMessage msg(CHILD_ID, V_TRIPPED);
          
          void setup()
          {
            gw.begin();
          
            // 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.
            gw.present(CHILD_ID, S_DOOR);
            // 433mhz Part
            pinMode(DATA_PIN, INPUT);
            // just leave D4 tristated
            pinMode(GND_PIN, OUTPUT);
            digitalWrite(GND_PIN, LOW);
            pinMode(VCC_PIN, OUTPUT);
            digitalWrite(VCC_PIN, HIGH);
            mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
          }
          
          void loop()
          {
            if (mySwitch.available())
            {
              tripped = (mySwitch.getReceivedValue() == bell);
              if (tripped)
              {
                gw.send(msg.set("1"));
                timerStart = millis();
                Serial.println(F("Ding Dong!!"));
              }
            }
            if (tripped && millis() - timerStart > 5000UL)
            {
              gw.send(msg.set("0"));
              Serial.println(F("no activity"));
              tripped = false;
            }
            mySwitch.resetAvailable();// i am not familiar with your library, so I'm not sure where this would go... or if you even need it with the non-blocking code.
          }
          

          again, I could not test it...

          Thank you! Looks much better. I will test later today when its not 31 celsius outside :)

          B 1 Reply Last reply
          0
          • M msebbe

            @BulldogLowell said:

            not tested, but I'd look to do it like this... with non-blocking code in case of a second press of the doorbell within the 5second timeout:

            /*
             this is set up for a 4 pin recv unit GND DATA DATA VCC
             plug GND into D2, DATA into D3 and D4, and VCC into D5
            */
            
            #include <MySensor.h>
            #include <SPI.h>
            #include <Bounce2.h>
            #include <RCSwitch.h>
            RCSwitch mySwitch = RCSwitch();
            
            #define CHILD_ID 3
            #define VCC_PIN 5 // source 5V up to 40mA from this pin
            #define GND_PIN 2 // sink up to 40mA on this pin
            #define DATA_PIN 3 // external int 1 on Uno
            
            MySensor gw;
            const int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
            boolean tripped = false;
            // Change to V_LIGHT if you use S_LIGHT in presentation below
            MyMessage msg(CHILD_ID, V_TRIPPED);
            
            void setup()
            {
              gw.begin();
            
              // 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.
              gw.present(CHILD_ID, S_DOOR);
              // 433mhz Part
              pinMode(DATA_PIN, INPUT);
              // just leave D4 tristated
              pinMode(GND_PIN, OUTPUT);
              digitalWrite(GND_PIN, LOW);
              pinMode(VCC_PIN, OUTPUT);
              digitalWrite(VCC_PIN, HIGH);
              mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
            }
            
            void loop()
            {
              if (mySwitch.available())
              {
                tripped = (mySwitch.getReceivedValue() == bell);
                if (tripped)
                {
                  gw.send(msg.set("1"));
                  timerStart = millis();
                  Serial.println(F("Ding Dong!!"));
                }
              }
              if (tripped && millis() - timerStart > 5000UL)
              {
                gw.send(msg.set("0"));
                Serial.println(F("no activity"));
                tripped = false;
              }
              mySwitch.resetAvailable();// i am not familiar with your library, so I'm not sure where this would go... or if you even need it with the non-blocking code.
            }
            

            again, I could not test it...

            Thank you! Looks much better. I will test later today when its not 31 celsius outside :)

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

            @msebbe

            OK, I reviewed the arduino library and it looks like mySwitch.resetAvailable(); belonged higher in the code, so I edited it. You may want to be wary of that.

            M 1 Reply Last reply
            1
            • B BulldogLowell

              @msebbe

              OK, I reviewed the arduino library and it looks like mySwitch.resetAvailable(); belonged higher in the code, so I edited it. You may want to be wary of that.

              M Offline
              M Offline
              msebbe
              wrote on last edited by
              #9

              @BulldogLowell said:

              @msebbe

              OK, I reviewed the arduino library and it looks like mySwitch.resetAvailable(); belonged higher in the code, so I edited it. You may want to be wary of that.

              Ok thanks for your effort :+1:

              When compiling I get this error below. I think this should be quiet easy to fix but I dont understand this language yet :confused:

              sketch_jul03a.ino: In function 'void loop()':
              sketch_jul03a:49: error: 'timerStart' was not declared in this scope
              sketch_jul03a:54: error: 'timerStart' was not declared in this scope
              'timerStart' was not declared in this scope
              
              B 1 Reply Last reply
              0
              • M msebbe

                @BulldogLowell said:

                @msebbe

                OK, I reviewed the arduino library and it looks like mySwitch.resetAvailable(); belonged higher in the code, so I edited it. You may want to be wary of that.

                Ok thanks for your effort :+1:

                When compiling I get this error below. I think this should be quiet easy to fix but I dont understand this language yet :confused:

                sketch_jul03a.ino: In function 'void loop()':
                sketch_jul03a:49: error: 'timerStart' was not declared in this scope
                sketch_jul03a:54: error: 'timerStart' was not declared in this scope
                'timerStart' was not declared in this scope
                
                B Offline
                B Offline
                BulldogLowell
                Contest Winner
                wrote on last edited by
                #10

                @msebbe

                try inserting:

                unsigned long timerStart;
                

                to the header in the next line following:

                boolean tripped = false;
                
                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  msebbe
                  wrote on last edited by
                  #11

                  @BulldogLowell said:

                  unsigned long timerStart;

                  Thanks that worked, however nothing happends when I test by using the door bell. I will investigate this when I get home on monday and stick to my old sketch until then .

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

                    and you cn try this:

                    /*
                     this is set up for a 4 pin recv unit GND DATA DATA VCC
                     plug GND into D2, DATA into D3 and D4, and VCC into D5
                    */
                    
                    #include <MySensor.h>
                    #include <SPI.h>
                    #include <Bounce2.h>
                    #include <RCSwitch.h>
                    RCSwitch mySwitch = RCSwitch();
                    
                    #define CHILD_ID 3
                    #define VCC_PIN 5 // source 5V up to 40mA from this pin
                    #define GND_PIN 2 // sink up to 40mA on this pin
                    #define DATA_PIN 3 // external int 1 on Uno
                    
                    MySensor gw;
                    const int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
                    boolean tripped = false;
                    unsigned long timerStart;
                    // Change to V_LIGHT if you use S_LIGHT in presentation below
                    MyMessage msg(CHILD_ID, V_TRIPPED);
                    
                    void setup()
                    {
                      gw.begin();
                    
                      // 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.
                      gw.present(CHILD_ID, S_DOOR);
                      // 433mhz Part
                      pinMode(DATA_PIN, INPUT);
                      // just leave D4 tristated
                      pinMode(GND_PIN, OUTPUT);
                      digitalWrite(GND_PIN, LOW);
                      pinMode(VCC_PIN, OUTPUT);
                      digitalWrite(VCC_PIN, HIGH);
                      mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
                    }
                    
                    void loop()
                    {
                      if (mySwitch.available())
                      {
                        tripped = (mySwitch.getReceivedValue() == bell);
                        if (tripped)
                        {
                          gw.send(msg.set(true));
                          timerStart = millis();
                          Serial.println(F("Ding Dong!!"));
                        }
                        mySwitch.resetAvailable();  //<<<<<<<<<< I think you want this here... I looked at the library on GitHub
                      }
                      if (tripped && millis() - timerStart > 5000UL)
                      {
                        gw.send(msg.set(false));
                        Serial.println(F("no activity"));
                        tripped = false;
                      }
                    }
                    
                    M 1 Reply Last reply
                    0
                    • B BulldogLowell

                      and you cn try this:

                      /*
                       this is set up for a 4 pin recv unit GND DATA DATA VCC
                       plug GND into D2, DATA into D3 and D4, and VCC into D5
                      */
                      
                      #include <MySensor.h>
                      #include <SPI.h>
                      #include <Bounce2.h>
                      #include <RCSwitch.h>
                      RCSwitch mySwitch = RCSwitch();
                      
                      #define CHILD_ID 3
                      #define VCC_PIN 5 // source 5V up to 40mA from this pin
                      #define GND_PIN 2 // sink up to 40mA on this pin
                      #define DATA_PIN 3 // external int 1 on Uno
                      
                      MySensor gw;
                      const int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
                      boolean tripped = false;
                      unsigned long timerStart;
                      // Change to V_LIGHT if you use S_LIGHT in presentation below
                      MyMessage msg(CHILD_ID, V_TRIPPED);
                      
                      void setup()
                      {
                        gw.begin();
                      
                        // 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.
                        gw.present(CHILD_ID, S_DOOR);
                        // 433mhz Part
                        pinMode(DATA_PIN, INPUT);
                        // just leave D4 tristated
                        pinMode(GND_PIN, OUTPUT);
                        digitalWrite(GND_PIN, LOW);
                        pinMode(VCC_PIN, OUTPUT);
                        digitalWrite(VCC_PIN, HIGH);
                        mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
                      }
                      
                      void loop()
                      {
                        if (mySwitch.available())
                        {
                          tripped = (mySwitch.getReceivedValue() == bell);
                          if (tripped)
                          {
                            gw.send(msg.set(true));
                            timerStart = millis();
                            Serial.println(F("Ding Dong!!"));
                          }
                          mySwitch.resetAvailable();  //<<<<<<<<<< I think you want this here... I looked at the library on GitHub
                        }
                        if (tripped && millis() - timerStart > 5000UL)
                        {
                          gw.send(msg.set(false));
                          Serial.println(F("no activity"));
                          tripped = false;
                        }
                      }
                      
                      M Offline
                      M Offline
                      msebbe
                      wrote on last edited by
                      #13

                      @BulldogLowell said:

                      and you cn try this:

                      /*
                       this is set up for a 4 pin recv unit GND DATA DATA VCC
                       plug GND into D2, DATA into D3 and D4, and VCC into D5
                      */
                      
                      #include <MySensor.h>
                      #include <SPI.h>
                      #include <Bounce2.h>
                      #include <RCSwitch.h>
                      RCSwitch mySwitch = RCSwitch();
                      
                      #define CHILD_ID 3
                      #define VCC_PIN 5 // source 5V up to 40mA from this pin
                      #define GND_PIN 2 // sink up to 40mA on this pin
                      #define DATA_PIN 3 // external int 1 on Uno
                      
                      MySensor gw;
                      const int bell = -251;     // This is the value that my 433mhz doorbell sends out when button is pushed
                      boolean tripped = false;
                      unsigned long timerStart;
                      // Change to V_LIGHT if you use S_LIGHT in presentation below
                      MyMessage msg(CHILD_ID, V_TRIPPED);
                      
                      void setup()
                      {
                        gw.begin();
                      
                        // 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.
                        gw.present(CHILD_ID, S_DOOR);
                        // 433mhz Part
                        pinMode(DATA_PIN, INPUT);
                        // just leave D4 tristated
                        pinMode(GND_PIN, OUTPUT);
                        digitalWrite(GND_PIN, LOW);
                        pinMode(VCC_PIN, OUTPUT);
                        digitalWrite(VCC_PIN, HIGH);
                        mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3
                      }
                      
                      void loop()
                      {
                        if (mySwitch.available())
                        {
                          tripped = (mySwitch.getReceivedValue() == bell);
                          if (tripped)
                          {
                            gw.send(msg.set(true));
                            timerStart = millis();
                            Serial.println(F("Ding Dong!!"));
                          }
                          mySwitch.resetAvailable();  //<<<<<<<<<< I think you want this here... I looked at the library on GitHub
                        }
                        if (tripped && millis() - timerStart > 5000UL)
                        {
                          gw.send(msg.set(false));
                          Serial.println(F("no activity"));
                          tripped = false;
                        }
                      }
                      

                      Hmm, still nothing. It seems to be the 433mhz reciver part that is not working.

                      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


                      7

                      Online

                      12.1k

                      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