Build | Fix | Re-use

Create Your Own Secret Knock Activated Drawer Lock

Check out this great DIY Project over at Adafruit submitted by Steve Hoefer.



Nothing says “There’s something valuable here!” than the sight of a lock. But what if the lock was invisible and the unlocking key could be transmitted through solid matter? No one would even know there was a lock, much less how to pick it.

That’s what the Secret Knock Activated Drawer Lock does. It hides all of the lock mechanism away and can only be unlocked by something you know: a secret pattern of knocks.

A solenoid locks secures the drawer while a piezo buzzer listens for knocks. A Trinket compares the knock pattern to the stored secret knock and if they match the solenoid latch retracts and the drawer can be opened. Setting your own custom knock is as simple as holding down a button and tapping the new rhythm.

The project is relatively straight forward and you should be able to complete it in an afternoon.

As always, read and understand this guide completely before starting the project.

Parts & Tools

This project only requires common tools and materials. You might need to make changes or additions depending on your specific installation.

Parts & Materials

  • A drawer or door (Preferably wood, without a latch.)
  • Adafruit Trinket 5V.
  • Lock-style solenoid. 12V.
  • Piezo Buzzer. 0.5″ – 1″ (12mm-24mm) diameter.
  • TIP120 Darlington Transistor.
  • 1MΩ 1/4W resistor.
  • 10KΩ 1/4W resistor.
  • 2.2KΩ 1/4W resistor.
  • 12V 1A power supply. (With 2.1mm center positive power plug.)
  • or, a 8xAA battery pack (w/2.1mm plug) – will last about a week powering the circuit
  • 2.1 mm barrel jack.
  • 1N4001 diode
  • Perfboard.
  • Hookup Wire.
  • (6x) #4 3/8″ round head wood screws. (Length depends on your installation. I used 2 1/2″ and (4) 3/4″ screws for the demonstration.)
  • Thin scrap wood. (Again, this depends on your installation. I used 6″ of 1/2″ square dowel and 2″ of 1/4″ square dowel for the demonstration.)


  • Safety glasses
  • Soldering iron & solder
  • Wire cutters
  • Wire strippers
  • Drill and assorted drill bits
  • Pliers
  • Screw driver
  • Ruler


Getting Started

If you’re not already experienced with the Trinket microcontroller, take the time to set it up and make sure you can load working code onto it. The “Introducing Trinket” guide will walk you through everything you need to know to get it set up and working.You will also need a good drawer or door to install the lock. A “good” drawer means:

  • At least 2 1/4″ deep. (57mm)
  • A wood front at least 3/8″ (10mm) thick.
  • Something that you can drill holes into without getting into trouble.

This project demonstrates installing it on a drawer but you could easily put it on the inside of a cabinet door.



This project uses straight-forward Arduino code and the standard Arduino EEPROM library. If you haven’t set up the Arduino IDE to work with the Trinket yet, follow the “Introducing Trinket” guide before continuing.Copy and paste this code into a new sketch and upload it to your Trinket.

For the curious, here’s a quick summary of what the code does:

  1. It initializes everything, set the appropriate input and output pins, and loads the saved knock pattern (if any) from EEPROM.
  2. After everything is initialized it listens for a spike on the piezo sensor. When its above a certain threshold it counts as a “knock”.
  3. When it hears a knock it starts a timer and then listens for more knocks.
  4. When it gets another knock it saves the time between knocks to an array.
  5. When there are no more knocks (There is at least 1.2 seconds without a knock) it checks to see if the sequence is correct.
  6. It does this by normalizing the time between knocks, that is making them relative to each other, not the exact milliseconds between them. So the longest time between knocks becomes 100, half that time becomes 50, etc. To use the language of music whole notes are 100, half notes are 50, quarter notes are 25, etc.
  7. It compares these values to the stored knock. If they match (or nearly match) the lock opens for a couple seconds and then goes back to #2. If the knock doesn’t match, it blinks a light for failure and then goes back to #2.

It does other things too, like read the button to see if it should program a new knock, etc.

The code is liberally commented and but here are a couple things you might be interested in modifying:

int threshold = 3;

(line 29) If the knock sensor is too sensitive you can try raising this value. Usually values below 10 work best, but values up to 250 have been known to work. (If you need to raise this above 250 then you probably have something wrong with your circuit or components.)

const int rejectValue = 25;

const int averageRejectValue = 15;

(line 30-ish) These two percentages indicate how accurate the knock needs to be to unlock. Raising these numbers allows a sloppier knock to work. Lowering them requires a more strict knock.



I recommend building the circuit on a solderless breadboard first to make sure that everything works before soldering it into place. Check out the “Operation” section for use and testing.The diagrams/images below are all the same circuit represented in different ways. Use whichever are most helpful.


Build Notes:

1: The Piezo.
Solder the piezo buzzer to the back of the PCB so it can be installed flush against the desk/drawer/etc and hear knocks more clearly.

