Introduction: Sound Level Detector Using LinkIt One

Hello!
In this Instructable we would be making a sound level detector and getting LED high output from the MediaTek LinkIt One once the trigger value is hit!

Let us start!

Step 1: What You Will Need?

  1. MediaTek LinkIt One
  2. Sound Sensor ( I shall be using the Grove Sound Sensor here!)
  3. LED (optional, we can use the 13th digital pin!)

Step 2: Assembly

Assembly for this project is pretty simple.
Connect the Sound sensor to the Grove ports or using the shield.

If you have the analog sensors, connect them using the Analog pins directly.

Connect the LED +ve to 13th digital pin and -ve to GND.

That's it! Pretty easy, right?

Step 3: Programming - Part 1

Let us start with basic code for Sound Sensor and then modify the same for output on 13th pin.

Base code:

const int pinSound = A0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
int value = analogRead(pinSound);
Serial.println(value);
delay(100);
}

This will serial print the value of sound.

Step 4: Programming - Part 2

Let us now augment the previous code to include support for the output on 13th digital pin, which also has an inbuilt LED.
We know, to use the pin as output, we have to specify so in the setup function.
pinMode(13, OUTPUT);

Code:

const int pinSound = A0;

void setup()
{

pinMode(13, OUTPUT);
Serial.begin(9600);

}

void loop()
{
int def=20; //set your threshold value here
int value = analogRead(pinSound);
Serial.println(value);
if(value>def)
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
}
else
{

digitalWrite(13, LOW); // turn the LED off(LOWis the voltage level)
}

delay(1000);

}