1
声音传感器模块是一个简单的麦克风。基于放大器LM358和驻极体麦克风,可用于检测环境的声音强度。
Steps
Code
串行监视器在检测到声音时打印 LOUD, LOUD 否则它打印 Quiet
int soundDetectedPin = A0; // Use Pin 10 as our Input
int soundDetectedVal = HIGH; // This is where we record our Sound Measurement
boolean bAlarm = false;
unsigned long lastSoundDetectTime; // Record the time that we measured a sound
int soundAlarmTime = 500; // Number of milli seconds to keep the sound alarm high
void setup ()
{
Serial.begin(9600);
pinMode (soundDetectedPin, INPUT) ; // input from the Sound Detection Module
}
void loop ()
{
soundDetectedVal = analogRead (soundDetectedPin) ; // read the sound alarm time
//Serial.println(soundDetectedVal);
if (soundDetectedVal > 400) // If we hear a sound //change this value for increasing/decreasing sensitivity
{
lastSoundDetectTime = millis(); // record the time of the sound alarm
// The following is so you don't scroll on the output screen
if (!bAlarm){
Serial.println("LOUD, LOUD");
bAlarm = true;
}
}
else
{
if( (millis()-lastSoundDetectTime) > soundAlarmTime && bAlarm){
Serial.println("quiet");
bAlarm = false;
}
}
}
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表德赢Vwin官网 网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !