alnajjar:
Hello,
I am experimenting with this project and followed exact instruction and code from the site (http://arduino.cc/en/tutorial/knock). I am using a Radio Shack 12V piezo (273-065). However, when printing to serial port, I get a value fluctuating between 322 and 327 even if the piezo is not being 'knocked'.
I tripled checked the circuit which is a trivial one (I have piezo +ve to A0, -ve to ground and a 1M resistor in parallel with the piezo), leaving me puzzled as to why I am not getting this.
Should I have a different piezo?
Thanks for your help in advance.
Al
I've never tried that circuit or code, but if I were going to do it, I would do a few things:
(1) Bias the analog input about 1/2 and 1/2 with a pair of large value (like 1 megohm) resistors. The piezo can output a negative or positive charge depending on which direction it's deflected.
(2) POSSIBLY average a few analog readings to clean up the signal. You would have to play with the averaging amount, because averaging is equivalent to a low pass filter. A door knock is likely to be more of an impulse (high frequency) signal, so too much averaging would "low pass" it away.
(3) Use a twisted pair of wires between the Arduino and the piezo.
Also, connect it in a differential manner (that is, between two analog inputs, not one input and ground). Then look for the DIFFERENCE between the two analog readings.
Note that any common mode noise (like 60 hz noise) will be ignored because it will cause the same signal on both inputs, the difference being, of course, zero.
So a differential input will ignore noise and only read the piezo.
Hope this helps.
(edit to add): Added diagram for differential mode
