Motion sensor increase Time high status via software
-
I have this for lighting and it is so easy.....
Set trigger (as you said) to minimum value on pir.
Then in code detect motion (use arduino uno pin 2 or 3 as interrupt). Then simply put a wait(time-in-milliseconds) after that.
Here is my example....
void loop() { //sendHeartbeat(); // Read digital motion value bool tripped = digitalRead(DIGITAL_INPUT_SENSOR); // send(msg.set(tripped?"1":"0"),true); // Send tripped value to gw if (tripped == HIGH){ send(msg.set(tripped = 0),true); } while(tripped == HIGH){ tripped = digitalRead(DIGITAL_INPUT_SENSOR); wait(5000); } send(msg.set(tripped = 1),true); // Sleep until interrupt on motion sensor. Send update every ten minutes. sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); }Just change wait(5000) to wait(10000).
-
I had thought of WAIT or rather DELAY, but the sketch is more complex than just the motion sensor, and using DELAY is not correct because it would block the execution of the code.
But can't I find other solutions ??? -
You should better use async coding, it won't block like wait() ;)
I did that for some old avr+analog pir nodes (custom pir state machine).So you simply need to use millis() + async coding. Below an example which explains how to blink a led without using any delay.
https://www.arduino.cc/en/Tutorial/BlinkWithoutDelayBy doing this way, your loop will never be blocked, and will run multiple times as you wish.
So you'll need to use some vars to store time/durations. And some booleans for your pir states, time to sleep node etc. -
I had thought of WAIT or rather DELAY, but the sketch is more complex than just the motion sensor, and using DELAY is not correct because it would block the execution of the code.
But can't I find other solutions ???I never said use 'DELAY'.
My code does not use 'DELAY'.
'WAIT' and 'DELAY' are not the same thing.
-
@scalz said in Motion sensor increase Time high status via software:
o non verrà mai bloccato e verrà eseguito più volte come desideri.
Quindi dovrai usare alcune vars per memorizzare tempo / durata. E alcuni bWe know Millis, it's already been used several times, but what I can't solve is the code, I can't process the code !!
-
I never said use 'DELAY'.
My code does not use 'DELAY'.
'WAIT' and 'DELAY' are not the same thing.
-
@sindrome73 MySensors' wait() is different from Arduino's delay(). See https://www.mysensors.org/download/sensor_api_20#waiting
-
I never said use 'DELAY'.
My code does not use 'DELAY'.
'WAIT' and 'DELAY' are not the same thing.
-
@electrik Since you haven't bothered to even post your full code, how is anyone to know what you want to do?
You asked a specific question and I tried to help without knowing anything about your hardware, code or desired operation.
@skywatch said in Motion sensor increase Time high status via software:
ti sei
Hello and sorry, if I gave the idea of being courteous !! sorry again
I didn't publish the code because I really don't know where to start, but now that I understand WAIT, that in MySensors and a separate thing, I also understand your example, and I thank you for helping me !!
But then again I didn't know that this WAIT, was something different from DELAY
I answer little, because I'm a little busy these days ..... But anyway for now thanks again for help