9 May 2013

Sound Sensor




This project makes use of Seeedstudio's Grove Sound Sensor. Which essentially gives your Arduino ears ! The small sound sensor (microphone) attaches to an Analog pin on the Arduino and can be used to detect the level of noise in the surrounding environment. You could potentially use this sensor to turn a light on in your house after recognising a specific clap/whistle sequence. In this tutorial we are going to connect a few LEDs to the Arduino, and get it to listen for a click/clap, and respond accordingly. Have a look at the video below for this project in Action.







Parts Required





Assembly

  • Place the Grove Base shield onto the Arduino UNO or compatible microcontroller.
  • Solder some headers onto a ProtoBoard and then stack this onto the Grove Base Shield
  • Stick a Mini-Bread board onto the ProtoBoard.
  • Get 3 LEDs and 330 ohm resistors, connect to Pins 3, 5 and 6, and then to Ground
  • Attach the Sound Sensor to the Grove Base Shield A0 clip (next to shield's reset button) 




Sketch








Arduino LogoArduino Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* =======================================================
ArduinoBasics: Sound Sensor: Written by ScottC 8th May 2013
==========================================================*/

int soundSensorPin=A0;
int soundReading=0;
int soundThreshold=500;
int intensity[3]={0,0,0};
int LEDPins[3] = {3,5,6};
int numberOfPins=3;
int currentPin=0;
int fadeCounter=0;
int fadeDelay=50;
boolean switcher = true;

void setup(){
 pinMode(soundSensorPin, INPUT);
 for(int i=0; i<numberOfPins;i++){
 pinMode(LEDPins[i],OUTPUT);
 }
}

void loop(){
 soundReading=analogRead(soundSensorPin);
 if(soundReading>soundThreshold){
 if(switcher){
 aboveThreshold(currentPin);
 switcher=true;
  }
 } else {
 if(switcher){
 belowThreshold();
 switcher=true;
  }
 }
}

void aboveThreshold(int cPin){
 switcher=false;
 if(intensity[cPin]<10){
 intensity[cPin]=255;
 delay(50);
 currentPin=currentPin+1;
 }

 if(currentPin==numberOfPins){
 currentPin=0;
 }
}

void belowThreshold(){
 switcher=false;
 fadeCounter++;
 if(fadeCounter==fadeDelay){
 fadeCounter=0;
 for(int i=0; i<numberOfPins;i++){
 analogWrite(LEDPins[i],intensity[i]);
 }
 for(int i=0; i<numberOfPins;i++){
 intensity[i]--;
 if(intensity[i]<0){
 intensity[i]=0;
   }
  }
 }
}



44 comments:

  1. how i can connect Grove universal 4 pin cable if i don't have grove - base shield
    thanks

    ReplyDelete
    Replies
    1. SIG (yellow wire) to Analog 0 pin.
      VCC (red wire) to 5v
      GND (black wire) to Ground (GND)

      White wire is not used.

      Delete
  2. can you give the circuit diagram of this?

    ReplyDelete
  3. Hi there so i have this project and know nothing about coding... I need a cat toy to go off when my cat starts meowing(at 5 in the morning). this is the cats toy.. https://www.getcatsmeow.ca/ i have replaced its motor with a 9v so its a little bit more challenging for my cat. and i have it running on a 9v ac power adapter.. I bought this sound sensor on ebay.. http://www.ebay.com/bhp/sound-sensor-module.. it seems to be the same set up as the one you suggested.. I just dont know a thing about coding to get this working.. if you could help out at all that would be awesome.. thanks so much!

    ReplyDelete
  4. sorry i am also a graphic designer and if you would like to trade code for maybe a logo or a new layout for your blog i would be more than willing to hook you up! thanks in advance!

    ReplyDelete
  5. my email is jadonv11@gmail.com

    ReplyDelete
    Replies
    1. Hi Jadon,

      Contact me via youtube, and I'll see what I can do.

      Delete
  6. Hi Scott, Do you have the circuit schematic for the project? I would buid the project but without the grove base shield and protoshield just to see if it can be compensated just using jumpers..
    thank you in advance

    ReplyDelete
    Replies
    1. Hi Beswan,

      You can definitely use this sensor by using jumper wires.
      The LEDs are attached to digital pins 3,5 and 6. Each with their own resistor, and then to ground.
      The Sound sensor has 4 connection points, however one of them is not used.
      Black wire = ground
      Red wire = 5v
      White wire = not used.
      Yellow wire = Connected to Analog pin 0.

      I would still recommend getting the Grove universal 4 pin cable to connect to the sensor, and then cut the other connector off so that you can easily attach the cable to the relevant pins on the Arduino board.

      Delete
  7. Hi, would you be able to use this to detect sound and then play a pre- recorded voice as well as an LED? Thanks

    ReplyDelete
    Replies
    1. Jack,
      Yes it is possible. However note that you would need the appropriate outputs in addition to the items described in this project.
      You could use your computer and the processing language to play a sound file or movie file, or you could find some other way to play the sound, and the illumination of the LED is already displayed in this project.

      Delete
  8. hallo
    am clemo,i saw ur clip on youtube about anttiny 85
    ,i was wondering u may help me out with a project programming using attiny45
    i wanna make clap switch
    operation=clap twice on clap twice off
    Can u help me with code that needed for the project?

    ReplyDelete
    Replies
    1. Hi Clement,
      I don't have an attiny85 - you must have mistaken me for someone else.
      My clip from youtube is shown above.

      Scott

      Delete
  9. How would I use a fast fourier transfer to identify a whistle pattern and then activate an LED? I'm at a road block and needs help badly.

    ReplyDelete
    Replies
    1. Hi Joseph,This question is for the forums. Have never dealt with fast fourier transfer algorithms.

      Delete
    2. This site may help you on your path

      Delete
  10. How would I be able to use the sound sensor to pick up high sounds ( police siren), and turn on or make an LED start flashing once the sound is heard? The important thing here is for the LED to not go off when normal sounds ( speech or clapping) is heard. Thanks

    ReplyDelete
    Replies
    1. and any hints or helpful tips about coding it? or any actual code haha

      Delete
    2. I don't think it discriminates between different frequencies.

      Delete
  11. Do you have a code for Arduino sound detection sensor tk0862 ?

    ReplyDelete
    Replies
    1. Sorry - I don't. I only have code for the sound sensor mentioned above.

      Delete
  12. hey can i use this circuit to detect the crying of babies?

    ReplyDelete
    Replies
    1. It will not discriminate between a baby and any other loud noise. But I guess you could get it to alert you when there is ongoing loud noise. As the noise gets louder the voltage changes. So the answer is yes, but only to the extent described above.

      Delete
  13. sorry, may I know how about this sensor program when we use atmega32 and bascom language?
    thank's before :)

    ReplyDelete
    Replies
    1. Hi Janur,
      I have never heard of the bascom language - sorry.
      Any reason why you don't want to use the Arduino IDE? It's free !!

      Delete
  14. Hi Scott, Can you tell me how to connect microcondensor directly to mikrokontroler arduino? I just need to read the voltage of the frequency. maybe you have the code for arduino. please tell me by email . thanks scott. i would appreciate it.

    ReplyDelete
    Replies
    1. Hi MMC,

      Have you seen this tutorial?
      http://www.arduino-hacks.com/arduino-vu-meter-lm386electret-microphone-condenser/

      I have never used a micro condenser on it's own. Sorry.

      Delete
  15. sir can i have the schematic diagram of this? I need this sir for my undergrad. thesis.. pls reply sir

    ReplyDelete
    Replies
    1. I did not do a schematic diagram for this project.
      But should be easy for you to create one in Fritzing (if required).

      Delete
  16. Sir can I adjust the volume or the loudness that it can receive???....because I will make an prototype that measure a sound or voice level that when the sound reach it's maximum decibel it will trigger the buzzer or the camera?

    ReplyDelete
    Replies
    1. I have never tried to adjust the sensitivity of the sensor, but I guess that is what the potentiometer is there for - I am not certain about this, because I have not checked.. But it can differentiate a loud noise from a soft one. The analog reading will change depending on how loud the sound is, and you could use this fact to only trigger when the analog reading reaches above a certain level.

      Delete
  17. I wrote a MATLAB script interfacing my laptop's inbuilt microphone to calculate the dbA levels of noise in my classroom. (un-calibrated, as of now)

    I want to now use this dbA calculation script on data from my arduino. (Electret Microphone Amplifier 4466). I want know what is the difference in the 2 inputs and what changes I should make in acquiring my data from the arduino to receive the same result as I did with the inbuilt microphone.

    ReplyDelete
    Replies
    1. I have no idea... I have never used MATLAB.

      Delete
  18. goodmorning sir, actually im going to create a project and one of its function is to detect the crying sound of the baby.. and one of my big problem is that i dont know what sensor to be use. can u help me :) thankyou sir

    ReplyDelete
  19. This product is pretty much over priced and useless since it's best use requires you buy a cable, build a shield to make it work properly total ripoff

    ReplyDelete
    Replies
    1. Hi Anonymous,
      Yes - the grove cable makes it easier to connect to the module, and the Grove Base shield makes it easier to interface with the Arduino, however, neither are compulsory. You could just connect the module directly to the Arduino without the shield. In fact, you could even use this module without an Arduino. But I must say that there aren't many modules out there that don't require you to buy a cable or wire of some sort.. that is just the reality of working with modules.
      I don't agree that it is useless... in fact I found this module to be very reliable, and works just as I expected it to... much better than some of the "cheaper" stuff you can buy elsewhere. I don't think that it is over-priced either... a good module for less than $5... I don't regret paying that amount for something that works well, and has some solid information from the manufacturer to get you up and running in next to no time: http://www.seeedstudio.com/wiki/Grove_-_Sound_Sensor. What you save on the cost of a cheaper module, you lose on the amount of time trying to figure out how to use it (providing it works).

      I guess I disagree with everything in your comment.
      But that is ok, we can agree to disagree :)

      Delete
  20. hi scott
    i am working on project, where i want to detect cry/shout of an adult (human).Does it possible? if yes then, what hardware are required? i have microphone , arduino nano. i am having problem with cry detection using these hardwares? actually i want to differentiate bewteen other loud sound and human cry. please HELP ME.thanks in advance

    ReplyDelete
    Replies
    1. I don't know how you would differentiate between other loud sounds and a human cry? You would have to have some way of analysing the different frequencies... similar to speech recognition. And that, I'm sorry to say, is beyond my level of knowledge.

      Delete
  21. Scott!
    what if i want to recognize single words like FOOD , WATER , SlEEP and send a signal to android app through HC 05? Does it possible with Arduino? and else hardware are required? Help me.

    ReplyDelete
    Replies
    1. Hi Zeeshan - this also would require some sort of analysis of the sound signals... and as mentioned previously - is beyond my level of knowledge. There may be a module out there that can handle the speech recognition processing required ... but I have not come across it yet.

      Delete
  22. scott- Do you know anyone who can help me in that!

    ReplyDelete
    Replies
    1. Zeeshan - your best bet is likely to be the Arduino forum

      Delete
  23. Hey, so this is a sound sensor which beeps/flashes if the sound level is above a certain threshold. But can we modify it to make a sound detector( as in which could distinguish different voices) ?

    ReplyDelete
    Replies
    1. No - it does not detect different frequencies.
      This particular sensor detects decibels.

      Delete

Feel free to leave a comment about this tutorial below.
Any questions about your particular project should be asked in the ArduinoBasics forum.

Comments are moderated due to large amount of spam.