Code lock circuit using dual flip flop IC CD4013


Electronic Locks are highly useful to protect our possession and it was widely used in all places. The demand for Electronic locks is high since it offer high security and easy to handle rather than the mechanical locks. Most of the E-locks in the market are cost more and not everyone could afford buying these locks. The circuit above can be a best solution for those who want to build an effective and low cost Electronic lock.


This code lock circuit was build around two D type Flip Flops IC’s CD4013. The operation of a single D type Flip flop unit is very important to understand the working principle of the above circuit. The operation of a D type Flip flop is as follows: Any input appearing at the data input D during present state will appear at pin Q  during the next clock cycle. This operation principle forms backbone of the above code locker. The below truth table of IC CD4013 might give you the idea of its working.


In the above circuit the Switches 1,3,5,8 are wired to feed the clock pulse to each flip flop units U1:A,U1:B,U2:A and U2:B. Therefore the password for the above locker is “1358” and should be pressed in the given sequence. Now take a look at the first state of the given table where it was stated that when positive edge clock was fed in to the CLK pin of the IC when Data pin D was in low 0 state will result in Low and high state in Q and Q’ pins of the IC. This state was used in the whole circuit.

Initially D pin of the U1:A is grounded and this in turn gives low output at pin 1 Q when positive edge is encountered in the CLK pin of U1:A by pressing switch 1. The Pin 1(Q) was wired to the Data pin 9 of U1:B, this will place the low signal in it. When switch 3 is pressed the positive edge clock is fed to U1:B, this will force the Q pin of U1:B to exhibit low state which was fed in its data input. This process will continue as you press 5 and 8 switches. Finally after switch 8 is pressed the Q pin 13 of U2:B will gives a low signal which in turn turns the PNP transistor ON and therefore the relay gets activated.

When anything other than the Password switches “1358” is pressed Q pin of the  all the flips flops will obtain high 1 state as shown in the above table. Therefore the locker will remain in lock state. Pull down resistors R2,R3,R4 and R5 was used to ensure that the CLK pin was in low state before feeding the input pulse. A diode was added along with the relay to prevent the reverse flow of current which might damage the IC.


  • You can change the password sequence by appropriate wiring to the CLK pins of each flip flop units.
  • The VDD(power) and VSS(ground) pins of the IC was omitted for simplification of the schematic. 
  • Sometimes the IC 4013 may not start with high state on start up, in that case add a power on reset circuitry to the reset pins of flip flops.

Ask your query

2 Comment threads
2 Thread replies
Most reacted comment
Hottest comment thread
3 Comment authors
Frank DonaldAnonymousJINBEE Recent comment authors
newest oldest most voted
Notify of

what is the model name of relay ?.
is it spdt relay ? parameter values ?