Increasing the sensitivity of a Piezo sensor

For a current project, I am using a piezo pickup to detect vibrations emitted from a piano string after a key has been struck.

The piezo is connected to an analogue input on my Arudino Uno, with a 1.2MOhm resistor also implemented into the circuit.

My problem: The piezo pickup responds only to firm taps and not much else.

My question: Would decreasing the resistance add more sensitivity and would it be safe to do this?

Thanks for taking the time to read this :slight_smile:

1.Make sure that you are you are using a good quality servo
2.The centre of the piezo cell is the most sensitive part

A simple one transistor amplifier would give you lots of gain - see attached

regards

Allan

simple amp.pdf (17.4 KB)

Had a quick read (maybe not enough) through the other thread on the same subject.

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

val = analogRead(knockSensor);
if (val <= THRESHOLD) {......

It seems you assume a piezo element generates a positive DC voltage.
That statement might only work for only one half of one sinewave of the string's base frequency.
Maybe you should read the sensor constantly until the peak A/D values have decreased below the threshold.
I like to see how you have attached that (unknown) piezo.
Leo..

The circuit I use for piezo elements is use a 47k/47k voltage divider to one terminal of the sensor,
then the other terminal to the Arduino pin.

The signal is centred at 2.5V and the high impedance of the divider limits the current that can flow. You
can then see the whole waveform as its offset to mid-rail.

You can add a resistance in parallel with the piezo element to decrease the sensitivity and
to stop it drifting at DC.

Wawa:
Had a quick read (maybe not enough) through the other thread on the same subject.

Breaking void loop into 3 separate sections... - Programming Questions - Arduino Forum

val = analogRead(knockSensor);
if (val <= THRESHOLD) {......

It seems you assume a piezo element generates a positive DC voltage.
That statement might only work for only one half of one sinewave of the string's base frequency.
Maybe you should read the sensor constantly until the peak A/D values have decreased below the threshold.
I like to see how you have attached that (unknown) piezo.
Leo..

Thanks for all the comments guys. I really appreciate this advice :slight_smile:

I have since changed:

val = analogRead(knockSensor);
if (val <= THRESHOLD) {......

to

val = analogRead(knockSensor);

while (val > THRESHOLD) {

val = analogRead(knockSensor);
}

Or better yet

while(analogRead (knockSensor) > THRESHOLDS) {}

Avocado232:
val = analogRead(knockSensor);

while (val > THRESHOLD)

  1. Could be anything. If the A/D samples during the negative part of the knock/wave, val will be 0.

  2. This won't run then.
    Leo..

Something to try.
This example repeatedly reads the piezo 100x and stores the highest peak into "finalValue".
"finalValue" is always available for the rest of the code.
See code if too sensitive.
During testing it could detect a pin dropping on a desk 50cm away from the piezo.
Leo..

const byte piezoPin = A0;
int rawValue; // raw A/D readings
int piezoValue; // peak value
int finalValue; // smoothed final value

void setup() {
  analogReference(INTERNAL); // remove this line if too sensitive
  Serial.begin(9600);
}

void loop() {
  piezo();
  //other code
}

void piezo() {
  for (int x = 0; x < 100; x++) {
    rawValue = analogRead(piezoPin); // 100 A/D readings
    if (rawValue > piezoValue) {
      piezoValue = rawValue; // store peaks
    }
  }
  if (finalValue < piezoValue) { // fast attack
    finalValue = piezoValue;
  }
  else {
    finalValue = (finalValue + piezoValue) / 2; // smooth decay
  }
  piezoValue = 0; // reset
  if (finalValue > 0) {
    Serial.println(finalValue); // print only if > 0
  }
}

Wawa:
Something to try.
This example repeatedly reads the piezo 100x and stores the highest peak into "finalValue".
"finalValue" is always available for the rest of the code.
See code if too sensitive.
During testing it could detect a pin dropping on a desk 50cm away from the piezo.
Leo..

const byte piezoPin = A0;

int rawValue; // raw A/D readings
int piezoValue; // peak value
int finalValue; // smoothed final value

void setup() {
 analogReference(INTERNAL); // remove this line if too sensitive
 Serial.begin(9600);
}

void loop() {
 piezo();
 //other code
}

void piezo() {
 for (int x = 0; x < 100; x++) {
   rawValue = analogRead(piezoPin); // 100 A/D readings
   if (rawValue > piezoValue) {
     piezoValue = rawValue; // store peaks
   }
 }
 if (finalValue < piezoValue) { // fast attack
   finalValue = piezoValue;
 }
 else {
   finalValue = (finalValue + piezoValue) / 2; // smooth decay
 }
 piezoValue = 0; // reset
 if (finalValue > 0) {
   Serial.println(finalValue); // print only if > 0
 }
}

Thanks for taking the time to suggest this! I am currently trying to work this into my current code using trial and error. Any pointers would be much appreciated!:

#include <Servo.h> 

Servo myservo;

int knockSensor = 0;               

byte val = 0;

int THRESHOLD = 0;

int buttonPin = 2;

int count = 1;


void setup() {

  myservo.attach(9);
  myservo.write(90);
  pinMode(buttonPin, INPUT_PULLUP);

}


void loop() {

  if (digitalRead(buttonPin) == LOW) {

val = analogRead(knockSensor);     

 while (val > THRESHOLD) {  

    val = analogRead(knockSensor); 
    
    }

    if (count == 1) {

    delay(1000); 
  
    myservo.write(85);
    delay (175);

    myservo.write(95);
    delay (260);

    myservo.write(90);
    delay (1000);

    count ++;

          }

val = analogRead(knockSensor);     

 while (val > THRESHOLD) {  

    val = analogRead(knockSensor); 
    
    }

   if (count ==2) {

    delay(1000); 
  
    myservo.write(80);
    delay (140);

    myservo.write(100);
    delay (140);

    myservo.write(90);
    delay (1000); 

      count ++;
      
          }

val = analogRead(knockSensor);     

 while (val > THRESHOLD) {  

    val = analogRead(knockSensor); 
    }

    if (count ==3) {

    delay(1000); 
  
    myservo.write(30);
    delay (120);

    myservo.write(130);
    delay (120);

    myservo.write(90);
    delay (1000); 

    count ++;

    }

    delay (1000); 

        if(count > 3) count = 1;

    }

}

First step would be to try the code with the piezo setup you have.
See if it works, before you combine.
A picture of the setup (post#3) would be nice.
Leo..

Wawa:
First step would be to try the code with the piezo setup you have.
See if it works, before you combine.
A picture of the setup (post#3) would be nice.
Leo..

I will post a picture as soon as I get the chance and will inform you if the code worked with my current setup.

Hi,
Wouldn't a guitar pickup be better?

Tom... :slight_smile:

Schematic? How are you protecting the Arduino input? A piezo puts out positive and negative voltage, and with a sharp rap it can be quite large.

polymorph:
Schematic? How are you protecting the Arduino input? A piezo puts out positive and negative voltage, and with a sharp rap it can be quite large.

I don't think common 1" piezo disks can produce enough current to damage a pin.
The internal clamping diodes will limit the voltage to VCC +0.5volt and GND -0.5volt.
Leo..

I think this is roughly what you want.
Untested. May need polishing.
Leo..

#include <Servo.h>
Servo myservo;

const byte buttonPin = 2;
const byte piezoPin = A0;
int rawValue; // raw A/D readings
int peakValue; // peak value
int finalValue; // smoothed final value


void setup() {
  myservo.attach(9);
  myservo.write(90);
  pinMode(buttonPin, INPUT_PULLUP);
  analogReference(INTERNAL); // remove this line if piezo is too sensitive
  Serial.begin(9600);
  while (digitalRead(buttonPin) == HIGH) {
  // wait here for start button
  }
}


void loop() {
  delay(1000);
  myservo.write(85);
  delay (175);
  myservo.write(95);
  delay (260);
  myservo.write(90);
  // wait for the sound to die
  do {
    for (int x = 0; x < 100; x++) { // 100 A/D readings
      rawValue = analogRead(piezoPin);
      if (rawValue > peakValue) {
        peakValue = rawValue; // store peaks
      }
    }
    if (finalValue < peakValue) { // fast attack
      finalValue = peakValue;
    }
    else {
      finalValue = (finalValue + peakValue) / 2; // smooth decay
    }
    Serial.print("Strike one ");
    Serial.println(finalValue);
    peakValue = 0; // reset
  } while (finalValue > 0);

  delay(1000);
  myservo.write(80);
  delay (140);
  myservo.write(100);
  delay (140);
  myservo.write(90);
  do {
    for (int x = 0; x < 100; x++) {
      rawValue = analogRead(piezoPin);
      if (rawValue > peakValue) {
        peakValue = rawValue;
      }
    }
    if (finalValue < peakValue) {
      finalValue = peakValue;
    }
    else {
      finalValue = (finalValue + peakValue) / 2;
    }
    Serial.print("Strike two ");
    Serial.println(finalValue);
    peakValue = 0;
  } while (finalValue > 0);

  delay(1000);
  myservo.write(30);
  delay (120);
  myservo.write(130);
  delay (120);
  myservo.write(90);
  do {
    for (int x = 0; x < 100; x++) {
      rawValue = analogRead(piezoPin);
      if (rawValue > peakValue) {
        peakValue = rawValue;
      }
    }
    if (finalValue < peakValue) {
      finalValue = peakValue;
    }
    else {
      finalValue = (finalValue + peakValue) / 2;
    }
    Serial.print("Strike three ");
    Serial.println(finalValue);
    peakValue = 0;
  } while (finalValue > 0);
}

It is not just current that damages a pin, excess voltage will do it as well despite internal diodes only meant for static protection.

Well, I don't see the difference between a voltage spike from a piezo and a static discharge.

I have just tested a common bare 1" piezo with 1Megohm load resistor on a scope (1Megohm probe).
The piezo was put on the desk with some (soft) weight on it.
Knocking on the desk next to the piezo produced only a few volts.
I could only get more than 5volt by tapping directly onto the brass of the disk.
Current was measured by shorting the piezo with a 1k resistor.
I could only get it slightly over 1mA by hitting the brass directly with a hard object, like a screwdriver.

I don't want this to end in another pin protection argument like we did before.
Use external clamping diodes if you want.
In this case I don't see the need for it.
Leo..

Try the sensor without any load resistor. A direct tap can generate over 300V.

The load resistor is an essential part of the circuit, so why test without it.
Leo..