Clapper

I have made a (reasonably) reliable clapper!
I used a circuit that I made myself to connect the microphone.
I know there are better circuits, but I didn't have an amp chip thing.
Here's the circuit:
5v
|
|----------|
| C O mike
|
)--B------|
| E
|
analog 0-----*------ww------|i ground
10k

Here's the code:

int def;
int on = false;
int switch1 = false;
int switch2 = false;

void setup()  {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  delay(250);
  int num1 = analogRead(0);
  delay(250);
  int num2 = analogRead(0);
  delay(250);
  int num3 = analogRead(0);
  def = (num1 + num2 + num3) / 3;
  digitalWrite(13, HIGH);
  delay(100);
  digitalWrite(13, LOW);
}

void loop()  {
  if(abs(def - analogRead(0)) > 3)  {
    delay(200);
    if(abs(def - analogRead(0)) > 3)  {
      switch1 = false;
    } 
    else {
      switch1 = true;
    }
    long time = millis();
    while((abs(def - analogRead(0)) < 3) && millis() <= time + 1000)  {
    }
    if(abs(def - analogRead(0)) > 3)  {
      switch2 = true;
    }
    else  {
      switch2 = false;
    }
    if(switch1 && switch2)  {
      if(on == false)  {
        digitalWrite(13, HIGH);
        on = true;
      }
      else  {
        digitalWrite(13, LOW);
        on = false;
      }
    }
  }
}

So far, it turns the led on or off with 2 claps.
It could easily be modified to work with 2 or more leds, where to light the second you clapped thrice (?) etc.

Hm, can be interesting for an enveloppe follower.
What's CBE on the schematic?

I think thats the Collector, Base and Emitter pins of a transistor.

  • Spirou

Yep, Spirou is right. By the way, it's a 2n2222 transistor.

Hm, can be interesting for an enveloppe follower.

What's an envelope follower?

Ok :wink:

An enveloppe follower is a device used for following the amplitude of sound. This data is then used as a (MIDI) controller or in a synth to have a more natural enveloppe for example!

Oh. I still don't quite understand, but whatever. By the way, this circuit gives readings up or down for loudness. That is why I used abs(). The lower or higher the reading is from the default, the louder it is. This makes it hard to distinguish the space between two different sounds, as the reading from the output is constantly flickering.

What we call enveloppe is what you call loudness.
The idea is that you can use this data to modulate something other.
For example, you sing to have a more natural dynamic profile than just playing on faders, and you use this data for the dynamic profile of a synth

I will give it a try when I have more time!

I tried out your circuit and it doesnt seem to want to work for me :(... I think your circuit needs to be like this

5v
|
|----------|
| E O mike
|
)--B------|
| C
|
analog 0-----*------ww------|i ground
10k