×

基于放大器LM358和驻极体麦克风

消耗积分:0 | 格式:zip | 大小:0.00 MB | 2023-06-20

张涛

分享资料个

描述

声音传感器模块是一个简单的麦克风。基于放大器LM358和驻极体麦克风,可用于检测环境的声音强度。

Steps

  • 将 Grove 电缆的一侧连接到声音传感器
  • 将 Grove 电缆的另一端连接到 Grove 屏蔽的 A0
  • 运行下面给出的代码
  • 打开串口监视器(ctrl + shift + m)查看输出

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;
   }
 }
}

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !