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. one button code lock

one button code lock

Scheduled Pinned Locked Moved General Discussion
13 Posts 3 Posters 2.8k 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.
  • DickD Offline
    DickD Offline
    Dick
    wrote on last edited by Dick
    #1

    Can anybody help me with this project I found on the internet. It is not a MYSENSORS project but who can help me to make it working in Mysensors? I use a serial gateway to Domoticz. I want to use a match of the code in Domoticz.

    This is the code:

    int count=0;
    unsigned long a[]={0,0,0,0,0};
    unsigned long b[]={0,0,0,0,0};
    unsigned long del[]={1000,1000,1000,5000}; 
    
    float tolerance=.4;
    
    void setup()
    {
    pinMode(2, INPUT);
    pinMode(10, OUTPUT);
    pinMode(13, OUTPUT);
    }
    
    void dataCapture()
    {
    a[count]=millis();
    delay(500); // for button debounce, your value may differ
    count++;
    }
    
    void checkCombination()
    {
    int compare=0;
    count=0;
    // calcualate delays between keypresses
    b[0]=a[1]-a[0];
    b[1]=a[2]-a[1];
    b[2]=a[3]-a[2];
    b[3]=a[4]-a[3];
    
    // compare the button delay values 
    if (b[0]<=(del[0]*(1+tolerance)) && b[0]>=(del[0]*(1-tolerance))) { compare++; }
    if (b[1]<=(del[1]*(1+tolerance)) && b[1]>=(del[1]*(1-tolerance))) { compare++; } 
    if (b[2]<=(del[2]*(1+tolerance)) && b[2]>=(del[2]*(1-tolerance))) { compare++; }
    if (b[3]<=(del[3]*(1+tolerance)) && b[3]>=(del[3]*(1-tolerance))) { compare++; }
    if (compare==4) { digitalWrite(10,HIGH); }
    delay(3000); 
    digitalWrite(10,LOW);
    if (compare!=4) { digitalWrite(13,HIGH); }
    delay(3000);
    digitalWrite(13,LOW);
    
    
    }
    
    void loop()
    {
    if (digitalRead(2)==HIGH)
    {
    dataCapture();
    }
    if (count>4)
    {
    checkCombination();
    }
    }
    
    mfalkviddM 1 Reply Last reply
    0
    • DickD Dick

      Can anybody help me with this project I found on the internet. It is not a MYSENSORS project but who can help me to make it working in Mysensors? I use a serial gateway to Domoticz. I want to use a match of the code in Domoticz.

      This is the code:

      int count=0;
      unsigned long a[]={0,0,0,0,0};
      unsigned long b[]={0,0,0,0,0};
      unsigned long del[]={1000,1000,1000,5000}; 
      
      float tolerance=.4;
      
      void setup()
      {
      pinMode(2, INPUT);
      pinMode(10, OUTPUT);
      pinMode(13, OUTPUT);
      }
      
      void dataCapture()
      {
      a[count]=millis();
      delay(500); // for button debounce, your value may differ
      count++;
      }
      
      void checkCombination()
      {
      int compare=0;
      count=0;
      // calcualate delays between keypresses
      b[0]=a[1]-a[0];
      b[1]=a[2]-a[1];
      b[2]=a[3]-a[2];
      b[3]=a[4]-a[3];
      
      // compare the button delay values 
      if (b[0]<=(del[0]*(1+tolerance)) && b[0]>=(del[0]*(1-tolerance))) { compare++; }
      if (b[1]<=(del[1]*(1+tolerance)) && b[1]>=(del[1]*(1-tolerance))) { compare++; } 
      if (b[2]<=(del[2]*(1+tolerance)) && b[2]>=(del[2]*(1-tolerance))) { compare++; }
      if (b[3]<=(del[3]*(1+tolerance)) && b[3]>=(del[3]*(1-tolerance))) { compare++; }
      if (compare==4) { digitalWrite(10,HIGH); }
      delay(3000); 
      digitalWrite(10,LOW);
      if (compare!=4) { digitalWrite(13,HIGH); }
      delay(3000);
      digitalWrite(13,LOW);
      
      
      }
      
      void loop()
      {
      if (digitalRead(2)==HIGH)
      {
      dataCapture();
      }
      if (count>4)
      {
      checkCombination();
      }
      }
      
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @Dick using parts of https://github.com/mysensors/MySensors/blob/development/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino should be fairly straightforward.

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

        this is the code untill now with one compilation error. I installed the Arduino IDE and add the Mysensors master to it but it did not solve the proble.

        
        #include <SPI.h>
        #include <MySensors.h>
        
        //#define SKETCH_NAME "One Button Code Lock"
        #define CHILD_ID_CODE 5
        #define RELAY_PIN 3 //Arduino Digital I/O pin number for relay
        #define BUTTON_PIN  2  // Arduino Digital I/O pin for button/reed switch
        #define LED_PIN 4
        #define RELAY_ON 1
        #define RELAY_OFF 0
        
        MySensor gw;
        
        
        //original code code_lock
        int count=0;
        unsigned long a[]={0,0,0,0,0};
        unsigned long b[]={0,0,0,0,0};
        unsigned long del[]={1000,1000,1000,5000}; 
        
        float tolerance=.4;
        MyMessage msg(CHILD_ID,V_TRIPPED);
        
        void setup()
        {
          gw.begin();
        pinMode(BUTTON_PIN, INPUT);
        pinMode(RELAY_PIN, OUTPUT);
        pinMode(LED_PIN, OUTPUT);
        }
        
        void dataCapture()
        {
        a[count]=millis();
        delay(500); // for button debounce, your value may differ
        count++;
        }
        
        void checkCombination()
        {
        int compare=0;
        count=0;
        // calcualate delays between keypresses
        b[0]=a[1]-a[0];
        b[1]=a[2]-a[1];
        b[2]=a[3]-a[2];
        b[3]=a[4]-a[3];
        
        // compare the button delay values 
        if (b[0]<=(del[0]*(1+tolerance)) && b[0]>=(del[0]*(1-tolerance))) { compare++; }
        if (b[1]<=(del[1]*(1+tolerance)) && b[1]>=(del[1]*(1-tolerance))) { compare++; } 
        if (b[2]<=(del[2]*(1+tolerance)) && b[2]>=(del[2]*(1-tolerance))) { compare++; }
        if (b[3]<=(del[3]*(1+tolerance)) && b[3]>=(del[3]*(1-tolerance))) { compare++; }
        if (compare==4) { digitalWrite(RELAY_PIN,HIGH); }
        delay(3000); 
        digitalWrite(RELAY_PIN,LOW);
        if (compare!=4) { digitalWrite(LED_PIN,HIGH); }
        delay(3000);
        digitalWrite(LED_PIN,LOW);
        gw.present(CHILD_ID, S_DOOR);
        
        }
        
        void loop()
        {
        if (digitalRead(2)==HIGH)
        
        gw.send(msg.set(value==HIGH ? 1 : 0));
        
        {
        dataCapture();
        }
        if (count>4)
        {
        checkCombination();
        }
        }
        
        
        
        

        the error code during compilation is
        Using library SPI at version 1.0 in folder: C:\Program Files (x86)\arduino-1.6.11\hardware\arduino\avr\libraries\SPI
        exit status 1
        Error compiling for board Arduino Nano.
        This is also during the selection of an UNO.
        Any idea???
        And is this code working using the 1.5.4. lib.

        DickD 1 Reply Last reply
        0
        • DickD Dick

          this is the code untill now with one compilation error. I installed the Arduino IDE and add the Mysensors master to it but it did not solve the proble.

          
          #include <SPI.h>
          #include <MySensors.h>
          
          //#define SKETCH_NAME "One Button Code Lock"
          #define CHILD_ID_CODE 5
          #define RELAY_PIN 3 //Arduino Digital I/O pin number for relay
          #define BUTTON_PIN  2  // Arduino Digital I/O pin for button/reed switch
          #define LED_PIN 4
          #define RELAY_ON 1
          #define RELAY_OFF 0
          
          MySensor gw;
          
          
          //original code code_lock
          int count=0;
          unsigned long a[]={0,0,0,0,0};
          unsigned long b[]={0,0,0,0,0};
          unsigned long del[]={1000,1000,1000,5000}; 
          
          float tolerance=.4;
          MyMessage msg(CHILD_ID,V_TRIPPED);
          
          void setup()
          {
            gw.begin();
          pinMode(BUTTON_PIN, INPUT);
          pinMode(RELAY_PIN, OUTPUT);
          pinMode(LED_PIN, OUTPUT);
          }
          
          void dataCapture()
          {
          a[count]=millis();
          delay(500); // for button debounce, your value may differ
          count++;
          }
          
          void checkCombination()
          {
          int compare=0;
          count=0;
          // calcualate delays between keypresses
          b[0]=a[1]-a[0];
          b[1]=a[2]-a[1];
          b[2]=a[3]-a[2];
          b[3]=a[4]-a[3];
          
          // compare the button delay values 
          if (b[0]<=(del[0]*(1+tolerance)) && b[0]>=(del[0]*(1-tolerance))) { compare++; }
          if (b[1]<=(del[1]*(1+tolerance)) && b[1]>=(del[1]*(1-tolerance))) { compare++; } 
          if (b[2]<=(del[2]*(1+tolerance)) && b[2]>=(del[2]*(1-tolerance))) { compare++; }
          if (b[3]<=(del[3]*(1+tolerance)) && b[3]>=(del[3]*(1-tolerance))) { compare++; }
          if (compare==4) { digitalWrite(RELAY_PIN,HIGH); }
          delay(3000); 
          digitalWrite(RELAY_PIN,LOW);
          if (compare!=4) { digitalWrite(LED_PIN,HIGH); }
          delay(3000);
          digitalWrite(LED_PIN,LOW);
          gw.present(CHILD_ID, S_DOOR);
          
          }
          
          void loop()
          {
          if (digitalRead(2)==HIGH)
          
          gw.send(msg.set(value==HIGH ? 1 : 0));
          
          {
          dataCapture();
          }
          if (count>4)
          {
          checkCombination();
          }
          }
          
          
          
          

          the error code during compilation is
          Using library SPI at version 1.0 in folder: C:\Program Files (x86)\arduino-1.6.11\hardware\arduino\avr\libraries\SPI
          exit status 1
          Error compiling for board Arduino Nano.
          This is also during the selection of an UNO.
          Any idea???
          And is this code working using the 1.5.4. lib.

          DickD Offline
          DickD Offline
          Dick
          wrote on last edited by
          #4

          anybodey an idea?

          TheoLT 1 Reply Last reply
          0
          • DickD Dick

            anybodey an idea?

            TheoLT Offline
            TheoLT Offline
            TheoL
            Contest Winner
            wrote on last edited by
            #5

            @Dick I'm sorry my friend. This kind of projects our my favorites to get into. But I'm a bit too occupied at the moment. Maybe in the weekend after next, if somebody else hasn't help you before that.

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

              @TheoL Nevermind, I am on holiday and I only prepare some projects and this was one of them. If you have time later this week or next week, take your time. Compliment for your website. strait forward and it giave me also some ideas about houtbewerking.
              have a nice evening.

              mfalkviddM TheoLT 2 Replies Last reply
              0
              • DickD Dick

                @TheoL Nevermind, I am on holiday and I only prepare some projects and this was one of them. If you have time later this week or next week, take your time. Compliment for your website. strait forward and it giave me also some ideas about houtbewerking.
                have a nice evening.

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

                @Dick the code you posted above is for MySensors 1.x. That is fine, I'm still using version 1.5 myself. But the code won't work with MySensors 2.0 installed, you need to have only MySensors 1.5 installed. MySensors 1.5 uses

                #include <MySensor.h>
                

                while 2.0 uses

                #include <MySensors.h>
                

                (notice the added "s").

                If you want to convert the code to use MySensors 2.0, use this guide.

                If I change the code to use MySensor.h, I get the following compilation errors:

                Build options changed, rebuilding all
                sketch_aug31a:23: error: 'CHILD_ID' was not declared in this scope
                
                 MyMessage msg(CHILD_ID, V_TRIPPED);
                
                               ^
                
                C:\Users\Micke\AppData\Local\Temp\arduino_modified_sketch_587105\sketch_aug31a.ino: In function 'void checkCombination()':
                
                sketch_aug31a:73: error: 'CHILD_ID' was not declared in this scope
                
                   gw.present(CHILD_ID, S_DOOR);
                
                              ^
                
                C:\Users\Micke\AppData\Local\Temp\arduino_modified_sketch_587105\sketch_aug31a.ino: In function 'void loop()':
                
                sketch_aug31a:81: error: 'value' was not declared in this scope
                
                     gw.send(msg.set(value == HIGH ? 1 : 0));
                
                                     ^
                
                exit status 1
                'CHILD_ID' was not declared in this scope
                

                The error message says that the compiler doesn't know what CHILD_ID is when it is trying to look at

                MyMessage msg(CHILD_ID, V_TRIPPED);
                

                That is because CHILD_ID has not been defined. I think you meant to use

                #define CHILD_ID 5
                

                instead of

                #define CHILD_ID_CODE 5
                

                The next error,

                sketch_aug31a:81: error: 'value' was not declared in this scope
                     gw.send(msg.set(value == HIGH ? 1 : 0));
                

                means that the compiler is unable to find out what "value" is, since it has not been used before. Depending on what logic you want here, different things need to be done.

                Use the code formatting tool in the Arduino IDE (Tools->Auto format) to make the code easier to read. It helps a lot when trying to spot mistakes.

                1 Reply Last reply
                1
                • DickD Offline
                  DickD Offline
                  Dick
                  wrote on last edited by
                  #8

                  Thanks for the reply. I modified the items you stated in your reply. I did not know the use of the "auto format" tools. that makes life easier. About the logic I want to use is the status of the relay "digitalWrite(RELAY_PIN, HIGH); " so I can use that info in Domoticz.

                  mfalkviddM 1 Reply Last reply
                  0
                  • DickD Dick

                    Thanks for the reply. I modified the items you stated in your reply. I did not know the use of the "auto format" tools. that makes life easier. About the logic I want to use is the status of the relay "digitalWrite(RELAY_PIN, HIGH); " so I can use that info in Domoticz.

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

                    @Dick in that case

                    gw.send(msg.set(HIGH));
                    

                    should be sufficient.

                    DickD 1 Reply Last reply
                    0
                    • DickD Dick

                      @TheoL Nevermind, I am on holiday and I only prepare some projects and this was one of them. If you have time later this week or next week, take your time. Compliment for your website. strait forward and it giave me also some ideas about houtbewerking.
                      have a nice evening.

                      TheoLT Offline
                      TheoLT Offline
                      TheoL
                      Contest Winner
                      wrote on last edited by
                      #10

                      @Dick Thank you for the compliments on my website. This is the one of the reasons why I've started with it. I know have been a slacker regarding my blog. But I've got a vacation planned at the end of September and I need to finish some smaller projects before the winter sets in.

                      DickD 1 Reply Last reply
                      0
                      • mfalkviddM mfalkvidd

                        @Dick in that case

                        gw.send(msg.set(HIGH));
                        

                        should be sufficient.

                        DickD Offline
                        DickD Offline
                        Dick
                        wrote on last edited by
                        #11

                        @mfalkvidd , I added the change you advised and no erroros in the compilation anymore.
                        I will post the result after my testing of the project. Thanks for the support.

                        1 Reply Last reply
                        1
                        • TheoLT TheoL

                          @Dick Thank you for the compliments on my website. This is the one of the reasons why I've started with it. I know have been a slacker regarding my blog. But I've got a vacation planned at the end of September and I need to finish some smaller projects before the winter sets in.

                          DickD Offline
                          DickD Offline
                          Dick
                          wrote on last edited by
                          #12

                          @TheoL Finish what is needed, 
                          mfalkvidd gave me already some advise so next week I can test the project. I hope you have a good holiday. Again about the other hobby, working with wood, it is also one of my hobbies. Most of the time only creating housings for my projects. next year I want to start an CNC project.

                          TheoLT 1 Reply Last reply
                          0
                          • DickD Dick

                            @TheoL Finish what is needed, 
                            mfalkvidd gave me already some advise so next week I can test the project. I hope you have a good holiday. Again about the other hobby, working with wood, it is also one of my hobbies. Most of the time only creating housings for my projects. next year I want to start an CNC project.

                            TheoLT Offline
                            TheoLT Offline
                            TheoL
                            Contest Winner
                            wrote on last edited by
                            #13

                            @Dick I love CNC projects. I want to do my first lamination project as a housing for a MySensors project. And also would love the build the Japanese lamp for which I've created the gesture controlled lamp.

                            I recently purchased a decent table saw from the LIDL. Well it's better than what I have. So I hope to speed up my projects. I've mounted it last Saturday and it works. I've got a new 2000W tool ;-)

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


                            7

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.0k

                            Posts


                            Copyright 2019 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