MODIFIED - SECRET KNOCK DOOR LOCK

Hi all, I've done a bunch of modifications to Steve Hoefer's code for his Secret Knock Detecting Door Lock. This is the changes that I've made:

-Added a Hall Effect Sensor to determine if the door is open or closed. -Swapped the gear motor with a servo. -Added a Serial LCD feedback screen. -Added a yellow LED. -Added a bunch of extra features. -Used the Arduino Mega.

Fritzing Diagram:

THE CODE:

Version 0.1: http://www.mediafire.com/?ghww3o5qde2 Version 0.2: http://www.mediafire.com/?nzd4yjojnzm (Easier to read code, UART LCD Interface)

MORE FILES ARE AVAILABLE AT http://mediafire.com/knocklock

This will be the first project I'm gonna build when my Arduino arrives from SparkFun.

If there is something wrong with the wiring or code, please post it here. My code really needs to be refined a bit too.

I might also connect the servo's power pin directly to the input voltage from my AC/DC adapter.

Please post any comments or advice. ;)

For some strange reason, you can't click on the download link, just copy and paste it into your browser window and you won't get a 403 error.

EDIT: Fixed

I'm gonna update the code in a few minutes to use the UART and not the SoftwareSerial library.

EDIT: Done.

-Used the Arduino Mega.

Maybe not such a positive thing.

Looks good though. I hope you have fun with your arduino ;)

Mowcius

Maybe not such a positive thing.

Looks good though. I hope you have fun with your arduino Wink

Mowcius

Why is using the Mega a bad thing? I would understand that if this project was more permanent, but please motivate.

Why is using the Mega a bad thing? I would understand that if this project was more permanent, but please motivate.

It is fine for a temporary project it's just that you could have done it on a normal arduino so a lot of people will try to flame you for that ;D

The mega is great though cos it gives you more program space.

I do like the project though. Why did you detect whether the door is open or not?

Mowcius

It is fine for a temporary project it's just that you could have done it on a normal arduino so a lot of people will try to flame you for that Grin

The mega is great though cos it gives you more program space.

I do like the project though. Why did you detect whether the door is open or not?

Mowcius

Yeah, I'd only make a project permanent if it was really useful. Overall I like the mega because of more flexibility, you're right about using a duemilanove or just the atmega for a more permanent solution. But it won't do any harm to use the mega, 'cos I don't plan to get another arduino, it's just a prototyping hobby for me.

I detected whether the door was open or not just because it would add a bit more action to the LEDs and the LCD, it's cool to see an LED light up and a line appear on the LCD when the door closes or opens. I've also coded it to not turn the lock when the door is open, I forgot to mention that I added a secret knock locking function and not just unlocking like the Steve Hoefer original code did. Updating... ::)

UPDATE:

Forgot to mention that my code also does locking on the right knock.

VERSION 0.3:

-Locking Button -Smarter LCD Line Output

Link: http://www.mediafire.com/download.php?jwxzjwn1jdy

instead of knockings, it would be fun with a recorded noise in mp3 format to unlock. or music, bad taste wouldnt get in... nofx:open, elvis:closed.

instead of knockings, it would be fun with a recorded noise in mp3 format to unlock. or music, bad taste wouldnt get in... nofx:open, elvis:closed.

:D

Hmm, maybe something simpler. Or if you are into a bit of elvis, get it to play it and only let people in who can identify the song!

Mowcius

Detecting a beat is relatively easy, it can make a cool project.

And the serious use; my phone can be my key. Hard to copy if the code resides embedded in some kind of noise. Access to the file mght be needed. Doable?

I have been working on some code for a similar (in principle) device that uses a pattern of turning the door knob as an input method. It is currently binary based for simplicity (a turned door handle corresponds to a 1 and a not turned knob a 0, this works because it is a time-based program) but I am working on a method that uses the knob as a rotary combination lock.

I have been working on some code for a similar (in principle) device that uses a pattern of turning the door knob as an input method. It is currently binary based for simplicity (a turned door handle corresponds to a 1 and a not turned knob a 0, this works because it is a time-based program) but I am working on a method that uses the knob as a rotary combination lock.

Now, THAT would be cool!

And the serious use; my phone can be my key. Hard to copy if the code resides embedded in some kind of noise. Access to the file mght be needed. Doable?

Yes, that could work great, you can record a very complex series of about 25 knocks and then save it on the arduino and your phone. On your phone you can just use a MP3 file. You can play it back quickly, like 5 knocks a second. In 5 seconds you can unlock the door.

I just finished writing the code for a really cool lock. It takes the rhythm-based code entry to a whole new level of awesome. Unfortunately it does require two separate Arduino boards; one of them serves as the lock, and the other the key. What makes it awesome is that the current combination that opens the lock switches between 20 possible combinations (there are really 9999 combinations, and one could use more than a set of 20, but I didn’t feel like writing the code for more than 20) 250,000 times per second. The lock and key must be turned on at the same time and maintain in sync within 8 microseconds of each other. That means that an unauthorized person attempting to copy the key may be able to extract the password set, however the case design that I have in mind will disconnect power to the key if the case is opened. This would cause the lock and key to lose synchronization with each other and the key to no longer function properly.

// lock circuit program
int codePin = 1;
int outPin = 2;
// the above pins were simply used for simplicity
// one could simply move them to other pins if desired
long ccv = 0;
int cv = 0;
int chksm = 0;
int rsintv = 4;
//value is set to 100 just because it ISNT zero
int value = 100;
int vselect = 0;
int tmhcount = 0;
long prevMicros = 0;
long tmhMicros = 0;

void setup() {
  pinMode(codePin, INPUT);
  pinMode(outPin, OUTPUT);
}

void loop() {
  unsigned long elpsdMicros = micros();
  
  if (elpsdMicros - prevMicros >= rsintv); {
    prevMicros = elpsdMicros;
    vselect = vselect++;
  }
  
  if (vselect == 1); {cv = 4297;};
  if (vselect == 2); {cv = 8263;};
  if (vselect == 3); {cv = 8922;};
  if (vselect == 4); {cv = 3758;};
  if (vselect == 5); {cv = 7111;};
  if (vselect == 6); {cv = 4009;};
  if (vselect == 7); {cv = 9421;};
  if (vselect == 8); {cv = 6335;};
  if (vselect == 9); {cv = 4426;};
  if (vselect == 10); {cv = 7570;};
  if (vselect == 11); {cv = 9562;};
  if (vselect == 12); {cv = 1052;};
  if (vselect == 13); {cv = 4644;};
  if (vselect == 14); {cv = 8970;};
  if (vselect == 15); {cv = 5577;};
  if (vselect == 16); {cv = 6644;};
  if (vselect == 17); {cv = 1227;};
  if (vselect == 18); {cv = 2153;};
  if (vselect == 19); {cv = 1679;};
  if (vselect == 20); {cv = 9001;};
  if (vselect > 20); {vselect = 0;};
  if (digitalRead(codePin) == HIGH); {
    ccv = cv*4;
    if (elpsdMicros - tmhMicros > 1); {
      tmhMicros = elpsdMicros;
      tmhcount++;
    }
    value = ccv - tmhcount;
    chksm = abs(value);
    if (chksm > 8); {
       tmhMicros = elpsdMicros;
       tmhcount++;
    }
    value = ccv - tmhcount;
    chksm = abs(value);
    if (chksm <= 12); {
      digitalWrite(outPin, HIGH);
          }
  }
}
// key program
long ccv = 0;
int cv = 0;
int vselect = 0;
int codePin = 1;
int rsintv = 4;
long prevMicros = 0;
long tmhMicros = 0;
int trnsfrPin = 2;

void setup() {
  pinMode(codePin, OUTPUT);
  pinMode(trnsfrPin, INPUT);
}

void loop() {
  unsigned long elpsdMicros = micros();
  
  if (elpsdMicros - prevMicros > rsintv); {
    prevMicros = elpsdMicros;
    vselect++;
  }
  /* the following segment contains 20 random passwords that
  will be rotated 250,000 times per second. If desired more
  can be added for increased complexity
  */
  if (vselect == 1); {cv = 4297;};
  if (vselect == 2); {cv = 8263;};
  if (vselect == 3); {cv = 8922;};
  if (vselect == 4); {cv = 3758;};
  if (vselect == 5); {cv = 7111;};
  if (vselect == 6); {cv = 4009;};
  if (vselect == 7); {cv = 9421;};
  if (vselect == 8); {cv = 6335;};
  if (vselect == 9); {cv = 4426;};
  if (vselect == 10); {cv = 7570;};
  if (vselect == 11); {cv = 9562;};
  if (vselect == 12); {cv = 1052;};
  if (vselect == 13); {cv = 4644;};
  if (vselect == 14); {cv = 8970;};
  if (vselect == 15); {cv = 5577;};
  if (vselect == 16); {cv = 6644;};
  if (vselect == 17); {cv = 1227;};
  if (vselect == 18); {cv = 2153;};
  if (vselect == 19); {cv = 1679;};
  if (vselect == 20); {cv = 9001;};
  if (vselect > 20); {vselect = 0;};
  if (digitalRead(trnsfrPin) == HIGH); {
    ccv = cv*4;
    digitalWrite(codePin, HIGH);
    //the code pin will be held at HIGH for the code value 
    //multiplied by 4 so as to account for the timing precision
    //of the board
    if(elpsdMicros - tmhMicros > ccv); {
      tmhMicros = elpsdMicros;
      digitalWrite(codePin, LOW);
    }
  }
}

I probably won't be doing any changes to the code for about 2 or 3 weeks, that's when my arduino stuff will arrive from SFE.

Hi All

Just a little comment: Instead of a Hall-Sensor a simple Reed-Relais (thats a switch operatet by a magnet) can do the job.
I bought some cheap door-alarms an modified it. I found one for less then five bucks and i got:

-3 LR44 Batteries
-the Reed Relais and magnet, all in a case with on/off switch and with screws
-piezo-speaker

My project was to play a sound when the door is open longer then 60s, because the room will get cold (and some familiy members always forget to close it)

That was befor I got my arduino so I used a serial-port of my linux-server to read the switch…

But to get a little bit on topic: Would it be possible to connet two piezos, placed some steps away at a stair to decide if one ist walking up or down?

by Andreas

You mean a Reed relay switch? Yes, you could use that too, but a Hall effect switch is simply what I have on hand. You might also want to modify the circuit and code a bit if you want to use a Reed relay.

For your question: Yes, but you might need lots of code and you'll get lots of wrong readings. It would be more accurate to use a laser and a photocell on a step or two, or you could use a rangefinder, there are lots of solutions.

You mean a Reed relay switch? Yes, you could use that too,

I think he means a magnetic reed switch in this case. A reed relay uses an internal magnetic reed switch activated by a coil, but in this case there is no relay coil activating the reed switch, just the magnetic reed switch activated by an external magnet.

Lefty