3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Low Cost Water Flow Sensor and Ambient Display

Step 4Calibrate your Sensor to Detect Vibrations

Calibrate your Sensor to Detect Vibrations
When the tap is turned on, the vibrations of the pipe will cause the piezo to generate a fluctuating current. Since the base reading tapers off around 520, you can compute an amplitude around this number to detect vibrations. My threshhold is set at 130, but you may increase or decrease this depending on the types of vibration you want to sense and sensitivity of your particular piezo piece.

To test the signal, use mastic to attach piezo to a flat surface. Try tapping or scratching on the surface at different locations and different intensities see what type of readings you get on the Arduino.

To reduce noise, I recommend computing a moving average of the input. This is a crude way of determining wave amplitude that avoids false positives due to random static current. More advanced methods such as FFT may also be used.

// Sample Code
int sensor = 2; // Analog in
int val =0; // Current reading for analog pin
int avg; // Running average of the wave amplitude
int MIDPOINT = 520; // Base reading

void setup() {
Serial.begin(9600);
avg = MIDPOINT; // set average at midpoint
}

void loop() {
val = analogRead(sensor);

// Compute wave amplittue
if (val > MIDPOINT) {
val = val - MIDPOINT;
} else {
val = MIDPOINT - val;
}

// compute running average fr the amplitute
avg = (avg * 0.5) + (val * 0.5);

if (avg > 130) {
// vibration detected!
Serial.println("TAP");
delay(100); // delay to ensure Serial port is not overloaded
}
}

« Previous StepDownload PDFView All StepsNext Step »
1 comment
Dec 12, 2009. 7:50 PMbaezl says:
 Hey I really liked your project so I wanted to try my own. I think I have all my parts write but its not working. Can you help me out? 

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
49
Followers
4
Author:staceyk