Automation Arduino自动照明系统故障代码。PIR、LDR、RTC、LED
事先谢谢你的帮助! 我正在尝试制作一个自动照明系统,在特定的时间范围内,在黑暗中照亮运动 使用的部件包括:Automation Arduino自动照明系统故障代码。PIR、LDR、RTC、LED,automation,arduino,Automation,Arduino,事先谢谢你的帮助! 我正在尝试制作一个自动照明系统,在特定的时间范围内,在黑暗中照亮运动 使用的部件包括: Arduino Clone Pro Mini 5V Atmega328 AM312 PIR传感器 DS3231 RTC分接板,带3v电池 5819 LDR(光刻胶),带10k 1/4电阻器 2n2222晶体管,带10k电阻器 3个带1欧姆电阻器的白色LED 1个9V电池 我测试并校准了所有传感器和电子设备。除了我上传以下代码外,一切正常: #include "RTClib.h" RT
- Arduino Clone Pro Mini 5V Atmega328李>
- AM312 PIR传感器李>
- DS3231 RTC分接板,带3v电池李>
- 5819 LDR(光刻胶),带10k 1/4电阻器李>
- 2n2222晶体管,带10k电阻器李>
- 3个带1欧姆电阻器的白色LED李>
- 1个9V电池李>
#include "RTClib.h"
RTC_DS3231 rtc;
const int ldrPin = A1; // Photoresistor Input Pin
const int pirPin = 4; // AM312 Motion Sensor Input Pin
const int ledPin = 13; // 3 white LEDs Ouput Pin
int ldrValue = 0; // Initial Value for the LDR
int pirState = LOW; // Initial State for the PIR
int pirValue = 0; // Initial Value for the PIR
void setup() {
Serial.begin(9600); // Starting Serial Monitor
// This is required by RTC DS3231 BreakOut Board
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
pinMode(ledPin, OUTPUT); // Sends signal to Transistor to Light 3 white LEDs
pinMode(ldrPin, INPUT); // Signals to Arduino if there is any lights
pinMode(pirPin, INPUT); // SIgnals to Arduino if there is any movement
}
void loop() {
DateTime now = rtc.now(); // Starts RTC
if ((now.hour() >= 6 && now.minute() >= 00) && (now.hour() <= 19 && now.minute() <= 59)) { // IF the time NOW is between 6:00(am) and 7:59(pm) then...
digitalWrite(ledPin, LOW); // ... keep the LEDs OFF
} else {
pirValue = digitalRead(pirState); // Scan for any movement
ldrValue = analogRead(ldrPin); // Scan for any lights
if (pirValue == HIGH) { // IF there is any movement
if (ldrValue <= 400) { // IF there is NO lights
digitalWrite(ledPin, HIGH); // Turn the LEDs ON
delay(120000); // Wait 2 mins
}
}
}
}
我也试着从delay改为millis(),但我也遇到了同样的问题。我怀疑代码有问题,我请求您帮助我找出哪里出错。
非常感谢您抽出时间
pirValue=digitalRead(pirState)代码>看起来不对。这基本上就是digitalRead(低)
。真的!我将更改为pirPin,看看会发生什么由于您的观察,我已将代码更改为:pirState=digitalRead(pirPin);//扫描任何移动ldrValue=analogRead(ldrPin);//如果(pirState==HIGH){//如果(ldrValue)有任何移动,则扫描所有灯光。如果(ldrValue)运行得很好,现在我只需要添加计时(millis())并设置好im。非常感谢
if (pirState == HIGH) {
Serial.println("Motion Detected");
}