Piezo Generator

I’ve been thinking of ways of creating interactivity with LEDs.

One of the issues you run into is controlling them. You can control a few with an Arduino easily but when you have a lot of them it starts getting messy pretty fast.

Something  just dawned on me.  I happen to have a piezoelectric disk so I put an LED against it and I was totally amazed that there was enough current to light the LED! So I soldered it and tried a few simple experiments.

So an LED can be activated mechanically. Further, this could prove to be a great way of harvesting small amounts of electricity from mechanical systems.

Piezoelectric sensors for sound, touch and vibration


I’m going to be using these as sensors on robots and other projects. I guess I need to figure out how to solder them as well as how to wire them up.

Piezoelectric sensors


I just picked up some of these. I think thy will make good sensors for pressure and stuff.

I can imagine they can be used to detect vibration, knocking, sound and such.

I was also thinking of using them at the corners of a touch area. Perhaps I could pick up the differential in pressure and guess the location of contact.

Here is my corner idea but used to follow hand claps.

/* 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 4 Sep 2010
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 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
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);
// send the string “Knock!” back to the computer, followed by newline
delay(100); // delay to avoid overloading the serial port buffer