O'Reilly logo

Internet of Things Programming with JavaScript by Ruben Oliva Ramos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting motion with the serial TTL camera

Turn on the motion detection of TTL camera:

  cam.setMotionDetect(true); 

Verify if the motion is activated:

  Serial.print("Motion detection is "); 
  if (cam.getMotionDetect())  
    Serial.println("ON"); 
  else  
    Serial.println("OFF"); 
} 

What happens when motion is detected by the camera:

if (cam.motionDetected()) { 
   Serial.println("Motion!");    
   cam.setMotionDetect(false); 

If motion is detected, take the picture or display the message:

  if (! cam.takePicture())  
    Serial.println("Failed to snap!"); 
  else  
    Serial.println("Picture taken!"); 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required