anyone can help me ?
how to change delay on my script.
delay pir sensor always crash with ldr sensor.
how to make sensors running simultaneously without waiting delay completion
helpme.ino (1.99 KB)
anyone can help me ?
how to change delay on my script.
delay pir sensor always crash with ldr sensor.
how to make sensors running simultaneously without waiting delay completion
helpme.ino (1.99 KB)
//------------alternative to change delay?-----
//--------------- variabel ldr-------------------
const int Pinled = 8;
int valueLDR;
//--------------- variabel pir-------------------
int ledpir = 13;
const int ReadPir = 2;
unsigned long turnoff; // time to turn off pir led
void setup() {
Serial.begin(9600);
//SET PIN (OUTPUT/INPUT)
//------------------LDR
pinMode(Pinled, OUTPUT); // Set pin 8 -> output led from LDR sensor
pinMode(A0, INPUT); // Set pin A0 -> input [pir]
//------------------------------------
//------------------PIR
pinMode(ledpir, OUTPUT); //------ [led]set pin output for [pir]
pinMode(ReadPir, INPUT); //------ set pin INPUT for [pir]
//------------------------------------
}
void loop()
{
//------------------------------------------------------------------------
valueLDR = analogRead(A0);
if (valueLDR < 100)
digitalWrite(Pinled, HIGH);
else
digitalWrite(Pinled, LOW);
//------------------------------------------------------------------------
if (digitalRead(ReadPir) == HIGH)
{
digitalWrite(ledpir, HIGH);
turnoff = millis() + 10000; // turn it off in ten seconds
}
if (millis() > turnoff) digitalWrite(ledpir, LOW);
//------------------------------------------------------------------------
}
thank you .
it's work.