Brick-SoundSensor

From ArduinoInfo
Jump to: navigation, search

Sound Sensing Brick

Sound_Sensor-Brick-1024.jpg
NOTE: The new 2012 version Sound Sensor is different and this example does NOT work. It will be updated..
The sound sensing brick includes a high sensitivity microphone and an onboard Low Voltage Audio Power Amplifier (LM386). Sensitivity is adjustable with the potentiometer labelled "VR1".

The sound sensor measures the volume of sound near the microphone.

This sensor connects with the usual 3-wire cable to a Analog Input (Usually plugged into a http://arduino-info.wikispaces.com http://arduinoinfo.mywikis.net/wikiSensorShield Sensor Shield]).

Below is example code to read data from the sensor. (Copy and Paste this into a blank Arduino IDE window, Verify and then Upload.) Click on the Serial Monitor (Rightmost Button) to see sound volume values.

/* YourDuino Electronic Brick Test
   Sound Sensor
   terry@yourduino.com */

/*-----( Declare Constants / Pin Numbers )-----*/
#define  SOUND_PIN  A2
#define  LED_PIN    13

/*-----( Declare Variables )-----*/

int  SoundValue  =0;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  pinMode(LED_PIN, OUTPUT);  // declare the ledPin as an OUTPUT
  Serial.begin(9600);        // initialize serial communication with computer
}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  SoundValue = analogRead(SOUND_PIN);    // read the value from the sensor
  Serial.println(SoundValue, DEC);          // send it to the computer (as ASCII digits)

  if (SoundValue > 50)
  {
    digitalWrite(LED_PIN, HIGH);  // turn the ledPin on
    delay(SoundValue*5);                  // stop the program for some time
  }

  digitalWrite(LED_PIN, LOW);   // turn the ledPin off
  delay(200);                  // stop the program for some time

}/* --(end main loop )-- */

/* ( THE END ) */