i laboriously (as i was not much into electronics at first) built a preamp to get a nice sensitivity and velocity response to knocks using piezos
i m really not sure about the english words but it amplify, then redress (positivise?) and then smooth the electric signal so it can be nicely received by the arduino
here is the scheme :
you need to adapt resistors 1 and 2 depending on the desired sensitivity
here is an arduino shield for 2 piezos (piezi ?)
beware cause it's reverse mounted : with components underneath the board (so i gain space) near the arduino components
this is the component face :
code should looks like this
this is not the code i use but a simpler one, working for one captor
const int piezo_0 = 0; // analog input 0
const int trigger_threshold_0 = 2; // difference with last value so it start to trig
const int delay_0 = 30; // pause to avoid multitriggers for one knock during 30ms
unsigned long now = 0;
unsigned long pause_0 = 0;
int triggerValue_0 = 0;
int previousValue_0 = 0;
int peakValue_0 = 0;
int maxValue_0 = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
now = millis();
if (pause_0 < now - delay_0){ // pause off
triggerValue_0 = analogRead(piezo_0);
if (triggerValue_0 >= previousValue_0 + trigger_threshold_0) {
delayMicroseconds(230); // wait 0.23 ms for peak
peakValue_0 = analogRead(piezo_0);
if (peakValue_0 > triggerValue_0){ // be sure peak value is higher
maxValue_0 = peakValue_0;
}
else {
maxValue_0 = triggerValue_0;
}
Serial.print("/piezo_0 ");
Serial.println(maxValue_0); // send osc message
previousValue_0 = maxValue_0;
pause_0 = millis();
}
else {
previousValue_0 = triggerValue_0;
}
}
}
You probably don't need to amplify it - just don't load it with that 10k resistor (R1) - that's reducing the sensitivity a lot. Piezos are very high impedance output so placing a "low" resistance of 10k across it will attenuate its output. Try 1M instead.
If I connect a piezzo directly to Arduino A0, (sorry no input protection at all, just for a short experiment), gently press a bit on the piezzo and let my homemade software breadboard display analog reads on A0 I see:
This means you easily go over 5 Volts and below zero (when you release the piezzo).
Maybe a 5.1V zener diode parallel the input would be good if you want to knock on a piezzo
OutOfLine:
This means you easily go over 5 Volts and below zero (when you release the piezzo).
Maybe a 5.1V zener diode parallel the input would be good if you want to knock on a piezzo
Important : I'm not having piezzo, I'm using Geophone.
Now as you have written and showed that it easily goes above 5 volts then please tell me one thing
why it didn't harm ADC of your Arduino as recommended should be max 5 volts.
patilchetan:
Now as you have written and showed that it easily goes above 5 volts then please tell me one thing
why it didn't harm ADC of your Arduino as recommended should be max 5 volts.
The Arduino has input diodes that protect the inputs from more than +5v and less than 0v, provided the current flowing into the diode is low enough. The current provided by a piezo knock sensor is tiny, unless you hit it with a hammer.
dc42:
The Arduino has input diodes that protect the inputs from more than +5v and less than 0v, provided the current flowing into the diode is low enough. The current provided by a piezo knock sensor is tiny, unless you hit it with a hammer.
Yes, probably I was over cautious suggesting a zener to protect the input, or maybe not?
Edit:
I could not reproduce my multimeter current readings, so I assume stupid user error.
I short circuit a piezzo disk by a cheap multimeter in the 200mA range to get some readings
[ meaningless multimeter readings deleted ]
If you're sure that you're reading mA not uA, then 20mA is certainly more than you should subject the Arduino input protection diodes to, and you should use external Schottky protection diodes.