Build external comparator for piezo vibration sensor to measure frequency

Good day, Masters! I really need your help on this one as the circuit will be due this week :sweat_smile: :roll_eyes: =(

I'm using Arduino UNO and MEAS Piezo Vibration Sensor from SparkFun

I have been searching the web on how to measure frequency using a piezo vibration sensor and nothing worked because they said it is only good as a detector and it is not meant to measure frequency. But Sir Magician helped me find a code and it works perfectly :slight_smile: the frequency increases the harder you blow on the sensor, just what I needed. Thank you again Sir!

The problem now is, it uses 3 digital pins; uses arduino's internal analog comparator(for Pin 6 and 7) and alternate port function T1 (for Pin 5) which is the input 16 Bit Hardware Counter1

I read about Analog Comparator here ->

"The Analog Comparator is an internal module of the microcontroller and it compares the input values on the positive pin (Digital Pin 6) and negative pin (Digital Pin 7). When the voltage on the positive pin is higher than the voltage on the negative pin AIN1, the Analog Comparator outputs a 1 in the ACO bit of the ACSR register."

and function T1 here ->

"The Frequency input is fixed to digital pin 5. This pin is mapped to the alternate port function T1 which is the input 16 Bit Hardware Counter1. To obtain a higher resolution than 16 Bit, the counter overflows are counted also and are calculated with the counter value to the final long integer result."

This means, I can only read one vibration sensor per Arduino. And I need to read at least three.

I need your advice on what components to use on this project.

Here's the site Sir Magician gave me :smiley:

<Click here for larger image>

/* Frequency & Period Measurement for Audio
 * connect pin 5,6,7 to input circuit
 * KHM 2010 /  Martin Nawrath
 * Kunsthochschule fuer Medien Koeln
 * Academy of Media Arts Cologne

#include "FreqPeriod.h"

double lfrq;
long int pp;

void setup() {
  Serial.println("FreqPeriod Library Test");

void loop() {

  if (pp ){

    Serial.print("period: ");
    Serial.print(" 1/16us  /  frequency: ");

    lfrq= 16000400.0 / pp;
    Serial.print(" Hz");

    Serial.println("  ");


void printDouble( double val, byte precision){
  // prints val with number of decimal places determine by precision
  // precision is a number from 0 to 6 indicating the desired decimial places
  // example: lcdPrintDouble( 3.1415, 2); // prints 3.14 (two decimal places)

  if(val < 0.0){
    val = -val;

  Serial.print (int(val));  //prints the int part
  if( precision > 0) {
    Serial.print("."); // print the decimal point
    unsigned long frac;
    unsigned long mult = 1;
    byte padding = precision -1;
      mult *=10;

    if(val >= 0)
      frac = (val - int(val)) * mult;
      frac = (int(val)- val ) * mult;
    unsigned long frac1 = frac;
    while( frac1 /= 10 )
    while(  padding--)
    Serial.print(frac,DEC) ;

That is a smart circuit.
On the Arduino Uno, a 'double' is actually a 'float'. The printDouble() function has no use.

The Arduino Pro Mini clone costs about 2.24 dollars on Ebay. You can use 3 of those for 3 sensors. They need an extra usb-to-ttl-serial converter.

That is a smart circuit.

Meaning... I can't replicate the circuit? :frowning:

I was only expressing my appreciation for that circuit.

Oh, sorry.

But, Sir, do you think it's possible?

If I use a comparator IC and use BlinkWithoutDelay instead of attachInterrupt(), what else should I need?

Can I use LM339 as an Analog Comparator?

I didn't answer your previous post, because I looked for the frequency library and I can't find if it allows more than one pin to measure the frequency. So I'm very sorry, but I don't know.
A comparator (not an OpAmp) that works with 5V is okay. You can use the LM339. But it is the frequency library that is the problem.

Ok, Thank you sir!

If the code will not work for 3 sensors, could anyone suggest a link for a frequency counter?

Please? =(

Anybody? =(

Can you show me how you got the frequency from a piezoeletric sensor?

I read all links you posted, but I dont know how to integrate my piezo with the frequency-measurement-library

Thank you sir