Seeking Alternative to MEAS Piezo Vibration Sensor, Small Vertical & Circuit

Hi All,

I have connected a MEAS Piezo Vibration Sensor, Small Vertical (Piezo Vibration Sensor - Small Vertical - SEN-09199 - SparkFun Electronics) to an Arduino Duemilanova, using the default “Knock” circuit:

The circuit seems to work OK but there is a slight lag between generating the impulse to trigger the event, and display via the Serial Monitor.

Current circuit is:

// created 25 Mar 2007
// by David Cuartielles <>
// modified 30 Aug 2011
// by Tom Igoe

// 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
// Working const int threshold = 960;  // threshold value to decide when the detected sound is a knock or not
const int threshold = 949;  // 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);
    // delay(1000);
    // digitalWrite(ledPin, LOW);
    // send the string "Knock!" back to the computer, followed by newline
    Serial.println("Sheep count.");

    // turn LED off after time period; testing = 2000ms
    // delay(2000);
    // digitalWrite(ledPin, LOW);
  delay(100);  // original delay
  // delay(500);  // modified delay to avoid overloading the serial port buffer

The purpose for this sensor is to count sheep, by using a light-weight plastic arm that will hang down on a slight angle into the sheep race at about chest height. The sensor will be mounted at the top of the arm, on the pivot, sheep run through, hit the arm, arm triggers the event, sheep get counted. Testing on the desktop shows the Piezo Vibration sensor is not an exact device, it does not seem to work consistenly when struck.

So, is there an alternative that someone can think of, along with the commensurate circuit? Requirements would be low cost, with a duty cycle not exceeding 1000 events per 24 hour period, and able to export the information printed on the serial port to an incremental counter or a web service.

Thanks in advance for you help, QH.

When the arm is allowed to move a bit, you can connect an mircoswitch to it, that closes when a sheep pushes the arm aside.

Thanks for that, I'll look into it :)