2: Wire Length. The length of wire between the lock and the knock sensor depends on where you plan to mount it. (See “Installation” section for more information.) Measure your distances and be sure to allow some extra for movement of drawers and doors. You should be able to put the lock several feet from the detector without any problems.

If you’re installing them close to each other then simply cut the connector off the solenoid lock.

3: Programming. The circuit uses the Trinket’s pin #3. In some cases you might need to disconnect the 2.2KΩ resistor from pin #3 to program the circuit.

Note that my sample programs just fine with pin 3 connected, but your mileage may vary. If you want to be extra sure of being able to program it after it’s soldered in place consider using female headers to mount the Trinket, or put a jumper between pin #3 and the 2.2KΩ resistor.



Make sure everything works before installing it.

Unplug the Trinket from USB and plug in the 12V power supply and then be sure it can accurately detect a knock, unlock on command, and record new knocks, as described below.

If it doesn’t behave, see the “Troubleshooting” section for what might be going wrong.


  1. The Trinket’s green power LED will light up.
  2. The Trinket’s red LED will light up.
  3. The solenoid lock will click open twice. (First really quickly, the second time for about a second or two.)
  4. The Trinket’s red LED will turn off and the lock will close.

When the red light goes out and the lock closes, it’s now listening for a knock and is ready to go.

The default secret knock is the classic Shave And A Haircut. To change it, see “recording” below.

  1. The red LED will blink when it senses a knock. (It should also sense if you lightly tap the piezo with your finger.)
  2. If the wrong sequence if knocks (or taps) is detected the red LED will flicker briefly.
  3. If the correct sequence is detected the red LED will light and the lock solenoid will retract for a couple seconds.

Recording a new secret knock:

  1. Press the record button. The red LED will light and the piezo will play a short tone to let you know its listening for a new knock. (Note: This button won’t work if it senses a knock in the last couple of seconds.)
  2. (If you change your mind, press the button again and the red light will go off, and it will play a different tone.)
  3. Kock your new knock pattern. The red light will blink off when it hears a knock.
  4. When you’re done, wait a second or two for it to register. It will then playback the knock pattern by both blinking the red LED and beeping the piezo.
  5. This is now saved as a new knock and it will be remembered even if it’s powered off.
  6. If you don’t like the knock or you made a mistake, press the button again to record a different pattern.

Now that you’re sure that it works, it’s time to install it.

Installing The Lock Solenoid

First you need to rotate the latch so it will latch when you close the drawer or door.

  1. Remove the screws from the solenoid cover. (One of mine was hidden under a sticker.)
  2. Remove the E-ring ring that holds the latch slug in place. (It’s kind of hidden between the spring and the square brass collar.) If you don’t have the specific tool from removing these, you can usually pry it off with needle-nose pliers and/or a screwdriver.
  3. Rotate the latch slug 90º so the long square side is on the side of the lock with the mounting holes.
  4. Replace the E-ring and screw the cover back on.

We’ll do the simplest installation which places the lock solenoid on the front of the drawer and latches against the frame of the drawer or door.

The lock solenoid needs to have enough spacers behind it so the latch will clear the frame when the drawer is closed so the latch will lock.

The latch also needs to be able to move freely when the drawer is closed. The solenoid isn’t super powerful, and if it’s wedged too tightly it won’t retract when activated. You will probably need to add add some spacers between the lock and the drawer/door.

Position it vertically so the latch smoothly slides under the drawer frame and fasten it in place with #4 wood screws. Drill pilot holes for the screws so the wood doesn’t split.



For example in the side view above, the drawer frame is 3/4″ (19mm) thick. The latch has 5/16″ (8mm) of clearance built in, so I need to add 1/2″ (12mm) of clearance to make sure it clears the frame and can still retract fully. I used two short pieces of 1/2″ square dowel.

Installing The Lock Sensor

The knock sensor needs to be fastened somewhere out of sight, but where you can knock easily and clearly on the other side. For a door that location is probably on the inside of the door. For a drawer it can be inside of the face of the drawer, along the side of the cabinet or under the surface of a the desk.

Wherever you put it you’ll probably want to be able to reach the programming button.

Use 1/2″ #4 wood screws to attach the perfboard to the inside of the sounding surface. Attach it so the piezo is against the knocking surface, and carefully tighten the screws to hold it in place. Reinforce and stabilize the perf board with some spacers of scrap lumber. (I used a bit of 1/4″ (6mm) square dowel between the perfboard and the drawer face, you can see it to the left in the picture below.)

After everything is in place and tested, tack the cables in place with hot glue, cable ties, or cable staples.


You’re done!

Remember: if you forget the knock or something else goes wrong you can disconnect the power for a moment to unlatch the lock for a couple seconds. If you run into any problems check out the Troubleshooting guide, Otherwise enjoy your super secret hiding place!

Leave a Reply