声控灯程序
音量传感器接口
4.1 RJ25 接口
当使用RJ25接口时,请链接到有黄色标识的 Makeblock主控 板(Meduino+Base Shield, Me Baseboard, Makeblock Orion, etc )的接口上。以Me baseboard1.1版的主板为例,可以链接 到3,6,7,8 号接口,如图:
音量传感器 方程功能介绍:从声音传感器读取测量结果,将结果输出到Arduino IDE Serial Monitor, 周期为100ms。 上传代码到Makeblock主板点击Arduino Serial Monitor , 将看到运行结果如下
安静的形况下读书为 130~135, 有声时范围为 230~600. 声响越大, 数值越高.
音量传感器的参数
•l 运行电压: 5V DC;
•l 信号类型: 模拟信号 (0.2V~3V); •l 尺寸: 52 x 24 x 17 mm (长x宽x高);
音量传感器的特性
•l 支持Arduino IDE, 并且我们提供了运行库来简化编程;
•l 支持MBlock,适合全年龄用户; •l 使用RJ25接口连线十分容易; •l 模块化安装,兼容乐高系列; •l 配有DIY接口,支持绝大多数Arduino系列主控板;
编程指南 ArduinoIDE 在 Arduino IDE界面下, 您可以使用此运行库Makeblock-Library-master 来 控制 Me Sound Sensor 如下是控制方程列表:
编程代码 01.#include<Makeblock.h> 02.#include <SoftwareSerial.h> 03.#include<Wire.h> 05.int Sound_Strength= 0; 06.MeSoundSensormySound(PORT_6); 07.void setup() 08.{ 09.// initializeserial communications at 9600 bps 10. Serial.begin(9600); 11.} 12.void loop() 13.{ 14.// read the analogvalues of module: 15. Sound_Strength=mySound.strength(); 17.// print theresults to the serial monitor: 18. Serial.print("Sound Strength: "); 19. Serial.println(Sound_Strength); 20. 21.// wait 100milliseconds before the next loop 22. delay(100); 23.}