O'Reilly logo

Raspberry Pi Sensors by Rushi Gajjar

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

Create a motion detector

We have already set up a piece of software called motion. It detects and captures motion, but that's not fun at all compared to building our own code to capture motion. We will create code that will detect motion and take a decision according to the extent of motion. We will trigger an LED to indicate the decision taken by the RasPi. This code is going to be a bit long, so the explanation is given in comments within the code. However, important information is provided just after the end of the code:

#include <iostream> #include <cv.h> #include <highgui.h> #include <stdio.h> #include <cctype> #include <iterator> #include <unistd.h> #include <wiringPi.h> #include "opencv2/highgui/highgui.hpp" #include <time.h> using namespace ...

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