Leftovers” is a project I started last semester in Sabine Seymour’s Fashionable Technology.

“Ruby Heels” was my second assignment in Physical Computing 1. Using a sensor/component to create sound. I really enjoyed working with the piezo contact speaker and want to experiment with it more.

For my midterm project I chose to experiment with nitinol wire, piezo contact sensor and LEDs.

//Veronica Black
//Pcomp 1 Midterm Oct.25, 2013

/* 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 writes
“knock” to the serial port, and toggles the LED on pin 13.

The circuit:
* + connection of the piezo attached to analog in 0
* – connection of the piezo attached to ground
* 1-megohm resistor attached from analog in 0 to ground


created 25 Mar 2007
by David Cuartielles
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.


// these constants won’t change:
const int ledPin = 13; // led connected to digital pin 13
const int nit = 8;
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not

// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(nit, OUTPUT);
Serial.begin(9600); // use the serial port

void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);

// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
digitalWrite(nit, ledState);
// send the string “Knock!” back to the computer, followed by newline
delay(100); // delay to avoid overloading the serial port buffer

Leave a Reply