Sound sensor troubleshooting

Hello everybody,

I purchased my arduino MC yesterday and went through a few of the "learning" links provided on www.arduino.cc however got stuck with reading the input of a sound sensor... For some reason, the serial window is outputting different values no matter the condition of the sensor, and it is always random, even if i unplug the sensor!

Here is my code:

int sensorPin = A0;
int ledPin = 13;
int sensorValue = 0;

void setup() {

pinMode(ledPin, OUTPUT);
}

void loop() {

sensorValue = analogRead(sensorPin);
Serial.println (sensorValue);

digitalWrite(ledPin, LOW);

if (sensorValue = 0)
{
digitalWrite(ledPin, HIGH);
}
}

I believe i am missing something in the setup method, something for INPUT, any hints?

Also, here are some photos:

I am assuming...
VCC is voltage
GND is ground
AUD is INPUT
http://www.filedump.net/index.php?pic=img20111223002311324701700.jpg

Here is how i hooked it up to the arduino MC:
http://www.filedump.net/index.php?pic=img20111223002321324701700.jpg

What i was attempting to do was whenever a sound reaches a certain frequency when detected by the sound sensor, the LED would light up. However my issue is trying to figure out the random numbers i am getting...

Please help me out on my first project :slight_smile:

Cheers,

Phil.

Well for a start that picture shows an LED connected to pin 13 without any series resistor. Any touorial that shows you that is very wrong and could damage your arduino.

I am not sure what an "arduino MC" is can you provide a link to this and your sound sensor. However ......

A sound sensor is a microphone so all you will get is seemingly random numbers from it as it samples the audio waveform.

What i was attempting to do was whenever a sound reaches a certain frequency when detected by the sound sensor, the LED would light up.

That is a lot more complex project than you think and is defiantly not one for a beginner.

Thank you for your reply...

Where can i read about which resistor is appropriate for different uses? (link?)

What i meant was Arduino Micro Controller (i used an acronym), however in my photo that i uploaded, you can see that i use an arduino UNO.

I do not know what model the sound sensor is as the store who sold it to me doesn't have anything on their website and the PCB itself doesn't have any useful information... The packaging however did have a label with information on it:

http://www.filedump.net/index.php?pic=img20111224002331324704307.jpg

Could you also give me more guidance for the progressive steps to take in order to achieve the goal which you noted is not for a beginner?

Cheers!

I look at the pictures and the "sound sensor". I notice the color - RED of the PCB board, and I was wondering if this "mic" is alone or with a circuit, so I was thinking ... RED PCB in Sparkfun Electronics PCB boards products, and I find this --->
SparkFun Electret Microphone Breakout - BOB-12758 - SparkFun Electronics and I look at the schematic of this product. That "mic' look like the one you are using ( my guess ) and I look at your program....

 if (sensorValue = 0)
  {
  digitalWrite(ledPin, HIGH);                  
  }

Well...Just say it will be hard to get a value of zero. The only condition that a zero "may" happen, a big voltage swing of + 5 V / 0V at the output of the "mic" <-- A very lound sound. The "mic" amp is set at a gain of 100.

Yep... My guess is correct. BOB-09964 is from Sparkfun Electronics ( It is fun using Ask.com and google.ca )

What i was attempting to do was whenever a sound reaches a certain frequency when detected by the sound sensor, the LED would light up. However my issue is trying to figure out the random numbers i am getting...

You need a "tune filter" ( an extra analog circuit to "filter" out the frequency from the sound wave < --- A sound wave contain multitude of frequencies within the wave. ) and a "peak detector" circuit ( measure a peak-to-peak signal into a DC signal ). Then the output of the "detector" will go toward the analog pin, set the program if it reach a certain value to trigger the LED.

My idea.

Sorry, i am a newby, the reason i set it to zero was because i did not know which value to try or what the values coming in the Signal console really meant... I was hoping someone could explain it to me.

I also ordered some resistors, so no work will be done until those arrive, but research never hurts :stuck_out_tongue:

Techone, thank you for giving me a solution, however i am afraid all this information (may seem minimal to you) is far too much at my current understanding, i get the general concept though. Elaboration would be very hepful and appreciated!

