Hi, I am doing a project for the school and I cannot figure out how to program a software. Basically, I need a PIR motion sensor to detect movement first, but not activate the DC motor yet, it has to start a timer and after a certain amount of time (let's say 15 seconds) check again if it still detects a motion. If yes, then reset the timer and keep the motor LOW, if it doesn't detect any motion, then the motor has to activate for a second and then stop.
If any further explanation of the project is needed, I can provide it.
Reading a PIR sensor is trivial. Turning a pin on when motion is detected is trivial. Waiting to see if the motion detected state is still true 15 seconds later is not hard.
I already did most of the stuff, I did my hardware part and tried really hard on working with software, but no matter how hard i tried, it did not go anywhere.
this is a sample of my code
const int CW = 7; //clockwise
const int CCW = 8; //counter clockwise
const int pirPower = 13; //Motion detector power supply pin
const int pirIn = 12; //Motion detector input pin
boolean pirDetected = false;
unsigned long motionTime;
int interval = 15000;
int previousMillis = 1;
In the piece of code, I wanted to start a timer to check the motion later on in the code. I expected while loop to only activate when the value is HIGH, but when it is LOW, I expected it to do the other part of the coding. Other way, I am not certain how to do it.
wretchetry:
In the piece of code, I wanted to start a timer to check the motion later on in the code. I expected while loop to only activate when the value is HIGH, but when it is LOW, I expected it to do the other part of the coding. Other way, I am not certain how to do it.
It does something. Feel free to share your observations and your definition of "work".
The time that motion starts is NOT when the pin is HIGH. It is when the pin is HIGH now but was not HIGH last time. Look at the state change detection example.
By clearing the time in motionStarted when motion is no longer detected, that stops the body of the statement from being executed even though motion started long ago.
As soon as i addeed the code, the mechanics started working just as i expected, the only problem i've ecnountered is that the motor keeps on spinning, while i need it to only spin for one second, how can i fix that?
wretchetry:
As soon as i addeed the code, the mechanics started working just as i expected, the only problem i've ecnountered is that the motor keeps on spinning, while i need it to only spin for one second, how can i fix that?