本站改版新增arduino频道
arduino 对射光电传感器 红外对射计数传感器
// 定义红外人体感应模块的信号引脚
const int motionSensorPin = 7;
void setup() {
// 开启串口通信
Serial.begin(9600);
// 设置红外人体感应模块的引脚为输入
pinMode(motionSensorPin, INPUT);
}
void loop() {
// 读取红外人体感应模块的输出信号
int motionDetected = digitalRead(motionSensorPin);
// 打印检测结果
if (motionDetected == HIGH) {
Serial.println("未检测到人体运动。");
} else {
Serial.println("检测到人体运动!");
}
// 等待一段时间
delay(500);
}
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0093021392822266 seconds