This is a breakout board of an Electret microphone, sound sensor. Which is essentially provide your Microcontroller an ear to detect or listen sound wave. This microphone has 100Hz-10kHz with an 60x mic preamplifier to amplify the sounds of voice, claps, door knocks or any sounds loud enough to detected by the microcontrollers. This device use uses analog or digital as the connected either digital or analog. Basically the electret Mic translate amplitude not volume by capturing sound wave between two conducting rod or plates one is the vibrating diaphragm and the other one fixed in the microphone and converting them into electrical waves form . These electrical signals are amplified and pickup by the microcontroller. As you can see below there are two example one is using digital and the other is using analog. Just follow the illustration below for the wiring.
Required Components
- Arduino UNO, MEGA, DUE, LEO, NANO, PRO, ESP8266 13, 12, 7, 11.
- LED (Any Color)
- Resistor 200 Ohms
- Solder Less Bread Board
- Jumper Wire / DuPont Wire
Wiring Diagram for Digital
Source Code / Sketch Code for Digital Pin
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 |
/* 14CORE Test Code for: Sound Sensor .:+osysso++:` `+yhs/-` `-+s+` `:/+++++++++` .:/++ooo++/-` .ooooooooooo+: :///////////- `odh/` `:y+` /ddhsooooooo+ /hddhsooooydddh sdddoooooosdddy` `////////////` -hds` `sy. +ddy` .ddd: sddy.dddo +ddd- .-----------` `hds :sssss/ -ossssso-yy` `hdd: oddy `ddd/oddd:......+dddo .++++++++++++ +dd` :sdddh` :ydddddddo +y/ .ddd+........ `hddy:.....:yddy.hdddddddddddy+. ```````````` ydy .hddd/+hdddhydddh/.+yo /hdddddddddd. :shddddddddhs/`+ddd:````-yddy- :ooooooooooo+ odh` sdddooyyyyyhddddyy.sy+ ` `......... ``.... ....` ```...` ` `` `` ` -dd+`::::` .:::- /yy. -oos+:-oos+--oos+: /o `+y o/: o:+/ h:`yos /+-`/+/+ s:y/y. /dd/ `+yy: +//+ +/:+ +/:+ -. `/ -:o.:/:`//+- + +:- :`-+:`://: +`o`+. -yds. `/yys- .`-.. .``` ```` .`` ` ` ``` ``-..` ` :ydy/.`````.-/oyhs: `+++oo+oo+:.+-++/-/ooo+o +:o/oo///:+/ .:oyhhhhhhhso:` `. ``` */ int MyLedOut = 12;// Define as Output Led (The led attach to the MCU is optional) int SensorPin = 2; //Define as digital pin 2 int Value = 0;// Define as variable to hold the state Valueue void setup () { pinMode (MyLedOut, OUTPUT) ;// define LED as output interface pinMode (SensorPin, INPUT) ;// output interface D0 is defined sensor } void loop () { Value = digitalRead(SensorPin);// Set the value is equal to digitalPin 2 to be read if (Value == HIGH) // If the sound sensor detect sound wave set MyLedOut to High or ON { digitalWrite (MyLedOut, HIGH); } else { digitalWrite (MyLedOut, LOW); // If no sound detected set MyLedOut to LOW or OFF } } |
Wiring Diagram for Analog
Source Code / Sketch Code for Analog Pin
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 |
/* 14CORE Test Code for: Sound Sensor .:+osysso++:` `+yhs/-` `-+s+` `:/+++++++++` .:/++ooo++/-` .ooooooooooo+: :///////////- `odh/` `:y+` /ddhsooooooo+ /hddhsooooydddh sdddoooooosdddy` `////////////` -hds` `sy. +ddy` .ddd: sddy.dddo +ddd- .-----------` `hds :sssss/ -ossssso-yy` `hdd: oddy `ddd/oddd:......+dddo .++++++++++++ +dd` :sdddh` :ydddddddo +y/ .ddd+........ `hddy:.....:yddy.hdddddddddddy+. ```````````` ydy .hddd/+hdddhydddh/.+yo /hdddddddddd. :shddddddddhs/`+ddd:````-yddy- :ooooooooooo+ odh` sdddooyyyyyhddddyy.sy+ ` `......... ``.... ....` ```...` ` `` `` ` -dd+`::::` .:::- /yy. -oos+:-oos+--oos+: /o `+y o/: o:+/ h:`yos /+-`/+/+ s:y/y. /dd/ `+yy: +//+ +/:+ +/:+ -. `/ -:o.:/:`//+- + +:- :`-+:`://: +`o`+. -yds. `/yys- .`-.. .``` ```` .`` ` ` ``` ``-..` ` :ydy/.`````.-/oyhs: `+++oo+oo+:.+-++/-/ooo+o +:o/oo///:+/ .:oyhhhhhhhso:` `. ``` */ int SensorAnalogPin = A0; //Adjust the pontensionmeter to change the Analog input DEC value int MyLedOut = 12; // Define as Output which is connected to Digital pin 12 int Value = 0; // Define as to hold the value of SensorAnalogPin which is connected to A0 void setup () { pinMode (MyLedOut, OUTPUT); //Set the digital pin 12 as output Serial.begin (9600); //Start serial communication to get the DEC value from the sensor } void loop () { Value = analogRead (SensorAnalogPin); digitalWrite (MyLedOut, HIGH); delay (Value); digitalWrite (MyLedOut, LOW); delay (Value); Serial.println (Value, DEC); } |
Example Code for Sound Detection with PWM
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 |
int intens[3]={0,0,0}; int MyLedOut[3] = {3,5,6}; //Place 3 LED to Pin 3, Pin 5, and Pin 6 int Pins=3; int PinCurrent=0; int FaderCounter=0; int DelayFade=50; int SensorPin=A0; int SensorSound=0; int ThresholdValue=500; boolean Switchs = true; void setup(){ pinMode(SensorPin, INPUT); for(int i=0; i<Pins;i++){ pinMode(LEDPins[i],OUTPUT); } } void loop(){ SensorSound=analogRead(SensorPin); if(SensorSound>ThresholdValue){ if(Switchs){ aboveThreshold(PinCurrent); Switchs=true; } } else { if(Switchs){ belowThreshold(); Switchs=true; } } } void aboveThreshold(int cPin){ Switchs=false; if(intens[cPin]<10){ intens[cPin]=255; delay(50); PinCurrent=PinCurrent+1; } if(PinCurrent==Pins){ PinCurrent=0; } } void belowThreshold(){ Switchs=false; FaderCounter++; if(FaderCounter==DelayFade){ FaderCounter=0; for(int i=0; i<Pins;i++){ analogWrite(LEDPins[i],intens[i]); } for(int i=0; i<Pins;i++){ intens[i]--; if(intens[i]<0){ intens[i]=0; } } } } |