The following information is a single lesson in a larger project. Find more great projects here.
Make your own secret knocking mechanism in this project! A piezo buzzer usually creates vibrations, but this time you will use it as an input to detect how many times someone knocks on your door. You can take things a step further and automatically open a box with a servo motor if someone knocks the right number of times!
Step 1: Project Description
The piezo you used for playing back sounds in the theremin and keyboard projects can also be used as an input! When the piezo is pressed flat against a solid surface that can vibrate (like a wooden table top) your Arduino can sense the vibrations and read them with the analog input pins. Using this information your Arduino program can count how many times someone has knocked.
In this project, you will set a certain number of knocks as a secret code for opening a box. If someone knocks the right number of times, the box unlocks by moving the arm of a servo motor!
In this project, you will need the physical Arduino kit in order to use the piezo as an input component.
- Continue to the next step.
Step 2: Bill of Materials
You will need the following electrical components for this project:
1 piezo component
3 LEDs (red, yellow, and green)
3 220 ohm resistors
1 10 k-ohm resistor
1 M-ohm resistor
1 100 uF capactior
1 servo motor ...and of course your Arduino Uno and a breadboard!
It’s possible to build the circuit by itself, but it’s much more fun if you use this as a tool to lock something. If you are building your own locking box, you will also want some kind of container to modify, like a shoebox. You will also need a plastic arm adapter to attach to your servo motor spindle.
Can you match each component on the list to its location on the breadboard?
Continue to the next step.
Step 3: Knock Lock Circuit Diagram
There are many features to your knock lock project. A button will let you lock the motor in place. Some LEDs will give you status: a red LED indicates the box is locked, a green LED indicates the box is unlocked, a yellow LED lets you know if the right number of knocks has been received.
Take a look at the circuit diagram for this project and a description, below.
As usual, the servo motor will by operated by receiving pulses from a digital pin (pin 9).
Each LED is also simply connected to a digital output.
The piezo is connected to analog pin A0. We want the Arduino to sense a range of knock intensities, which result in different input voltages to this pin.
Continue to the next step.
Step 4: Writing a Function
You’ll also be writing your own function that will let you know if a knock is too loud or too soft.
Writing your own function helps save programming time by reusing code instead of writing it out many times. As you have seen in the past, functions can take arguments and return values. In this case, you’ll give your custom function the volume of the knock. If it is in the right range, you’ll change the value of a variable.
- Continue to the next step to learn how to build the Knock Lock circuit.
Next Lesson:Setting Up the Circuit
We have a be nice policy.
Please be positive and constructive.