Hi guys in my project of domotic, i need of this:
i have a sensor of light and pir sensor, when the brightness value exceeds a certain limit (means light is ON), start a countdown (10000 millis), if the sensor pir is LOW for 10 second set a pin LOW, if sensor pir is HIGH, reset countdown. how would you do?
void setup() {
pinMode(PINLED, OUTPUT); //LED
pinMode(PINPIR, INPUT); // PIR
timer.setInterval(1000L, sendSensor);
}
void sendSensor() {
int pir = digitalRead(PIRPIN); // pir cabina
int pinlight = analogRead(PINLIGHT); // sensor light
if (pinlight > 100) {
// start countdown 10000 millis
if (pir == HIGH) {
//reset countdown
}
else if (countdown==0) {
offled()
}
}
void offled() {
digitalWrite(PINLED, LOW)
}
void loop()
{
Blynk.run();
timer.run();
}
I hope is clear