37种传感器(六)之声音传感器模块+Stduino Nano&UNO
本文转载自:http://www.stduino.com/forum.php?mod=viewthread&tid=28&extra=page%3D1=
关键词:
51、stm32、arduino、stduino、单片机、stduino UNO&Nano、声音模块
说明:
声音传感器的作用相当于一个话筒(麦克风)。它用来接收声波,显示声音的振动图象,但不能对噪声的强度进行测量。传感器内置一个对声音敏感的电容式驻极体话筒。
声波使话筒内的驻极体薄膜振动,导致电容的变化,而产生与之对应变化的微小电压。这一电压随后被转化成0-5V的电压,经过A/D转换被数据采集器接收。
模块有两个输出,AO输出模拟量,实时输出麦克风两端电压值;当声音强度到达某个阈值时,DO引脚输出高电平信号,否则输出为低电平信号。(阈值可通过电位器调节)
实验目的:
检测声音
器材:
Stduino Uno/Nano;杜邦线;声音传感模块。
电路连接:
代码展示:
- <font face="Arial">int LED = 13;
- int BUTTON = 8;//DO接口
- int val;//数字变量val
- void setup()
- {
- // put your setup code here, to run once:
- pinMode(LED,OUTPUT);
- pinMode(BUTTON,INPUT);
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- val=digitalRead(BUTTON);
- if(val ==HIGH)//当监测到有声音时,LED闪烁
- {
- digitalWrite(LED,LOW);
- }
- else
- {
- digitalWrite(LED,HIGH);
- }
- delay(1000);
- val = 0;
- }</font>
复制代码
- <font face="Arial" size="3">int sensorPin = A0;//A0接口
- int ledPin = 13;
- int sensorValue = 0;//数字变量val
- void setup()
- {
- // put your setup code here, to run once:
- pinMode(ledPin,OUTPUT);
- pinMode(sensorPin,INPUT_ANALOG);
- Serial.begin(9600);
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- sensorValue=analogRead(sensorPin);
- digitalWrite(ledPin,LOW);
- delay(sensorValue);
- digitalWrite(ledPin,HIGH);
- delay(sensorValue);
- Serial.println(sensorValue);
- }</font>
复制代码 实验效果:
|