Arduino开发之Analog Sound Sensor
来源:互联网 发布:linux改名命令 编辑:程序博客网 时间:2024/06/16 08:13
环境搭建:
1. Arduino UNO R3开发板,
2. Arduino IDE。
我这里使用的是1.8.3。可以在https://www.arduino.cc/en/Main/Software下载并安装。
安装好之后,桌面会有如下图标。
示例开发:
1.连接设备。
本例中我们以Analog Sound Sensor(DFR0034)并结合DFR0021-R为例,基于Arduino Uno R3和Arduino IDE开发。
DFR0021-R的引脚和Arduino Uno开发板的连接方式如下,
DFR0021-R
DFR0034
Arduino Uno R3
VCC
VCC
3.3V
GND
GND
GND
信号引脚
信号引脚
DFR0021接数字引脚13,DFR0034
接模拟引脚A0
2. 编码。
连接好之后,用数据线连接Arduino开发板和电脑。同时打开Arduino IDE。输入下述代码。
int led = 13;
int threshold = 30; //Change This
int volume;
void setup() {
Serial.begin(9600); // For debugging
pinMode(led, OUTPUT);
}
void loop() {
volume = analogRead(A0); // Reads the value from the Analog PIN A0
//Debug mode
Serial.println(volume);
//delay(100);
if(volume>=threshold){
digitalWrite(led, HIGH); //Turn ON Led
Serial.println("LED is ON!");
}
else{
digitalWrite(led, LOW); // Turn OFF Led
Serial.println("LED is OFF!");
}
}
然后保存文件。
选择Arduino Uno开发板。
编译上传大到开发板。
3.运行。
选择COM口信息,
然后选择端口监视工具,查看程序运行信息。
串口监视信息,
上面的数据就是Red LED 返回当前状态(ON表示开,OFF表示关)。此例中,当检测到声音高于20时,LED灯就会亮。
整体运行界面:
实际效果图:
阅读全文
0 0
- Arduino开发之Analog Sound Sensor
- Arduino开发之Analog Linear Temperature Sensor
- Arduino开发之Light Sensor
- Arduino开发之Infrared Motion Sensor
- Arduino开发之GP2Y0A21 Distance Sensor
- Arduino implement pressure sensor
- 37 sensor kit. Arduino
- Android底层开发工作小结Camera, Sound, SD, USB, G-sensor, TP,factory
- Analog
- Arduino开发之Blink LED
- Arduino: Ultrasonic Sensor & Motor Car
- PIR Motion Sensor with Arduino
- iOS 开发 初级:Audio之 System Sound Services的使用
- IOS开发音频播放之System Sound services
- Android开发教程之感应检测Sensor
- 高通平台手机开发之Sensor
- 高通平台手机开发之Sensor
- Arduino开发之Digital Push Button(Red)
- Spring MVC,403,404,500页面
- Spring入门概述(萌新必看)
- BZOJ1087 [SCOI2005]互不侵犯King 状态压缩DP
- HDU
- unix常用命令使用经验
- Arduino开发之Analog Sound Sensor
- springmvc常用注解标签详解
- 通过Ajax的方式上传文件
- linux下的用户管理详解
- sun.misc.BASE64Encoder找不到jar包的解决方法
- 《C和指针》读书笔记(四)
- Pycharm Unresolved reference导入编写py文件报错
- android电量优化
- struts2架构中核心对象的探索—— ActionContext和ServletActionContext