Introduction: Motion Activated Security Camera Using Intel Edison

The goal of this project is to make a security camera which is turned on by a motion senor. A Passive Infra-Red (PIR) motion sensor continuously monitors for any motion in its field of view. When a motion is detected it causes a USB camera to capture an image. This picture is sent to the user's email over WiFi using Intel Edison’s integrated WiFi module. This security system is suitable for both residential and commercial security systems.


Components required:

  • Edison with Arduino expansion board and external power supply
  • 2 Micro B to Type A USB cables
  • PIR Motion Sensor
  • 3 female-to-male jumper wires to connect the PIR motion sensor to Edison Arduino ports
  • 1 USB Camera (Logitech HD Webcam C270)

Step 1: Getting Started With Intel Edison

You can follow the instructions given here to set-up your Edison Board. This site gives a good overview of assembling the Edison board and explains the basic cable connections (Power supply, USB).

Step 2: Installing Intel Edison Board Drivers and Flashing Firmware

Intel Edison's firmware is usually updated weekly. So, it is a good idea to update the firmware to ensure you face fewer firmware bugs.

To update the Edison firmware to the latest version, go to Intel® Edison Board Installer and select appropriate operating system to download the IOT Design Kit installer. Open the Installer and it will take you through the steps to update Edison drivers and firmware. It also allows you to install IDE of your choice for programming Edison. You can choose from Arduino IDE for Edison, Intel XDK IoT Edition, Eclipse. For this project, we did not use any of these IDEs. The code is written in node.js in a text editor like vi and run on Edison terminal through SSH.

In case you prefer to update firmware manually, or the Intel Edison Board Installer did not work as expected for you, you can follow the instructions from here to manually install drivers and update the firmware http://www.intel.com/support/edison/sb/CS-035286.h...

When nothing works and you cannot see your Edison drive on Windows Explorer, use the instructions from https://communities.intel.com/message/284785#284785 to flash Edison. And then follow the steps for manually updating the firmware.

Step 3: Setup Edison WiFi

Step 4: Connect the PIR Motion Sensor to Edison

We are going to use GPIO pin 6 on Edison Arduino expansion board to connect the output of the PIR sensor. The VCC of the sensor is connected to 5V on arduino expansion board and GND of the sensor is connected to the GND of the board. Please refer to the image above to make sure you have the right connections.

Step 5: Install NodeMailer

We started with the instructable Intel Edison Intruder Alarm by A_Steingrube and improved upon it to send picture taken by the Logitech USB camera as an email attachment. We will need NodeMailer to send emails.

  • To install Node Package Manager and NodeMailer package on your edison using the following commands.
curl  https://www.npmjs.org/install.sh  | sh
npm install nodemailer

Step 6: Copying Your Code to the Edison Root Directory

You can edit your code in Windows and then copy the file to the Edison drive. Then you can copy this file to the Edison's root directory from where the code is run.

  • After you copied over the securitycamera_instructable.js to the Edison drive, mount Edison from the terminal.
rmmod g_multi
mkdir /update
losetup -o 8192 /dev/loop0 /dev/disk/by-partlabel/update
mount /dev/loop0 /update
  • Then copy the file to the root directory.
cp /update/securityCamera_instructable.js /home/root/
  • Finally unmount your Edison.
cd /
umount /update
modprobe g_multi
  • After you unmounted the Edison storage directory, go back to your root directory
cd /home/root/

Step 7: Install Logitech C270 USB Camera Drivers on Edison

The Logitech C270 Webcam is UVC compliant. We need to install UVC drivers on Edison to use this. To do this,

  • First make sure power supply is plugged into the Edison.
  • Plug the webcam into the large USB port next to the power jack.
  • Make sure the microswitch, show in the pictures above, is switched towards the large USB port.
  • After plugging the webcam to USB port, there should be a /dev/video0 dev node when the UVC driver is working properly.
  • To check it, from your root directory type the following
ls -l /dev/video0
  • You should see the video file as below
crw-rw----    1 root     video      81,   0 Jul 22 20:32 /dev/video0
  • If you don’t have the proper USB webcam enabled Edison image or your USB camera is not plugged in, then you will get message like this
ls: /dev/video0: No such file or directory
    To start using the webcam to take pictures, download the latest release binary from Edison terminal.
