knock sensor problem

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 get a value fluctuating between 322 and 327 even if the piezo is not being 'knocked'.

That sounds fine.
The load resistor of 1M is too high to reduce all the interference getting into the pin, so there will be some background variations.

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

piezo-arduino.jpg

Grumpy_Mike:

I get a value fluctuating between 322 and 327 even if the piezo is not being 'knocked'.

That sounds fine.
The load resistor of 1M is too high to reduce all the interference getting into the pin, so there will be some background variations.

I would expect the analog reading to be zero if the piezo is not being touched and there is a 1 meg to ground, yes?

Or is he seeing leakage from the A/D converter circuitry that a 1 meg can't swamp out?

would expect the analog reading to be zero if the piezo is not being touched and there is a 1 meg to ground, yes?

No.

Or is he seeing leakage from the A/D converter circuitry that a 1 meg can't swamp out?

It is not leakage it is pick up interference. In effect this input is floating.

Bias the analog input about 1/2 and 1/2 with a pair of large value (like 1 megohm) resistors.

The circuit design as it is is poor but works. The negative spikes are absorbed by the static protection diodes on the input circuitry and there is so little power in the output of the sensor that no harm is done.

POSSIBLY average a few analog readings to clean up the signal.

At a 100uS sample rate there are not many chances to catch a pulse.

Thanks all. I am getting a reading on A0 but it has very small and almost random variation (320-330) which is not related to whether the piezo is 'knocked' or not. I tried reducing the 1M resistor in half which shifted the reading up but still no variation with knock.

Having seen the circuit on the Arduino site, I assumed it is 'officially' approved and therefore I followed it without questioning. From what you guys are saying, it is a poor design and that it doesn't work as is.

I will try what Krupski suggested but I really don't want to tie up 2 analog pins.

Thanks.

Al

alnajjar:
I will try what Krupski suggested but I really don't want to tie up 2 analog pins.

Well what would work even better is an op-amp. Connect the piezo between the inverting and non-inverting inputs and setup the gain to give you a nice strong (volts range) signal from the piezo when a knock is detected.

I would suggest using an op-amp that is designed for single supply use, then run it from the 5 volt rail of the Arduino and bias the non-inverting pin at 1/2-1/2.

Pros:
(1) Single supply op-amp does not need a biploar supply.
(2) Protection - the op-amp output cannot swing below zero nor above 5 volts, thereby protecting the analog input pin
(3) Better signal - the differential connection of the piezo will give you the common mode noise rejection you need, and the gain will give the Arduino a nice, reliable signal. You can even add a few capacitors and resistors to make a high-pass or band-pass filter to further clean up the piezo signal.
(4) You will then only need one analog input on the Arduino.

Cons:
(1) More parts
(2) More cost

Lastly, you may want to add a snubber (two 1N914 or 1N4148 diodes in parallel, opposite directions) to clamp the piezo output to approximately +/- 0.7 volts. A piezo can produce very high voltages if given a step input (that's how gas grill igniters work!). An accidental tap or touch on the piezo could burn out the op-amp without the diodes.

|--->|---|
|---|<---|

Above is what I mean... back to back diodes.

Hope this helps.

Having seen the circuit on the Arduino site, I assumed it is 'officially' approved and therefore I followed it without questioning.

It does work but it is a poor design. Many people have got it to work.

Are you sure you have a 1M resistor and that it is wired correctly. In particularly the ground of the arduino is connected. If you are using a solderless bread board then some have a break in the power and ground lines indicated by a break in the paint lines.
From what you say it looks like you have not got it connected correctly.
How about positing a picture not more than 1000 pixels square of your setup so we can check.

Grumpy_Mike:

would expect the analog reading to be zero if the piezo is not being touched and there is a 1 meg to ground, yes?

No.

Or is he seeing leakage from the A/D converter circuitry that a 1 meg can't swamp out?

It is not leakage it is pick up interference. In effect this input is floating.

The 328p data sheet (Rev. 8271H – 08/2013, page 301) states that the leakage current of any I/O pin is 1 microampere (max) for both low and high level.

So, a 1uA current through a 1 meg resistor is 1 volt. With an A/D output range of 0 to 1023, 1 volt would show as a reading of around 205 (decimal). The OP was getting a reading of 322...327 which makes me suspect that he WAS seeing leakage.

Also, the datasheet says that something driving the A/D input should have an output impedance of 10K ohms or less, to swamp out the internal capacitance and leakage current of the input.

Lastly, how can you say that a pin connected to VCC or GND through a 1 meg resistor is "in effect, floating"? Floating means there is nothing defining it's state (i.e. a resistor or an active driver) or in other words an OPEN, UNCONNECTED input.

1 meg is less than ideal for most digital uses (bias for a cmos inverter crystal oscillator circuit being one exception) but it certainly doesn't result in a "floating" input.

I agree with you though....... that piezo circuit as posted is a LOUSY design.

Thanks again Mike and Krupski.

Mike you are absolutely correct. 7 rows of the bread board that came with the protoshield v5 is do not connect. there must be something that prevented the jumpers from making connection. Sorry about that I should have checked the breadboard which you don't typically have to do that.

It is a lousy circuit and unreliable. So, for my project, I will use an FSR pressure sensor instead which works perfectly for my application.

I build exhibits for a children's museum and this exhibit has 8 pads (1/2" translucent plexi)that light up and play a sound when little kids jump on them - in case you want to know what the project is about.

Many thanks again for you ideas and insight.

Al

Glad you got it working.

So, a 1uA current through a 1 meg resistor is 1 volt.

Where do you get 1uA from?

You seem to be hung up on leakage what is leaking? Capacitors leak when they self discharge, this is not the case here as he was seeing a reading, capacitor leakage would reduce that reading.

Also, the datasheet says that something driving the A/D input should have an output impedance of 10K ohms or less, to swamp out the internal capacitance and leakage current of the inp

Yes it says 10K but again leakage does not enter into it. The 10K is so that the input capacitor is sufficiently charged in the time between switching to that input and when the conversion starts. Hence the regular advice to take two readings one after the other and use the second when you have a high input impedance.

how can you say that a pin connected to VCC or GND through a 1 meg resistor is "in effect, floating"? Floating means there is nothing defining it's state (i.e. a resistor or an active driver) or in other words an OPEN, UNCONNECTED input.

There is a continuum between floating and being pulled to a logic state. The lower the resistance the more the interference has to be to generate a certain noise voltage. This is known as noise immunity.
Now you would accept that 1K is pulling it down quite hard, and nothing is floating. What about 10M? In the grand sachem of things this is likely to have very little effect on a signal, just try touching an oscilloscope probe and see the signal you get. Put a 1M resistor across the same scope probe and try again. Yes the signal is not as great but you will see it is still big enough to cause interference. Notice I said "in effect", a 1M resistor does very little in the noise immunity stakes.