Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

MengFanjun的博客

一、电路接线

声音传感器

声音传感器引脚 Arduino引脚
VCC 5V
GND GND
OUT 6

LED

LED引脚 Arduino引脚
正极 8
GND GND

二、代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int val;
int ledpin=8;
int voicepin=6;
void setup()
{
Serial.begin(9600);
pinMode(voicepin,INPUT);
pinMode(ledpin,OUTPUT);
}

void loop()
{
val = digitalRead(voicepin);
Serial.println(val);
delay(500);
digitalWrite(ledpin,HIGH);
if (val == LOW) // no voice
{
digitalWrite(ledpin,LOW); // clear led
} else {
digitalWrite(ledpin,HIGH); // set led
}
}

如果没声音LED不亮 如果有声音LED亮

评论