wget http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-32bit-static.tar.xz
tar xf ffmpeg-release-32bit-static.tar.xz
cd ffmpeg-2.7.2-32bit-static/
  • To capture a still image, use the following command from Edison terminal.
./ffmpeg -s 320x240 -f video4linux2 -i /dev/video0 -vframes 1 image.jpeg

Step 8: Run the Javascript Code

  • To run the security camera module on your Edison, use the embedded code and modify it to update the email address and password.
//Print console message to start the camera
process.stdout.write("Begin security camera");

//Set-up GPIO pin 6 
var mraa = require('mraa');
var motionSensor = new mraa.Gpio(6);
motionSensor.dir(mraa.DIR_IN);

//Set up email information using node mailer
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport({
	service: "Gmail",
	auth: {
		user: "EdisonCam@email.com",
		pass: "EdisonCamPassword"
	}
});

//command line execution function used to activate USB camera from command line later in the code
function run_cmd(cmd, args, callBack ) {
    var spawn = require('child_process').spawn;
    var child = spawn(cmd, args);
    var resp = "";

    child.stdout.on('data', function (buffer) { resp += buffer.toString() });
    child.stdout.on('end', function() { callBack (resp) });
} // ()


//Start motion sensor!
periodicActivity();

function periodicActivity()
{
	//Read the motion sensor activity
	var motionSensorTriggered = motionSensor.read();
	//Image Number
    var i = 0;
    //Send email if the motion sensor is HIGH
	if(motionSensorTriggered){
		//Print activity detected message
		process.stdout.write("Motion sensor detected");
    	//Remove previously captured picture
		run_cmd( "rm", ['-f', '/home/root/intruder_image.jpeg'], function(text) { console.log (text) }); 
		//Take a picture from the USB camera - from command line
		run_cmd( "/home/root/ffmpeg-2.7.2-32bit-static/ffmpeg", ['-s', '1280x720', '-f', 'video4linux2', '-i', '/dev/video0', '-vframes', '1', 'intruder_image.jpeg'], function(text) { console.log (text) });
		//Print done message
		console.log("\nDone with taking the picture");
		//Send our email message with picture attachment
		smtpTransport.sendMail({
			from: "EdisonCam ",
			to: "User Name ",
			subject: "Possible Intruder Alert",
			text: "A possible intruder is detected on your EdisonCam! Check the picture attached to see if you know this person. Please call 911 if you suspect any illegal activity.",
                        attachments:[
      			{
				filename: 'intruder_image.jpeg',
				path: '/home/root/intruder_image.jpeg'				
	   			}
			]
		}, function(error, response){ //Send a report of the message to the console
			if(error){
				console.log(error);
			}else{
				console.log("Message sent: " + response.message);
			}
			smtpTransport.close();
		});
		process.stdout.write("Message sent");
//		}	
		//To avoid flooding of the user's Inbox with our emails, we want to wait a few seconds
		//(in this case, 30 seconds) before sending another email. The timeout
		//is in milliseconds.  So, for 1 minute, you would use 60000.
		setTimeout(periodicActivity, 30000);
	
	}else{ 
		//The motion sensor wasn't triggered, so we don't need to wait as long.
		// 1/10 of a second seems about right and allows Edison to do other
		// things in the background.
		setTimeout(periodicActivity, 100);
	}
} 
  • And then cd into your root directory and use the following command to execute the javascript.
cd /home/root/
node securityCamera_instructable.js
  • Tada! you should receive an email as shown in the picture!

If you are using Gmail for your demo, you might see that the emails from your Edison are blocked after sending 100-150 emails. That is because Gmail limits the number of emails you can send in a day. We used Yahoomail to get around this issue at the Austin Mini Maker Faire 2015. Yahoomail allows you to send ~100 emails every hour. Alternatively, you can set-up your own email client to get around this issue. Also, you can decrease the email frequency in your code by adjusting the following line

setTimeout(periodicActivity, 30000);

But this also requires the user to be more patient to see the email output.

Comments

author
IoTtony (author)2016-01-20

I'd be interested to do this using the Edison Mini-Board. Has anyone used the mini board for this or know what the wiring changes need to be?

author
amberrayh (author)2015-07-23

Great job on this Instructable! It is very easy to follow. Thank you for sharing!

About This Instructable

5,702views

23favorites

License:

More by mallani:Motion Activated Security Camera using Intel Edison
Add instructable to: