本来准备把Sound Sensor拿来做麦克风拾音,结果发现 Wiki上说:
Grove - Sound Sensor是一个简单的麦克风。它是基于LM386以及电极麦克风制作的,能用于探测环境声音的强度。输出信号的增益可以通过板上的一个电位器调节。
然后我就在找电位器……电位器呢?!!!
而且上面还是LM358……
难道是我的Wiki版本不对?
既然都说了是用来探测环境声音强度的,那就用来检验强度吧。
接A3口,然后用led灯输出,就做一个声控灯吧……
下面是简单的程序代码~
麦克风设置为模拟输入~
- #include
- #include
- #include "rgb_lcd.h"
- #include <timerOne.h>
- #define THRESHOLD_VALUE 400//The threshold to turn the led on 400.00*5/1024 = 1.95v
- rgb_lcd lcd;
- Servo myservo;
- const int colorR = 255;
- const int colorG = 255;
- const int colorB = 255;
- const int thresholdvalue = 10 ; //led trun on value
- const int timerInterval = 15 * 1000; //15ms
- const int APinTemp = 0;
- const int APinBright = 1;
- const int APinPot = 2;
- const int APinSound = A3;
- const int DPinLed = 2;
- const int DPinServo = 3;
- const int DPinKey = 4;
- const int DPinBuzzer = 5;
- const int DPinTouch = 7;
- void setup()
- {
- lcd.begin(16, 2);
- lcd.setRGB(colorR, colorG, colorB);
- // lcd.setCursor(0, 0);
- // lcd.print("temp:");
- lcd.setCursor(6, 1);
- lcd.print("panpan2333");
- pinMode(DPinLed , OUTPUT);
- pinMode(DPinBuzzer , OUTPUT);
- pinMode(DPinKey , INPUT);
- pinMode(DPinTouch, INPUT);
- pinMode(APinSound , INPUT);
- // myservo.attach(3);
- // Timer1.initialize(timerInterval);
- // Timer1.attachInterrupt( showLcd );
- // attachInterrupt(DPinKey, interruptKeyControlLed, CHANGE);
- }
- void loop()
- {
- int sensorValue = analogRead(APinSound);//use A3 to read the electrical signal
- lcd.setCursor(0, 0);
- lcd.print("sensorValue ");
- lcd.println(sensorValue);
- if (sensorValue > THRESHOLD_VALUE)
- {
- digitalWrite(DPinLed, HIGH);
- delay(2000);
- }
- digitalWrite(DPinLed, LOW);
- }
复制代码
|