Pages: [1]   Go Down
Author Topic: piezo as knock sensor : building preamp  (Read 3143 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

following these conversations
http://arduino.cc/forum/index.php/topic,26791.msg199278.html
(and in french) http://arduino.cc/forum/index.php/topic,33598.msg245621.html

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
Code:
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;
    }
  }
}
« Last Edit: February 05, 2011, 03:05:32 am by kro » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Is the circuit working properly ?
What was your input voltage before amplification?

I'm having a sensor which gives output in mV and now I'm
trying to increase it to V using a amplifier.

Will it be advisable if I try your circuit?
Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12200
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@MarkT :

I'm having different sensor : Geophone which is giving output in 10mV (minimum) and
1 Volt (maximum) on DSO with healthy noise.

So I'm trying if this circuit works for me or else I need to make it on own which I'm not
aware much in details.

What would you suggest?
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
Follow pin 0 tolerance 1
values +/- set tolerance (any other byte to stop)

120 ********
122 ********
124 ********
126 ********
131 *********
138 *********
147 **********
161 ***********
178 ************
202 *************
231 ***************
264 *****************
296 *******************
322 *********************
355 ***********************
424 ***************************
561 ************************************
596 **************************************
678 *******************************************
814 ***************************************************
972 *************************************************************
1023 ****************************************************************|
1021 ****************************************************************
997 ***************************************************************
833 *****************************************************
615 ***************************************
422 ***************************
255 ****************
127 ********
39 ***
0 0

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 smiley-wink
« Last Edit: January 30, 2012, 09:55:47 pm by OutOfLine » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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 smiley-wink


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.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Jr. Member
**
Karma: 1
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ]
« Last Edit: February 02, 2012, 08:02:07 am by OutOfLine » Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Jr. Member
**
Karma: 1
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I could not reproduce my first findings. Checking again gave readings that look save for arduino inputs.

If you're sure that you're reading mA not uA

so I assume I was not,
how embarrassing smiley-wink

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,

thanks for great information.
I have a question - what should I change in preamp circuit if I'm going to conect it to 3.3v arduino?
Logged

Pages: [1]   Go Up
Jump to: