The code example will capture the knock and if it is stronger than a certain threshold, it will send the string "Knock!" back to the computer over the serial port. In order to see this text you could either use a terminal program, which will read data from the serial port and show it in a window, or make your own program in e.g. Processing. Later in this article we propose a program that works for the software designed by Reas and Fry.

to:

The code example will capture the knock and if it is stronger than a certain threshold, it will send the string "Knock!" back to the computer over the serial port. In order to see this text you could either use the Arduino's serial monitor, or make your own program in e.g. Processing. Later in this article we propose a program that works for the software designed by Reas and Fry.

The code example will capture the knock and if it is stronger than a certain threshold, it will send the string "Knock!" back to the computer over the serial port. In order to see this text you could either use a terminal program, which will read data from the serial port and show it in a window, or make your own program in e.g. http://www.processing.org?. Later in this article we propose a program that works for the software designed by Reas and Fry.

to:

The code example will capture the knock and if it is stronger than a certain threshold, it will send the string "Knock!" back to the computer over the serial port. In order to see this text you could either use a terminal program, which will read data from the serial port and show it in a window, or make your own program in e.g. Processing. Later in this article we propose a program that works for the software designed by Reas and Fry.

Changed line 53 from:

Representing the Knock in Processing

to:

Representing the Knock in Processing

The code example will capture the knock and if it is stronger than a certain threshold, it will send the string "Knock!" back to the computer over the serial port. In order to see this text you could either use a terminal program, which will read data from the serial port and show it in a window, or make your own program in e.g. http://www.processing.org?. Later in this article we propose a program that works for the software designed by Reas and Fry.

Added lines 51-117:

=]

Representing the Knock in Processing

If, e.g. we would like to capture this "knock" from the Arduino board, we have to look into how the information is transferred from the board over the serial port.
First we see that whenever there is a knock bigger that the threshold, the program is printing (thus sending) "Knock!" over the serial port. Directly after sends the byte 10, what stands for EOLN or End Of LiNe, and byte 13, or CR - Carriage Return.
Those two symbols will be useful to determine when the message sent by the board is over. Once that happens, the processing program will toggle the background color of the screen and print out "Knock!" in the command line.

[=

// Knock In
// by David Cuartielles <http://www.0j0.org>
// based on Analog In by Josh Nimoy <http://itp.jtnimoy.com>

// Reads a value from the serial port and makes the background
// color toggle when there is a knock on a piezo used as a knock
// sensor.
// Running this example requires you have an Arduino board
// as peripheral hardware sending values and adding an EOLN + CR
// in the end. More information can be found on the Arduino
// pages: http://www.arduino.cc

Knock Sensor

Here we use a Piezo element to detect sound, what will allow us to use it as a knock sensor. We are taking advantage of the processors capability to read analog signals through its ADC - analog to digital converter. These converters read a voltage value and transform it into a value encoded digitally. In the case of the Arduino boards, we transform the voltage into a value in the range 0..1024. 0 represents 0volts, while 1024 represents 5volts at the input of one of the six analog pins.

A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. In our example we are plugging the Piezo on the analog input pin number 0, that supports the functionality of reading a value between 0 and 5volts, and not just a plain HIGH or LOW.

The other thing to remember is that Piezos have polarity, commercial devices are usually having a red and a black wires indicating how to plug it to the board. We connect the black one to ground and the red one to the input. We also have to connect a resistor in the range of the Megaohms in parallel to the Piezo element; in the example we have plugged it directly in the female connectors. Sometimes it is possible to acquire Piezo elements without a plastic housing, then they will just look like a metallic disc and are easier to use as input sensors.