One Transistor Code Lock

Discussion in 'The Projects Forum' started by hzk17, May 2, 2013.

  1. hzk17

    Thread Starter Member

    Mar 20, 2013
    31
    0
    One Transistor Code Lock, Description: This is of course the simplest electronic code lock circuit one can make. The circuit uses one transistor, a relay and few passive components. The simplicity does not have any influence on the performance and this circuit works really fine.
    The circuit is nothing but a simple transistor switch with a relay at its collector as load. Five switches (S0 to S4) arranged in series with the current limiting resistor R2 is connected across the base of the transistor and positive supply rail. Another five switches (S5 to S9) arranged in parallel is connected across the base of the transistor and ground. The transistor Q1 will be ON and relay will be activated only if all the switches S0 to S4 are ON and S5 to S9 are OFF. Arrange these switches in a shuffled manner on the panel and that it. The relay will be ON only if the switches S0 to S9 are either OFF or ON in the correct combination. The device to be controlled using the lock circuit can be connected through the relay terminals. Transformer T1, bridge D1, capacitor C1 forms the power supply section of the circuit. Diode D2 is a freewheeling diode. Resistor R1 ensures that the transistor Q1 is OFF when there is no connection between its base and positive supply rail.

    I have almost made it three times and yet i dont know what the hell is wrong.
    *Important, I am using a DPDT Relay 5V, and the Supply being given by me is about 9V

    Please give me your kind suggestion, tips.
     
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,674
    2,724
    Why 2 sets of switches?

    You could just use the bottom row (any number of switches in parallel) and alternate between N.O. and N.C. to set the code. The benefit is the wiring will be *much* simpler to the panel -- only 2 wires to the switch bank.

    BTW, a drawback of this circuit is that it is far too easy to quickly guess the right code. A better, more secure, solution (though more complicated, of course) is to enforce a correct switch sequence, limit the amount of time necessary to enter the code, force a delay between multiple code entries, *and*, limit the number of times a wrong code can be entered before the operator is locked out.

    Edit: Further, why even use a transistor? You could just series a bank of N.O. and N.C. switches with the relay coil. Much simpler, don't you think?
     
    hzk17 likes this.
  3. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    If you are trying to use a 9v "transistor" battery with a 5v relay, the battery life will be very short. You would do much better to use three alkaline "D" cells in series for 4.5v. If you are using rechargeable batteries, then use four of them in series to get about 4.8v.

    The 1N4007 diode has a band towards one end of it; the band indicates the cathode, and in the schematic, the cathode is shown connected to the positive power supply. If you had the diode reversed, the coil would be effectively shorted out, and your poor transistor would likely have gotten fried.


    Remove S0 through S9 from your circuit.
    Then wire jumper directly from the bottom of R2 to the junction of Q1's base and R1.
    The relay coil should energize. If it does not, then make certain the transistor is OK, and you have the relay coil connected properly.

    Once you can energize/de-energize the coil using the wire jumper, then install S0 into the circuit, and move the jumper from the bottom of R2 to the bottom of S0. See if you can energize/de-energize the coil using S0.

    If that works, then leave S0 in the position where the coil is energized, move the jumper to the low side of where S1 goes, install S1 and see if you can energize/de-energize the coil using S1. If it doesn't work, try replacing S0 with another switch; perhaps it's not good - and check how you wired up the switch; maybe you have a bad connection.

    Repeat until you have all of the switches working.
     
    Last edited: May 2, 2013
    hzk17 likes this.
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Ten SPST switches makes for 1,023 wrong combinations and one correct combination; each switch you add doubles the complexity.

    Try doing that without using any IC's. Our OP is having a tough time getting the ten switch circuit to work; suggesting added complexity really isn't much help.

    That would also be more simple for someone to figure out how it works; thus what the combination is.
     
    hzk17 likes this.
  5. hzk17

    Thread Starter Member

    Mar 20, 2013
    31
    0
    Thanks alot SgtWookie and joeyd999
     
  6. hzk17

    Thread Starter Member

    Mar 20, 2013
    31
    0
    I am also going to use a dc toy motor and a buzzer, when incorrect sequence is entered, the buzzer should start, and when the correct sequence is entered the motor should start, so for that i am using the DPDT relay that is correct ?
     
  7. richard.cs

    Member

    Mar 3, 2012
    162
    31
    Well, you'd be right about the numbers if the buttons were pressed sequentially, (assuming the person trying to crack it already knows it's 5 buttons), but the way the system works makes it unexpectedly easy to brute force.

    If someone pushes and holds the first button the probability of it being corect is 5/10. If they are correct the second button is 4/9, the third 3/8, the fourth 2/7 and the 5th 1/6 so the actual probability of a random attempt being correct is (5*4*3*2*1)/(10*9*8*7*6) = 120/30240 = 1/252

    Consider now if someone holds down 4 buttons then mashes the keyboard in such a way that the remaining buttons are pushed one by one, not particularly hard to do in a couple of seconds but you significantly drop the number of attempts needed - the probability of each 4 buttons + keyboard mash hitting the correct answer is 1/42 (6 times more likely than getting 5 buttons).

    I've cracked a poorly designed bike lock in a couple of minutes before now where it had 3 levers with 12 positions each. You'd expect 12^3 combinations but because it used levers you could set the first two and flick the last lever to test 12 combinations at once, so you could actually try all the combinations in 144 attempts and about 3 minutes.
     
    joeyd999 likes this.
  8. Dodgydave

    Distinguished Member

    Jun 22, 2012
    4,977
    744
    So what is going wrong then ?
     
  9. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,674
    2,724
    Please elaborate. Why is a simple switch/relay configuration simpler to hack than the transistor solution?
     
Loading...