Any guides on what i should work on to progress to my goal as i mentioned?

Thank you!!!

A sound waveform is a complex and rapidly varying voltage:-
http://method-behind-the-music.com/mechanics/physics

If you sensor is wired up correctly and working you will see random numbers returned from measuring this voltage. When the sound is very low these numbers will have a restricted small range around 512, as the sound gets louder the maximum and minimum of these numbers will get further apart. Remove your LED and see if that happens.

When you disconnect the sensor you will again get random numbers but this time because of pickup because the input is "floating", this link explains about floating inputs:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Using a tone detecting chip is relatively simple but only works for one frequency.
If you want to do it for bands then look here:-
http://skoba.no-ip.org/msgeq7/index.html

However if you want to detect any frequency the software selects then you need a bit of complex maths called an FFT:-

Having said that I would recommend that you learn too use the arduino first by following some of the tutorial so at least you can understand any answers given to you, start here:-

Thanks for all the help fellas!!

To elaborate on my original intentions, i wanted the sound sensor to control the intensity of the light based on the frequency the sound sensor detects. Of course this complicates it as it has to be an analog control, but i would be with digital for now as it seems simpler.

Here is a picture of something i had, however broke from being cheaply built... http://www.google.ca/imgres?q=sunbeam+sound+sensor&um=1&hl=en&sa=N&rlz=1C1_____enCA463CA463&biw=1920&bih=1099&tbm=isch&tbnid=FX1AgysM3fGiAM:&imgrefurl=http://lps2u.com/newshop/products/Sunbeam-Audio-Sound-Controller.html&docid=G_djFW9YEXMHyM&imgurl=http://www.lowerpricestore.com/img/aud/sb/sc/main_640.jpg&w=640&h=480&ei=WCL2TuCFMInr0gGNuvC1Ag&zoom=1&iact=hc&vpx=311&vpy=307&dur=6061&hovh=194&hovw=259&tx=184&ty=119&sig=110393392758143287479&page=1&tbnh=148&tbnw=189&start=0&ndsp=56&ved=1t:429,r:10,s:0

I wanted to make something that reacts to music playing.

@Grumpy_Mike

Thanks for the link of the EQ chip. That look interresting and I will plan to order one and experiments so I will be more familiar with it. I download the datasheet.

@the_big_dill

To elaborate on my original intentions, i wanted the sound sensor to control the intensity of the light based on the frequency the sound sensor detects. Of course this complicates it as it has to be an analog control, but i would be with digital for now as it seems simpler.

I look at the controller you talk about, I don't think this device use "frequency" to control the intensity of the light, but the amplitude of the sound wave to control the intensity of the light. My instint <-- gut feeling --- tell me when the sound is low, a low light flashing, and when the sound is lound, a lots of flashing... I am correct ? work like a VU meter... In that case, you have what you need ( the mic , Arduino and a LED ) Connect the Led with a limiting resistor about 330 ohm to 470 ohm ( at Digital pin 11 for a PWM, or disconnect that led and use the UNO pin 13 led already builtin using delay. Than you just do a code to control the LED using the data from the analog pin input.

Techone,

That is EXACTLY what i wanted to do :slight_smile: And you are CORRECT!

I just lack the accurate vocabulary to describe what i want in this topic :stuck_out_tongue:

I placed an order on about 100 resistors yesterday, 50 @ 330 Ohms and 50 @ 270 Ohm, Any other resistors i would most likely need?

Also, which type of "controller" should i use to regulate different modes, as in the picture i showed you? I believe they are called "potentiometers"?? They have different specs, which should i look into buying?

Thanks again for the awesome help :slight_smile:

I believe they are called "potentiometers"

Yes get 10K ones for the arduino.

Any other resistors i would most likely need?

I would get 1K & 10K as well.

Of course this complicates it as it has to be an analog control, but i would be with digital for now as it seems simpler.

You can use PWM control to digitally control the brightness:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

Would something like this work?

And thanks for the great links you provided, very pleasing to read :slight_smile:

Yes those pots look fine.