‘Knock Back’ – A Knock Echoing Arduino

A Knock Echoing Arduino

This is a simple Arduino sketch that was originally designed to experiment with arrays and the built-in timing functionality. I based it on the tutorial sample code http://www.arduino.cc/en/Tutorial/KnockA Knock Echoing Arduino

The system consists of a piezo sensor connected to an analog pin that listens for a knock from the user. The Arduino then stores the time the knock occurred in an array. After a predefined time without further knocks occurring, the Arduino will ‘play back’ the knocks on a buzzer and LED in time to the original knocking pattern.

The device could be expanded to include a stepper motor or similar suitable output that would recreate the knocks exactly, just replace the output buzzer.
You could also use the piezo input sensor as the output buzzer by altering the code.

Step 1: Materials

[box color=”#985D00″ bg=”#FFF8CB” font=”verdana” fontsize=”14 ” radius=”20 ” border=”#985D12″ float=”right” head=”Major Components in Project” headbg=”#FFEB70″ headcolor=”#985D00″]

You will need:

1. An Arduino UNO or compatible board.
2. An LED and appropriate resistor (I used 220R).
3. A piezo sensor.
4. A 1M pull-down resistor.
5. A piezo buzzer or alternative output device (see page one notes).
6. A breadboard and wires.[/box]

Step 2: Assemble

Assemble (1)

The configuration of the device is fairly simple.

1. Connect the LED to pin 9 (via the resistor) and GND.
2. Connect the output buzzer to pin 8 and GND.
3. Connect the knock senzor to analog pin 0 AND GND.
4. Connect your 1M resistor to the positive wire of the knock sensor and GND. This is used as a pull-down resistor.

Note: Be sure to check that my resistor recommendations are correct for the components you are using, including the lack of resistors on the two piezo buzzers.

Step 3: The Sketch

Upload the following to your Arduino.

/* Echoing Knock Sensor

This sketch reads a piezo element to detect a knocking sound.
It reads an analog pin and compares the result to a set threshold.
If the result is greater than the threshold, it stores the value of millis() to an array.
Following a defined period without additional knocks, the knocks are replayed by the device.

Created by Dan Nicholson <http://dannicholson.co.uk>
Based on “Knock Sensor” created 25 Mar 2007 by David Cuartielles <http://www.0j0.org> modified 30 Aug 2011 by Tom Igoe

*/

 

Read more: ‘Knock Back’ – A Knock Echoing Arduino

Leave a Comment

Your email address will not be published. Required fields are marked *