完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我有一个带有 HC-SR501 PIR 的 ESP8266,我已经将其解析到电路板上以进行 3.3v 操作。
当我在上面运行一个非常简单的代码时,它运行得很好。 使用相同的接线设置,以及与之前使用温度传感器的更大程序的一部分相同的代码,它似乎总是在继续阅读? 这是简单的代码和输出。它检测到动作并立即启动。 代码:全选int ledPin = 13; // choose the pin for the LED int inputPin = 4; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare sensor as input Serial.begin(115200); Serial.println(\"Starting up\"); } void loop(){ val = digitalRead(inputPin); // read input value Serial.println((String)\"the value of val is \" +val); if (val == HIGH) // check if the input is HIGH { Serial.println(\"Motion is on\"); if (pirState == LOW) { Serial.println(\"Motion detected!\"); // print on output change pirState = HIGH; } } else { digitalWrite(ledPin, LOW); // turn LED OFF if (pirState == HIGH) { Serial.println(\"Motion ended!\"); // print on output change pirState = LOW; } } } 这是似乎给出错误读取的代码 代码:全选void do_board_function() { // This boards function is to get and send DHT temp/humity to MQTT Serial.println(\"\"); Serial.println(\"Starting Board Functions\"); //////START - TEMP + HUM////// float readt = dht.readTemperature(); delay(2000); float readh = dht.readHumidity(); // Check if any reads failed and exit early (to try again). if (isnan(readt)) { Serial.println(\"Failed to read from DHT sensor!\"); } else { Serial.print(\"Temperature = \"); Serial.print(readt); Serial.print(\" .... \"); Serial.print(\"Humidity = \"); Serial.print(readh); Serial.println(); String temp_strt = String(readt); String hum_strt = String(readh); temp_strt.toCharArray(temp, temp_strt.length() + 1); //packaging up the data to publish to mqtt String temp_strh = String(readh); hum_strt.toCharArray(hum, hum_strt.length() + 1); //packaging up the data to publish to mqtt // String MQTTPublish = String(\"Temperature is\" + t + \"Humidity is\" + h); client.publish(Topic_DataMessagesTemp, temp); client.publish(Topic_DataMessagesHum, hum); //////END - TEMP + HUM////// //New Motion Sensor code val = digitalRead(MOTIONPIN); // read input value Serial.println((String)\"the value of val is \" +val); if (val == HIGH) // check if the input is HIGH { Serial.println(\"Motion is on\"); if (pirState == LOW) { Serial.println(\"Motion detected!\"); // print on output change pirState = HIGH; } } else { if (pirState == HIGH) { Serial.println(\"Motion ended!\"); // print on output change pirState = LOW; } } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
1132 浏览 1 评论
576浏览 6评论
477浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
461浏览 5评论
462浏览 4评论
435浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 15:37 , Processed in 0.908423 second(s), Total 73, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号