Mic & led

Hi everyone,
i'm trying to turn on a led when the "sound" level is over the value i decided, something like here-Arduino + Sound Sensor - Daniel Andrade

only i'm using this mic- Search results for: 'condenser microphone 2 2k ohm 1 5v'

with this amplify circuit (was recommended at this forum)-
and i also connected the output of the amplifier (the transistor collector) to pin 0 through 0.1uF capacitor. the empty thing in the middle is where the PNP transistor goes in :slight_smile:

i'm using this code:

int led = 8;
void setup(){
pinMode(0,INPUT);
pinMode(led,OUTPUT);
Serial.begin(9600);
}
void loop(){
  digitalWrite(led,LOW);
int micvalue= analogRead(0);
Serial.println(micvalue);
delay(200);

if(micvalue>650){
digitalWrite(led,HIGH);
delay(30);
}
else{
digitalWrite(led,LOW);
}
}

in silence i get somthing like 630-640~ and when i put my iphone next to the mic, the micvalue goes above 650 - it stays above it get stuck at 740 or 900 or any value bigger than 650, and then the led blinks without stopping.
here is a video of it:

Hi,

I think you are charging up that capacitor for a "long" time.

The Arduino analog input has a VERY high impedance: perhaps 100 million ohms.

Connect a 10K or so resistor from A0 to ground. Experiment with the value.

Let us know how it goes....

Other: an off-the-shelf solution to Sound Sensing is: http://yourduino.com/sunshop2/index.php?l=product_detail&p=367

DISCLAIMER: Mentioned stuff from my own shop...

Where did you get that mic circuit? Its nonsense. You have 3.3V rail shorting out the signal.

As usual wikipedia wins for us:

But actually the capacitor isn't needed as we can do the low-pass filtering in software
after the ADC, so just a single resistor is enough.

BUT that's unlikely to work - microphones output a signal level of a millivolt or so at
normal sound levels. You won't be able to see that directly with the ATmega's 10 bit
ADC unless you shout right into the microphone.

You need amplification - there are microphone modules with an on-board opamp to
boost the signal level to something more sensible - for instance SparkFun Electret Microphone Breakout - BOB-12758 - SparkFun Electronics
which has 100x amplification (40dB gain, to be technical).

Connect a 10K or so resistor from A0 to ground. Experiment with the value.

terryking228 - it did work, i'm getting 0-2~ in silence and it goes up dependes on the noise. BUT im having another problem:
i hooked up the led to a PNP transistor and changed the code a bit:

int led = 8;
void setup(){
pinMode(0,INPUT);
pinMode(led,OUTPUT);
Serial.begin(9600);
}
void loop(){
  digitalWrite(led,HIGH);
int micvalue= analogRead(0);
Serial.println(micvalue);
delay(50);

if(micvalue>25){
digitalWrite(led,LOW);
}
else{  digitalWrite(led,HIGH);}

}

so now the led turn on only when there is sound. TWO THINGS:

  1. my main goal is to activate/fire a dslr flash. so it's look like this

im connecting the two wires (blue&white) to emitter&collector, and when i make sounds nothing happens. i tried changing the sides of the wires (blue to collector and white to emitter) but no change, and when i connect the led it's works. if i connect directly the blue wire to the white the flash fires of course.

  1. when only the led connected, when there is sound the led blinks in very low light (dimmed). i thought maybe it's because it's happen very quickly so i delayed the blink for 10ms , and then the micvalue is stuck again on 300 and somthing.....

i hooked up the led to a PNP transistor and changed the code a bit:

Need to see circuits. Hand drawn / photo ok....

Other possible solution: LED to Photoresistor (black tape) to camera...

i'm a bit a shame of the sketch but here you go:
https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-frc1/1001463_10201081438455286_1630215336_n.jpg

(it's a pnp transistor like i mentioned)

OK, the PNP to the camera is just "floating.

You need:

  • 1K or so resistor from PNP base to Arduino Pin 8 (Note will be active LOW)
  • PNP Emitter connected to Arduino +5v
  • PNP Emitter and Base connected to camera so the emitter is at camera + terminal

Best: Use an optoisolator like 4N35 etc. It has a LED inside, coupled to a transistor.

Examples: http://www.glacialwanderer.com/hobbyrobotics/?p=10
One doing both focus and shoot: http://mirkules.com/blog/wp-content/uploads/2012/11/optoisolator_fire_schem.png

DISCLAIMER: Mentioned stuff from my own shop... like these 4N35: http://yourduino.com/sunshop2/index.php?l=product_detail&p=315

are you sure its not going to damage my flash or Arduino connecting the 5v to the emittet together with the flash?
And what about the collector leg? Gnd?

and I know there is a better microphone with an amplifyer but right now I have this one and I prefer to use it. But thanx for the offer

Why does your code set the led pin HIGH before you even read the analogue input ?

Because its a pnp transistor its normaly close - which mean the High command will turn it off

I understand that, but to put it another way.
Why are you turning off the LED before checking the value of the analogue input ?

You seem to be confusing yourself (& us) by attempting to debug everything at once. I suggest you get the input working (just use Serial.print () to show what you are reading, then get the LED behaving the way you want (maybe Serial.parseInt () to provide fake levels), and then get your logic worked out (again using Serial to supply levels and monitor program flow).
Or any other order that suits you. Divide & conquer.

Right now the only problem i have is that theflash doesnt fire - and terryking228 explained why- the PNP to the camera is just "floating. And he advised me with a solution butmy worry is:
are you sure its not going to damage my flash or Arduino connecting the 5v to the emittet together with the flash?
And what about the collector leg? Gnd?

And i dont have an optoisolator right now, so i just wanna make sure his solution not gonna harm my flash