IoT/Intel Edison
Grove - Sound Sensor
appmarkers
2015. 1. 24. 22:18
Grove - Sound Sensor
Grove - Sound Sensor can detect the sound strength of the environment.
The main component of the module is a simple microphone, which is based on the LM358 amplifier and an electret microphone.
This module's output is analog and can be easily sampled and tested by a Seeeduino.
Hardware Required
- Intel® Edison Module
- Arduino* expansion board
- Grove Base Shield v2
- Grove Sound Sensor
Circuit
Schematic
Code
// Function: If the sound sensor senses a sound that is up to the threshold you set in the code, the LED is on for 200ms.
// Hardware: Grove - Sound Sensor, Grove - LED
/*macro definitions of the sound sensor and the LED*/
#define SOUND_SENSOR A0
#define LED 2 // the number of the LED pin
#define THRESHOLD_VALUE 400//The threshold to turn the led on 400.00*5/1024 = 1.95v
void setup()
{
Serial.begin(115200);
pins_init();
}
void loop()
{
int sensorValue = analogRead(SOUND_SENSOR);//use A0 to read the electrical signal
Serial.print("sensorValue ");
Serial.println(sensorValue);
if(sensorValue > THRESHOLD_VALUE)
{
turnOnLED();//if the value read from A0 is larger than 400,then light the LED
delay(200);
}
turnOffLED();
}
void pins_init()
{
pinMode(LED, OUTPUT);
pinMode(SOUND_SENSOR, INPUT);
}
void turnOnLED()
{
digitalWrite(LED,HIGH);
}
void turnOffLED()
{
digitalWrite(LED,LOW);
}
See
Also
Reference sites