Arduino 我的Led灯不亮';即使我在digitalWrite(ledpin,低)之后增加了延迟,也不会增加其正常运行时间;
所以我有一个PIR运动传感器和一个led。一旦检测到运动,led将点亮。灯亮了,但led的正常运行时间只有5秒。我想增加5,这样当检测到运动时,正常运行时间将为10秒 我已经添加了延迟(5000);数字写入后(ledpin,低电平);在led熄灭前增加5秒延迟,但仍然是5秒而不是10秒Arduino 我的Led灯不亮';即使我在digitalWrite(ledpin,低)之后增加了延迟,也不会增加其正常运行时间;,arduino,Arduino,所以我有一个PIR运动传感器和一个led。一旦检测到运动,led将点亮。灯亮了,但led的正常运行时间只有5秒。我想增加5,这样当检测到运动时,正常运行时间将为10秒 我已经添加了延迟(5000);数字写入后(ledpin,低电平);在led熄灭前增加5秒延迟,但仍然是5秒而不是10秒 //the time we give the sensor to calibrate (10-60 secs according to the datasheet) int calibrationTime =
//the time we give the sensor to calibrate (10-60 secs according to the
datasheet)
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 10000;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 10; //the digital pin connected to the PIR sensor's output
int ledPin = 13;
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
//LOOP
void loop(){
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
///////////////I added delay below by 5 seconds but nothing changed
delay(5000);
if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}
//我们给传感器标定的时间(根据
(数据表)
int校准时间=30;
//传感器输出低脉冲的时间
长无符号整数低维;
//传感器的毫秒数必须很低
//在我们假设所有运动都停止之前
长无符号整数暂停=10000;
布尔lockLow=true;
布尔时间;
int-pirPin=10//连接到PIR传感器输出的数字引脚
int-ledPin=13;
//设置
无效设置(){
Serial.begin(9600);
pinMode(pirPin,输入);
引脚模式(LED引脚,输出);
数字写入(pirPin,低位);
//给传感器一些时间进行校准
串行打印(“校准传感器”);
对于(int i=0;ipause){
//确保此代码块仅在
//检测到一个新的运动序列
lockLow=真;
Serial.print(“运动结束于”);//输出
串行打印((毫秒()-暂停)/1000);
序列号。打印号(“sec”);
延迟(50);
}
}
}
您需要在关闭LED之前设置延迟时间。已经尝试过,但没有成功。您将延迟时间设置在哪里?你有什么错误吗?此外,由于您声明您的LED亮起5秒,但我找不到任何延迟或计时器,因此我假设在检测运动时,您的PIR每次亮起5秒。你能证实这一点吗?当我照你说的做的时候,发生的是,是的,它增加了5秒,在led关闭之前变成了10秒。但在它关闭后,当我试图在pir传感器前做一个动作时,我还需要等待10秒,然后它再次亮起,将延迟置于Serial.print(“在检测到的动作”)之后;串行打印(毫秒()/1000);序列号。打印号(“sec”)代码>希望有帮助!