Thursday, December 8, 2016

Final Project: Motion Detection

Motion detection played a big part in my last gesture, and I wanted to include it in my final as well. However, instead of it being "Motion detected = move, no motion = stay still," I wanted the motor linked to the motion detector to spin faster the longer it detected motion.

My code for it looks like this:

 if (cam.motionDetected()) {
   Serial.println("Motion!");
   cam.setMotionDetect(false);
   digitalWrite(motionLED, HIGH);
   if (motorSpeed < 255) {
   motorSpeed++;
   }
   delay(200);
   cam.resumeVideo();
   cam.setMotionDetect(true);
 } else if (! cam.motionDetected()) {
   Serial.println("Still.");
   digitalWrite(motionLED, LOW);
   //analogWrite(motionMotor, 0);
   delay(200);
   if (motorSpeed > 29) {
    motorSpeed--;
   }
   if (motorSpeed == 30) {
    motorSpeed = 0;
   }
 } else {
   //analogWrite(motionMotor, 0);
   //motorSpeed = 0;
 }

Demonstration

The motionLED is the blue LED; I included it because sometimes the motion detector doesn't work; I can't quite figure out when it won't.

For each moment it detects motion, it increments speed by one:


No comments:

Post a Comment