Why I am getting a Wave like readings from Piezo Sensor using Knock Sketch

Components: Piezo Sensor
Sketch: Knock Sketch Example (Piezo connected on A0 and Ground with resistance to same pins) Threshold is 100. (code below is showing threshold as 20)
COM output: I get “Knock!” text displayed in a specific frequency, every 1 second. It does not change whether I send vibration to the Piezo or leave it untouched.

I tried reversing the polarity of Piezo, there is no change in the “Knock!” text display pattern.

I checked my table has no way of getting periodic Vibrations.

I donot understand what is causing this behaviour.

Any guidance to resolve this and make my Piezo behave as per the sketch is appreciated!!!

Thanks!

/* 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

   http://www.arduino.cc/en/Tutorial/Knock
   
   created 25 Mar 2007
   by David Cuartielles <http://www.0j0.org>
   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 knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 20;  // 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);    
  // Serial.print("Sensor Reading:"); Serial.println(sensorReading);
  
  // 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
    Serial.print("Knock:");Serial.println(sensorReading);         
  }
  delay(100);  // delay to avoid overloading the serial port buffer
}

What sketch?

http://forum.arduino.cc//index.php?topic=97455.0

Added code I uploaded to my Arduino, above.

const int knockSensor = A0; // the piezo is connected to analog pin 0

The analog pin number is 0. The analog pin can be used as a digital pin. The number of the pin, then, depends on which board you have. To make it easier to port code, the Arduino team defined a bunch of aliases, A0, A1, etc. that have values that depend on the board type.

Since you are not using the analog pin as a digital pin, you should not be using the digital pin name.

  delay(100);  // delay to avoid overloading the serial port buffer

Printing data to the serial port not more than once every 1/10th of a second is not a bad idea. Doing nothing else during the time you don't want to be printing to the serial port is not. Look at the blink without delay example. Think in terms of "print to the serial port without delay".

If you are getting readings from the analog pin when the piezo is not being touched, you have a hardware problem.

Which piezo sensor do you have? How is it wired?

PaulS:

const int knockSensor = A0; // the piezo is connected to analog pin 0

The analog pin number is 0. The analog pin can be used as a digital pin. The number of the pin, then, depends on which board you have. To make it easier to port code, the Arduino team defined a bunch of aliases, A0, A1, etc. that have values that depend on the board type.

Since you are not using the analog pin as a digital pin, you should not be using the digital pin name.

He IS using the analog pin name, defined in the header file. A0 is the pin name, not its number. You use A0 through A5 if you want to use analog or digital.

Pin 0 is a digital pin, which happens to be the Serial Rx pin.

He IS using the analog pin name

A0 is an alias for a value. The value on a 328 based Arduino is 14.

A0 is the pin name, not its number.

Wrong.

Pin 0 is a digital pin, which happens to be the Serial Rx pin.

There is also an analog pin 0.