SALES INQUIRIES: 1 (888) 767-9864

How to make a secret knock detector to trigger anything with only an Arduino and a few cheap components

There are a couple good use-case scenarios for making a secret knock detector using an Arduino.

  • You are a spy who needs to authenticate your cohorts
  • You are a super hero who wants a secret knock to open the entrance to your lair

Whatever the reason – by the end of this tutorial you will know how to use an Arduino, a piezo transducer and a couple other cheap components to make secret knock detector.

Here is an overview of exactly what we will talk about in this lesson:

  1. The components you will need and how to set up this simple circuit.
  2. The concept of operation of this secret knock detector
  3. A thorough description of each block of code in the Arduino sketch
  4. Why North American grizzly bears love piezo transducers

For this secret knock detector circuit you need:

  • Arduino (I use the Arduino Uno) [1]
  • Solderless breadboard [1]
  • 1 Mohm Resistor [1]
  • Piezo transducer (aka buzzer) [1]
  • Jumper wires [4]
  • 5.1V Zener diode (for extra protection) [1]
  • No spill stopper for a “to-go” coffee cup

How to set up the Circuit:

This is a really simple circuit to setup, below are step-by-step instructions and a breadboard diagram.

  1. Place the piezo transducer on the breadboard, with the positive lead and the negative lead on separate rails.
  2. Connect the positive lead to pin A0 on the Arduino and the other lead to ground.
  3. Finally, use the 1Mohm resistor to connect the leads of the piezo transducer.
  4. As an additional level of protection, you might consider adding a 5.1V zener diode between the leads to protect against high voltage spikes from frying your input pin – you might call it a cheap insurance policy.

Piezo buzzer circuit with Arduino

An Overview of this Secret Knock Detectors operation

Here is the basic concept of how this will work.

We want something to happen when you tap out a secret code.

We will create a sequence of soft and hard taps – this will be our secret code which will be represented as 0’s and 1’s in an array.

For example:

The code above represents a secret code of soft , soft , hard, soft .

The piezo transducer will turn the mechanical pressure created by the tap into a signal that the Arduino analog pin can read. The level of the signal will determine whether a tap gets characterized as soft or hard.

The threshold of a soft vs hard tap need to be determined empirically, once you have the circuit built – it will depend on what you have the piezo transducer attached to – I have mine taped to a piece of paper.

You should start with the default threshold values provided in the sketch and change them to suit your specific setup.

Once a tap signal is picked up by the Arduino, the sketch will compare the entered sequence of taps to the secret code, one tap at a time.

If the code is entered correctly, then we will trigger an action on the output pin. In this code below, we trigger an LED to turn on for a couple seconds – but you could trigger a servo arm, a pump, or whatever you might need.

If the code is entered incorrectly – nothing happens.

Here is the code for your hacking enjoyment:

If you enjoyed this lesson, you should join our free Arduino Crash Course – it has 19 Video Training lessons all about using Arduino (you can sign up below).