PiR triggers the gear motor to move forward 0-60 seconds - stop
PiR triggers the gear motor to move in reverse 0-60 seconds - stop
0-60 second pause between each trigger.
Essentially, the PiR loops the motor back & forth, (forward-reverse) after each trigger.
enum State {
STOPPED,
MOVING,
WAITING
} state = STOPPED;
boolean directionForward = true;
uint32_t moveStartMs;
void setup() {
// put stuff here to set up the PIR and motor
}
void loop() {
switch (state) {
case STOPPED:
if(pirDetected()) {
if(directionForward) {
startMotorForward();
}
else {
startMotorReverse();
}
}
moveStartMs = millis();
state = MOVING;
break;
case MOVING:
if(millis()-moveStartMs >= 60000L) {
stopMotor();
directionForward = !directionForward;
state = WAITING;
}
break;
case WAITING:
if(millis()-moveStartMs >= 120000L) {
state = STOPPED;
}
break;
}
}
boolean pirDetected() {
// you need to write this bit
return false;
}
void startMotorForward() {
// write this bit
}
void startMotorReverse() {
// write this bit
}
void stopMotor() {
// write this bit
}
If the challenge was easy it won't be so challenging. Who said anything about a motor speed..variable. Uhmm....apparently not a project requirement. Asking the right question is part of the challenge.
My point was that you failed to say anything about the speed of the motor.
Uhmm....apparently not a project requirement.
Really? The speed of the motor is not important?
Asking the right question is part of the challenge.
I'm going to pass, then. Asking clarifying questions is one thing. Asking basic "It looks like you failed to say anything about xxxx; is that intentional?" questions should not be necessary.
Bingoo:
Uhmm....apparently not a project requirement.
Apparently? I'm getting the impression that this is a school project. Are you able to tell us what institution you are attending? The lecturer/class name would be handy, too. Oh, and could you let us know your student id number? No need for real names - just the id number should do.