Reader small image

You're reading from  Arduino By Example

Product typeBook
Published inSep 2015
Reading LevelIntermediate
Publisher
ISBN-139781785289088
Edition1st Edition
Languages
Tools
Right arrow
Authors (2):
 Adith Jagadish Boloor
Adith Jagadish Boloor
author image
Adith Jagadish Boloor

Adith Jagadish Boloor was born in Mangalore, India. He grew up tinkering with toys and gadgets that kindled his interest in how things work. His admiration for science and technology, specifically in the fields of robotics, 3D printing, and smart systems, grew into a passion that he is working towards, nurturing it into a career. He completed his higher studies at Purdue University, USA and Shanghai Jiao Tong University, China and is working towards obtaining a masters degree in robotics. Adith has experience working on robots ranging from simple obstacle—avoiding robots built at home to complex humanoid robots such as the Darwin-OP in Purdue University's research lab. He has coauthored a research paper and has two patents on his name. He enjoys traveling and grabs every opportunity he can to explore the different parts of the world. He is also an international chess player.
Read more about Adith Jagadish Boloor

Adith Jagdish Boloor
Adith Jagdish Boloor
author image
Adith Jagdish Boloor

<p>Adith Jagadish Boloor was born in Mangalore, India. He grew up tinkering with toys and gadgets that kindled his interest in how things work. His admiration for science and technology, specifically in the fields of robotics, 3D printing, and smart systems, grew into a passion that he is working towards, nurturing it into a career. He completed his higher studies at Purdue University, USA and Shanghai Jiao Tong University, China and is working towards obtaining a masters degree in robotics.</p> <p>Adith has experience working on robots ranging from simple obstacle—avoiding robots built at home to complex humanoid robots such as the Darwin-OP in Purdue University's research lab. He has coauthored a research paper and has two patents on his name.</p> <p>He enjoys traveling and grabs every opportunity he can to explore the different parts of the world. He is also an international chess player.</p>
Read more about Adith Jagdish Boloor

View More author details
Right arrow

Chapter 5. Burglar Alarm – Part 2

This is part 2 (and the final part) of the burglar alarm series. So far, we have configured the camera, the Bluetooth, and Python.

In this chapter, we will be going through the following topics:

  • Obtaining and processing the image of the intruder

  • Uploading the image to a convenient website

  • Sending the URL to your smart phone

So, shall we get right to it?

Dealing with the image


As discussed before, when Arduino sends a message to Python, it is going to take a snapshot using the camera and save it to the computer. What do we do with it, then? How do we upload it to a file sharing platform? There are several ways to do this, but in this chapter, we will be using Imgur. Yes, the same Imgur that you have been using, knowingly or unknowingly, on Reddit or 9gag.

Go to http://imgur.com/ and sign up for a new account.

Once you have verified your account, go to https://api.imgur.com/oauth2/addclient to add a new application so that Imgur permits you to post images using a script. Use the following information:

  • Application name: Arduino burglar alarm

  • Authorization type: OAuth 2 authorization without callback URL

  • Email: <your email>

  • Description: Using Arduino to catch the cookie thieves

Now proceed, and you will get a page like this:

Imgur will give you the Client ID and Client secret. Save them in a safe location as we will need them later.

Let us...

Sending a notification to a smart device


There are many ways a notification can be sent to your smart device (e-mail, SMS, or via an app). During the course of writing this chapter, I realized that an e-mail is not the most efficient way to alert the user of an emergency (a burglar in this case), and there is no single global SMS notification service that can be used by people from different parts of the world. Hence, we are going to use yet another really powerful push messaging app called Pushover.

It works by communicating over the Internet, and conveniently there is a Python library associated with it that we will use to send notifications to the Pushover app on our smart device.

Go to https://pushover.net/login and create a new account. By default, you get a 7-day trial, which is sufficient for completing this chapter. If you like the software, you can go ahead and purchase it, as you can use it for future projects.

Once you have verified your e-mail ID, look up Pushover on the iTunes...

Putting the pieces together


Go ahead and create this circuit for Arduino:

The connections are as follows:

  • PIR → Arduino

  • GND → GND

  • OUT → D02

  • VCC → 5V

  • HC-06 → Arduino

  • VCC → 3.3V

  • GND → GND

  • TXD → D10

  • RXD → D11

Don't get mad, but there is one last library that you need to install in order to allow Arduino to communicate with Python: pySerial. Go to https://pypi.python.org/pypi/pyserial, download pyserial-2.7.win32.exe, and install it just like you install any other software. Then, we are ready.

Open Arduino and load the alarm_bluetooth.ino file that came with this chapter. It is recommended that you have the most up-to-date Arduino software before proceeding:

#include <SoftwareSerial.h> // serial library used for communication

SoftwareSerial burg_alarm(10, 11); // communicates via TX, RX at 10, 11 respectively
int ledPin = 13; // in built LED to show status changes
int pirPIN = 2;   // signal of the PIR sensor goes to pin 2
int pirState = LOW; // initiate the PIR status to LOW (no motion)
int pirVal...

Summary


This was a long project, wasn't it? However, it is truly worth the end product, as well as the knowledge gained from each element that went together, mainly, Arduino, Bluetooth, and Python. Sometimes, instead of wasting time creating something completely from scratch, it is often a good idea to use what already exists and tweak it to do what we want. We did this for Imgur and Pushover, both very powerful tools. I hope you enjoyed and had a lot to take away from this chapter.

In the next chapter, we will take networking to a whole new level by creating a master remote for your entire home. Yes, you've guessed it – home automation.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Arduino By Example
Published in: Sep 2015Publisher: ISBN-13: 9781785289088
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Adith Jagadish Boloor

Adith Jagadish Boloor was born in Mangalore, India. He grew up tinkering with toys and gadgets that kindled his interest in how things work. His admiration for science and technology, specifically in the fields of robotics, 3D printing, and smart systems, grew into a passion that he is working towards, nurturing it into a career. He completed his higher studies at Purdue University, USA and Shanghai Jiao Tong University, China and is working towards obtaining a masters degree in robotics. Adith has experience working on robots ranging from simple obstacle—avoiding robots built at home to complex humanoid robots such as the Darwin-OP in Purdue University's research lab. He has coauthored a research paper and has two patents on his name. He enjoys traveling and grabs every opportunity he can to explore the different parts of the world. He is also an international chess player.
Read more about Adith Jagadish Boloor

author image
Adith Jagdish Boloor

<p>Adith Jagadish Boloor was born in Mangalore, India. He grew up tinkering with toys and gadgets that kindled his interest in how things work. His admiration for science and technology, specifically in the fields of robotics, 3D printing, and smart systems, grew into a passion that he is working towards, nurturing it into a career. He completed his higher studies at Purdue University, USA and Shanghai Jiao Tong University, China and is working towards obtaining a masters degree in robotics.</p> <p>Adith has experience working on robots ranging from simple obstacle—avoiding robots built at home to complex humanoid robots such as the Darwin-OP in Purdue University's research lab. He has coauthored a research paper and has two patents on his name.</p> <p>He enjoys traveling and grabs every opportunity he can to explore the different parts of the world. He is also an international chess player.</p>
Read more about Adith Jagdish Boloor