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.
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... :
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);
}
}
}
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?
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.