BakeBit - Sound Sensor

From FriendlyELEC WiKi
Revision as of 15:39, 14 December 2016 by Yftan (Talk | contribs) (特性)

Jump to: navigation, search

查看中文

1 Introduction

Sound Sensor
  • The BakeBit - Sound Sensor is a sound detection module. The module contains an electret condenser microphone. Sound waves impinging on the diaphragm cause the capacitance between it and the back plate to change synchronously, this in turn induces an AC voltage on the back plate, which is amplified with LM358 as output.
  • Its default output is high. When it detects a sound wave it will output low. When no sounds are detected it will output high.

2 Hardware Spec

  • Standard 2.0mm 4-Pin BakeBit Interface

BakeBit - Sound Sensor

  • Pin Description:
Pin Description
GND Ground
5V 5V Supply Voltage
NC Not Connected
SIG Signal

3 示例程序:Sound Sensor

这个示例用Sound Sensor实现一个声控开关,当检测到环境声音达到指定的分贝时,点亮LED。

3.1 硬件连接

简单的将 Sound Sensor 模块插入 A0 接口,将 LED 插入 D5 接口,如下面这样:

Sound Sensor-1.jpg Sound Sensor-2.jpg

3.2 示例源代码

import time
import bakebit
 
# Connect the BakeBit Sound Sensor to analog port A0
# SIG,NC,VCC,GND
sound_sensor = 0
 
# Connect the BakeBit LED to digital port D5
# SIG,NC,VCC,GND
led = 5
 
bakebit.pinMode(sound_sensor,"INPUT")
bakebit.pinMode(led,"OUTPUT")
 
# The threshold to turn the led on 400.00 * 5 / 1024 = 1.95v
threshold_value = 400
 
while True:
    try:
        # Read the sound level
        sensor_value = bakebit.analogRead(sound_sensor)
 
        # If loud, illuminate LED, otherwise dim
        if sensor_value > threshold_value:
            bakebit.digitalWrite(led,1)
        else:
            bakebit.digitalWrite(led,0)
 
        print("sensor_value = %d" %sensor_value)
        time.sleep(.2)
 
    except IOError:
        print ("Error")

Github


3.3 运行示例

假设你已经参考bakebit教程安装了BakeBit源代码,
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_sound_sensor.py:

cd ~/BakeBit/Software/Python
sudo python bakebit_sound_sensor.py

3.4 运行结果

对着声音传感器制造点声音,例如拍打手掌,LED将被亮起。

4 相关资料