Reader small image

You're reading from  Arduino for Secret Agents

Product typeBook
Published inNov 2015
Reading LevelIntermediate
Publisher
ISBN-139781783986088
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Marco Schwartz
Marco Schwartz
author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz

Right arrow

Chapter 7. Monitoring Secret Data from Anywhere

In this chapter, we are going to build a project that will continuously record data from sensors, and send this data over Wi-Fi so it's accessible from any web browser. This is great for a secret agent that wants to monitor a room remotely, without being seen. You'll of course be able to adapt the project with your own sensors, depending on what you want to record.

To do so, these are the steps we are going to take in this chapter:

  • We will use Arduino along with the CC3000 Wi-Fi chip, which is quite convenient to give Wi-Fi connectivity to Arduino projects.

  • We will send sensor data to an online service called dweet.io, and then display the result on a dashboard using Freeboard.io.

  • Finally, we'll also see how to set up automated alerts based on the recorded data. Let's dive in!

Hardware and software requirements


First, let's see what the required components are for this project.

We'll of course use an Arduino Uno as the brain of the project. For Wi-Fi connectivity, we are going to use a CC3000 breakout board from Adafruit:

We'll also use a bunch of sensors to illustrate the behavior of the project: a DHT11 sensor for temperature and humidity, a photocell for light levels, and a motion sensor.

Finally, here is a list of all the components that we will use in this project:

On the software side, you need the latest version...

Hardware configuration


Now let's assemble the different components of this project. This is a schematic to help you out:

First, connect the power. Connect the Arduino Uno 5V to the red power rail on the breadboard, and the GND pin to the blue power rail. Also, place all the main components on the breadboard.

After that, for the DHT11 sensor, follow the instructions given by the schematic to connect the sensor to the Arduino board. Make sure you don't forget the 4.7k Ohm resistor between the VCC and signal pins.

We are now going to connect the photocell. Start by placing the photocell on the breadboard in series with the 10k Ohm resistor. After that, connect the other end of the photocell to the red power rail, and the other pin of the resistor to the blue power rail. Finally, connect the pin between the photocell and the resistor to Arduino Uno pin A0.

Finally, for the motion sensor, connect the VCC pin to the red power rail, the GND pin to the blue power rail, and finally the output pin of...

Sending data to dweet.io


The first step in this project is really to send data to the web so it is stored online. For this, we'll use a service called dweet.io. You can check it out at https://dweet.io/.

This is the main welcome page:

This is the complete Arduino code for this project:

// Libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "DHT.h"
#include <avr/wdt.h>

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// DHT sensor
#define DHTPIN 6
#define DHTTYPE DHT11

// Create CC3000 instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed
                                        
// DHT instance
DHT dht(DHTPIN, DHTTYPE);

// WLAN parameters
#define WLAN_SSID       "yourWiFiSSID"
#define WLAN_PASS       "yourWiFiPassword"
#define WLAN_SECURITY...

Monitoring the device remotely


We are now going to see how to access the data stored on dweet.io and display it graphically. For that, we are going to use a website called freeboard.io. You can go there with the following URL http://freeboard.io/.

This is the main welcome screen where you need to create an account:

Once you have an account, you can create a new board:

Once this is done, you should be redirected to a similar page showing an empty board:

First, we need to set a datasource, meaning that we need to tell Freeboard to get data from the dweet thing we are storing the data in. Add a new datasource and fill out the fields as shown in the following screenshot, with the name of the thing that stores your data of course:

After that, you will see the datasource appearing at top of your board, with the last update date:

It's now time to add some graphical elements to our dashboard. We'll first add one for the temperature. Click on a new pane, which will create a new block inside the dashboard...

Creating automated e-mail alerts


There is one more thing we can do with our project. Spying on the data is good, but we are not always behind a computer. For example, we would like to receive an alert via e-mail if motion is detected by the project.

Dweet.io proposes this kind of service, at a very cheap price (less than $1 a month). To do this, you need to make your device private with a lock. This is basically a key you can get from https://dweet.io/locks.

This is the screen where you can buy this key:

Once we have the key, we can actually set our alert. The dweet.io website explains this very well:

To set up an alert, simply go to the following URL by modifying the different parameters with the desired parameters https://dweet.io/alert/youremail@yourdomain.com/when/yourThing/dweet.motion==1?key=yourKey.

Once that's done, you will automatically receive an alert whenever motion is detected by your project, even if you are not actually watching the data!

Summary


In this chapter, we built a project that can just be put in a room to spy on it from anywhere in the world. It continuously records data from the sensors connected to it, and sends this data directly to the cloud.

There are of course many things you can do to improve this project. You can, for example, experiment with your own sensors, depending on the data you want to spy on. You can also try to replace the CC3000 Wi-Fi chip with the GSM/GPRS shield we used in an earlier chapter to have a module you can place somewhere without having to connect it to a Wi-Fi network.

In the next chapter, we'll dive into a more advanced topic: actually building a GPS tracker based on Arduino!

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Arduino for Secret Agents
Published in: Nov 2015Publisher: ISBN-13: 9781783986088
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

Author (1)

author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz