Arduino开发之Infrared Motion Sensor

xiaoxiao2021-02-28  111

环境搭建: 1. Arduino UNO R3开发板, 2. Arduino IDE。 我这里使用的是1.8.3。可以在 https://www.arduino.cc/en/Main/Software下载并安装。 安装好之后,桌面会有如下图标。 示例开发: 1.连接设备。 本例中我们以Infrared Motion Sensor(SEN0018)并结合DFR0021-R为例,基于Arduino Uno R3和Arduino IDE开发。 DFR0021-R的引脚和Arduino Uno开发板的连接方式如下, DFR0021-RSEN0018Arduino Uno R3VCCVCC3.3VGNDGNDGND信号引脚信号引脚DFR0021接数字引脚13,SEN0018接数字引脚3 2. 编码。 连接好之后,用数据线连接Arduino开发板和电脑。同时打开Arduino IDE。输入下述代码。 const int buttonPin = 3; // motion sensor const int ledPin = 13; // led pin int buttonState = 0; // variable for reading the pushbutton status void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); Serial.begin(9600); // use the serial port } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); Serial.println("High"); } else { digitalWrite(ledPin, LOW); Serial.println("Low"); } } 然后保存文件。 选择Arduino Uno开发板。 编译上传大到开发板。 3.运行。 选择COM口信息, 然后选择端口监视工具,查看程序运行信息。 串口监视信息, 上面的数据就是Red LED 返回当前状态(High表示开,Low表示关)。 整体运行界面: 实际效果图:
转载请注明原文地址: https://www.6miu.com/read-32936.html

最新回复(0)