Piezo sensor problem

Hi all, first post, bit of a noob so bear with me please!

At Halloween I built my first arduino project. A simple tilt switch that was connected to my door knocker. With an audio shield I had it playing a scream mp3, which worked well enough!

I wanted to extend this by using a piezo on the analogue input so a knock on the door would also trigger a sample. This worked fine on a breadboard with the sensor just a short distance away on my workbench - a sharp rap on the bench caused a trigger, but as soon as I extended the wiring the sensor seemed to trigger constantly. Is there something obvious I've overlooked here?

Post your code so we can see if it is in the SW.
I think you have quite a low threshold to react on the analog signal and if the wire is longer you will get more noise … (just an assumption)

Thanks, here’s the code:

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include “WaveUtil.h”
#include “WaveHC.h”
#include <LiquidCrystal.h>

// setup the lcd library with the numbers of the interface pins
LiquidCrystal lcd(6, 7, 8, 9, 16, 17);

//setup the tilt sensor on pin 14 (analogue 0)
#define LED 13
#define BUTTON 14
int valtilt=0;

//setup the piezo sensor on pin analogue 1
int knockSensor = 1;
byte valknock=0;
int statePin = LOW;
int THRESHOLD = 50;

SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card

uint8_t dirLevel; // indent level for file/dir names (for prettyprinting)
dir_t dirBuf; // buffer for directory reads

WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

// Function definitions (we define them here, but the code is below)
void lsR(FatReader &d);
void play(FatReader &dir);

void setup() {

// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

//set pins for sensor
pinMode (LED, OUTPUT);
pinMode (BUTTON, INPUT);

// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
lcd.print (“Ready”);

//////////////////////////////////// LOOP
void loop() {
if (valtilt==HIGH || valknock >=THRESHOLD){
digitalWrite(LED, HIGH);

lcd.setCursor (0,0);
lcd.print (“Doorbell sensor!”);
lcd.setCursor (0,1);
lcd.print (“scream.wav”);
else {
lcd.setCursor (0,0);
lcd.print (“Knock sensor!”);
lcd.setCursor (0,1);
lcd.print (“scream.wav”);
else {
digitalWrite (LED, LOW);

lcd.setCursor (0,0);
lcd.print (“Waiting…”);



Piezo sensor is very high impedance device, it's not clear if you have loaded it with 1 MoHm resistor. Anyway, the only way to reduce interference coming from long wires( acting like antenna) is reduce impedance, inserting amplifier right on the piezo, single transistor should be o'k. or you can use an electret mic, which already has transistor inside

Thanks magician, so will one of these be ok: http://uk.farnell.com/jsp/search/productdetail.jsp?SKU=1299885&ICID=baynote-1299885-pr

And (sorry to ask -never used one before) how do I connect it please?

Should be o'k. Look into datasheet, on a link you posted, diagram "E. MEASUREMENT CIRCUIT" shows connection with 2.2 kOHm resistor and cap. You don't need a cap, just connect resistor mic joint to analog input. I think internal amplifier 'd be sufficient for knock sensor.

Ok, something new to learn then! I'll get hold of one and report back. Thanks for advice, really appreciated.