Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I am trying to figure out how to create a combination lock using logic gates, so that a password must be input (let's say pressing numbered buttons) in the correct order.

I understand logic gates completely, and have some of a grasp on flip-flops and latches, but I'm definitely getting stuck on how to use them in the right combination.

So as an example, if there are 3 buttons (call them 1, 2, & 3), I would like to be able to set a password such as 1 2 3 1 (hardcoded is fine), where they have to be input in that exact order, otherwise you have to start at the beginning again (1 2 3 3 3 3 1 will not work).

Any tips, links, hints on this?

share|improve this question
Tangential comment: You can most likely implement the whole thing in a CPLD quicker, easier and cheaper than using discrete logic components. Added benefit is that the attacker cannot see how the components are wired together. The question is still very relevant though, as you have to construct the whole thing out of logic gates one way or the other. – drxzcl Feb 16 '11 at 9:24

2 Answers

up vote 4 down vote accepted

I would probably use two bits to encode the three switches, and the general approach would be to have a string of pairs (one for each bit) of D or JK flip-flops to accept the sequence of input digits, essentially a shift register for pairs of bits. Then there would have to be de-bounce circuitry for the switches, and some way to generate a clock signal from the key presses (probably on release) to shift the digits through the register. Finally, XOR gates between the stages of the shift register and the digits of the key (hardwired to 1231 or use switches, etc) would produce signals to indicate when each digit is a correct match (logic Low on match), and then a multi-input NOR of the XOR outputs would give a final output signal that would indicate when the entire sequence in the shift register matches the key.

share|improve this answer
So you're saying make 1,2,3 into 00, 01, 10, then cycle through the password press by press, testing each press against the stored code in the shift register? – JustcallmeDrago Feb 16 '11 at 3:38
not exactly- first press would enter a pair of bits to the 1st stage of the shift register. 2nd press would shift the 1st code to the 2nd stage, and enter the new code in the 1st stage, and so on, so that at any point in time, if you have say 5 stages of shift register, you have the last 5 button presses represented. This 'latest-5' would be checked against the key value all the time. I.e., the key is not stored in the shift register, the key is just hardwired inputs to the XORs, or some hidden switch inputs to them; the shift reg stores the user input. – JustJeff Feb 16 '11 at 11:53
Makes sense, thanks a lot! The shift register is the component I needed. – JustcallmeDrago Feb 16 '11 at 18:38

A long long time ago I made a 'combination' lock with one button. It used a shift register. A long button press would shift in a 0, a short one would shift in a 1. (I used some resistors and capacitors to do this, but there are more elegant ways). The outputs of the shift register were connected to two inhibit lines using diodes. To open the lock, one inhibit line had to be pulled high (by a resistor), the other low. The code was determined by how the diodes connectd to the inhibit lines.

At that time I lived in a caravan. No toilet inside the caravan. The door automatically fell into the lock when I closed it behind me. Without the electronic lock I would have to dig up the spare key burried behind the 7th tree every time I forget to take the keys with me when I went for a nightly visit to the loo.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.