Knock detector using microphone problem

Hi, I wanna make a knock detector using a microphone with an op-amp circuit (from the google)(lm358)
And a simple code that act whenever the analog read of the pin is greater then value or lower then it, witch totally works on <50 delay but when I use 100 delay it doesn't work anymore.

My question is how I can improve the circuit to make the signal longer (like the pir module)?

Circuit:

I also have tl062cp witch works with this circuit too
But I don't know if is better to use it

..make the amp output trig an interrupt. Then your code can do other tasks while waiting for the knock..

knut_ny:
..make the amp output trig an interrupt. Then your code can do other tasks while waiting for the knock..

Seems complicated
Give me an example

Why make a knock detector with a microphone.
A knock detector (direct surface contact) with a 1" piezo disk will likely work much better.
Can post a sketch that is more reliable and more sensitive than the commonly used KnockSensor sketch.

The diagram posted is a sound detector.
Supply the LM358 from Arduino's 5volt pin. Use the "dotted line" output, not the cap output.
Read continuously with an analogue input, and subtract the ~512 offset from your readings.
A threshold could be set with an "if" statement.
Post the code you have so far.
Leo..

Hi,
I think we need to see your code, why do you need a delay?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

OPs circuit;

Tom.. :slight_smile:

TomGeorge:
Hi,
I think we need to see your code, why do you need a delay?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

OPs circuit;

Tom.. :slight_smile:

The code doesn't matter is just a sketch so far, in the future i will use a better version into my big project, witch must have that 100 ms delay

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  if ((analogRead(A4) < 565 ) or (analogRead(A4) > 590)) {
    Serial.println(analogRead(A4));
  }
  delay(100);
}

this code works perfectly with the delay of 1-40 but not with 100, it can't catch all the knocks

Wawa:
A knock detector (direct surface contact) with a 1" piezo disk will likely work much better.

i also have a PIEZO TRANSDUCER but it's the same story, on 100 delay, sometimes it can't catch them all

Hi,
delay of 100mS, STOPS the code for 100mS, nothing happens, not even an AtoD conversion.
You need to look at an Example called "Blink without Delay' to se how to do timing without the delay command.

Tom... :slight_smile:

TomGeorge:
Hi,
delay of 100mS, STOPS the code for 100mS, nothing happens, not even an AtoD conversion.
You need to look at an Example called "Blink without Delay' to se how to do timing without the delay command.

Tom... :slight_smile:

So, the answer to my question is that
there is no way i can improve the circuit so the signal can become longer, maybe to become 100 ms instead of just 3 ms

The thing with the code is that in the loop is has so many task and each task cost the arduino some time to complete it so the delay get longer so the knock is not detected anymore

Hi,
You could get the output of your circuit to trigger a monostable.

This would give a constant width pulse out no matter how short the input pulse.
The sensitivity would have to be set in your amplifier as the output would be a 5V pulse each time a knock was detected.

Look up , pulse extenders also monostable timer

Tom.. :slight_smile:

TomGeorge:
Hi,
You could get the output of your circuit to trigger a monostable.

This would give a constant width pulse out no matter how short the input pulse.
The sensitivity would have to be set in your amplifier as the output would be a 5V pulse each time a knock was detected.

Look up , pulse extenders also monostable timer

Tom.. :slight_smile:

I used Tl062cp as the omp amp with the circuit i linked in the first post
555 timer with a 330uF cap and a variable res
and i use an object to keep the microphone on the table so it will be more sensible

So far, is that good ?

330u seems a lot - with 1k resistor it would give ~ 300ms... whats the variable resistor value?

regards
Allan

I wrote this sketch for another project. Very sensitive if you position the piezo in right place.
Use the piezo and resistor mentioned at the start of the sketch.
It has an alarm with threshold. Remove if you like.
Leo..

// knock sensor/alarm
// Piezo, with 1Megohm load resistor across, connected to A0 and ground
// optional 5volt buzzer on pin 13

int threshold = 100; // alarm threshold from 1 (very sensitive) to 1022 <<<<<<<<
int alarmDuration = 100; // alarm duration in milliseconds <<<<<<<<

const byte piezoPin = A0;
int rawValue; // raw A/D readings
int piezoValue; // peak value
const byte onboardLED = 13; // onboard LED and/or buzzer

void setup() {
  analogReference(INTERNAL); // remove this line if too sensitive
  Serial.begin(115200); // serial monitor for raw piezo output
  pinMode (onboardLED, OUTPUT);
}

void loop() {
  // reset
  piezoValue = 0;
  // read
  for (int x = 0; x < 250; x++) { // multiple A/D readings
    rawValue = analogRead(piezoPin);
    if (rawValue > piezoValue) {
      piezoValue = rawValue; // store peaks
    }
  }
  // print
  if (piezoValue > 0) {
    Serial.print(F("Piezo value is "));
    Serial.println(piezoValue);
  }
  // action
  if (piezoValue > threshold) {
    Serial.print(F("Knock was over the threshold of "));
    Serial.println(threshold);
    digitalWrite (onboardLED, HIGH);
    delay(alarmDuration);
    digitalWrite (onboardLED, LOW);
  }
}