Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arduino for Secret Agents
Arduino for Secret Agents

Arduino for Secret Agents: Transform your tiny Arduino device into a secret agent gadget to build a range of espionage projects with this practical guide for hackers

By Marco Schwartz
£19.99 £13.98
Book Nov 2015 170 pages 1st Edition
eBook
£19.99 £13.98
Print
£24.99
Subscription
£13.99 Monthly
eBook
£19.99 £13.98
Print
£24.99
Subscription
£13.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 20, 2015
Length 170 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781783986088
Vendor :
Arduino
Category :
Concepts :
Table of content icon View table of contents Preview book icon Preview Book

Arduino for Secret Agents

Chapter 1. A Simple Alarm System with Arduino

I want to start this book with a simple project that any secret agent will want to have, a simple alarm system that will be activated whenever motion is detected by a sensor. This simple system is not only fun to make but will also help us to go over the basics of Arduino programming and electronics, which are the skills that we will use in this whole book.

It will basically be a simple alarm (a buzzer that makes sound, plus a red LED) combined with a motion detector. The user will also be able to stop the alarm by pressing a button.

We are going to do the following in this chapter:

  • First, we are going to see what the requirements for this project are, in terms of hardware and software

  • Then, we will see how to assemble the hardware parts for this project

  • After that, we will configure our system using the Arduino IDE

Hardware and software requirements


First, let's see what the required components for this project are. As this is the first chapter of the book, we will spend a bit more time here to detail the different components, as these are components that we will be using in the whole book.

The first component that will be central to the project is the Arduino Uno board:

In several chapters of this book, this will be the 'brain' of the projects that we will make. In all the projects, I will be using the official Arduino Uno R3 board. However, you can use an equivalent board from another brand or another Arduino board, such as an Arduino Mega board.

Another crucial component of our alarm system will be the buzzer:

This is a very simple component that is used to make simple sounds with Arduino. You couldn't play an MP3 with it but it's just fine for an alarm system. You can, of course, use any buzzer that is available; the goal is to just make a sound.

After that, we are going to need a motion detector:

Here, I used a very simple PIR motion detector. This sensor will measure the infrared (IR) light that is emitted by moving objects in its field of view, for example, people moving around. It is really easy and quite cheap to interface with Arduino. You can use any brand that you want for this sensor; it just needs a voltage level of 5V in order to be compatible with the Arduino Uno board.

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

On the software side, the only thing that we will need in the first chapter is the latest version of the Arduino IDE that you can download from the following URL: https://www.arduino.cc/en/main/software.

Note that we are going to use the Arduino IDE in all the projects of this book, so make sure to install the latest version.

Hardware configuration


We are now going to assemble the hardware for this project. As this is the first project of this book, it will be quite simple. However, there are quite a lot of components, so be sure to follow all the steps.

Here is a schematic to help you out during the process:

Let's start by putting all the components on the board. Place the buzzer, button, and LED on the board first, according to the schematics. Then, place the 330 Ohm resistor in series with the LED anode (the longest pin) and connect the 1k Ohm resistor to one pin of the push button.

This is how it should look at this stage:

Now we are going to connect each component to the Arduino board.

Let's start with the power supply. Connect the 5V pin of the Arduino board to one red power rail of the breadboard, and the GND pin of the Arduino board to one blue power rail of the breadboard.

Then, we are going to connect the buzzer. Connect one pin of the buzzer to pin number 5 of the Arduino board and the other pin to the blue power rail of the breadboard.

After that, let's connect the LED. Connect the free pin of the resistor to pin number 6 of the Arduino board and the free pin of the LED (the cathode) to the ground via the blue power rail.

Let's also connect the push button to our Arduino board. Refer to the schematic to be sure about the connections since it is a bit more complex. Basically, you need to connect the free pin of the resistor to the ground and connect the pin that is connected to the button to the 5V pin via the red power rail. Finally, connect the other side of the button to pin 12 of the Arduino board.

Finally, let's connect the PIR motion sensor to the Arduino board. Connect the VCC pin of the motion sensor to the red power rail and the GND pin to the blue power rail. Finally, connect the SIG pin (or OUT pin) to Arduino pin number 7.

The following is the final result:

If your project looks similar to this picture, congratulations, you just assembled your first secret agent project! You can now go on to the next section.

Configuring the alarm system


Now that the hardware for our project is ready, we can write down the code for the project so that we have a usable alarm system. The goal is to make the buzzer produce a sound whenever motion is detected and also to make the LED flash. However, whenever the button is pressed, the alarm will be switched off.

Here is the complete code for this project:

// Code for the simple alarm system

// Pins
const int alarm_pin = 5;
const int led_pin = 6;
const int motion_pin = 7;
const int button_pin = 12;

// Alarm
boolean alarm_mode = false;

// Variables for the flashing LED
int ledState = LOW;
long previousMillis = 0; 
long interval = 100;  // Interval at which to blink (milliseconds)

void setup()
{
  // Set pins to output
  pinMode(led_pin,OUTPUT);
  pinMode(alarm_pin,OUTPUT);

  // Set button pin to input
  pinMode(button_pin, INPUT);
  
  // Wait before starting the alarm
  delay(5000);
}

void loop()
{
  // Motion detected ?
  if (digitalRead(motion_pin)) {
    alarm_mode = true; 
  }

  // If alarm mode is on, flash the LED and make the alarm ring
  if (alarm_mode){
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;   
      if (ledState == LOW)
        ledState = HIGH;
      else
        ledState = LOW;
    // Switch the LED
    digitalWrite(led_pin, ledState);
    }
    tone(alarm_pin,1000);
  }

  // If alarm is off
  if (alarm_mode == false) {
  
    // No tone & LED off
    noTone(alarm_pin);  
    digitalWrite(led_pin, LOW);
  }

  // If button is pressed, set alarm off
  int button_state = digitalRead(button_pin);
  if (button_state) {alarm_mode = false;}
}

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

We are now going to see, in more detail, the different parts of the code. It starts by declaring which pins are connected to different elements of the project, such as the alarm buzzer:

const int alarm_pin = 5;
const int led_pin = 6;
const int motion_pin = 7;
const int button_pin = 12;

After that, in the setup() function of the sketch, we declare these pins as either inputs or outputs, as follows:

// Set pins to output
pinMode(led_pin,OUTPUT);
pinMode(alarm_pin,OUTPUT);

// Set button pin to input
pinMode(button_pin, INPUT);

Then, in the loop() function of the sketch, we check whether the alarm was switched on by checking the state of the motion sensor:

if (digitalRead(motion_pin)) {
  alarm_mode = true; 
}

Note that if we detect some motion, we immediately set the alarm_mode variable to true. We will see how the code makes use of this variable right now.

Now, if the alarm_mode variable is true, we have to enable the alarm, make the buzzer emit a sound, and also flash the LED. This is done by the following code snippet:

if (alarm_mode){
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;   
      if (ledState == LOW)
        ledState = HIGH;
      else
        ledState = LOW;
    // Switch the LED
    digitalWrite(led_pin, ledState);
    }
    tone(alarm_pin,1000);
  }

Also, if alarm_mode is returning false, we need to deactivate the alarm immediately by stopping the sound from being emitted and shutting down the LED. This is done with the following code:

if (alarm_mode == false) {
  
    // No tone & LED off
    noTone(alarm_pin);  
    digitalWrite(led_pin, LOW);
  }

Finally, we continuously read the state of the push button. If the button is pressed, we will immediately set the alarm off:

int button_state = digitalRead(button_pin);
if (button_state) {alarm_mode = false;}

Usually, we should take care of the bounce effect of the button in order to make sure that we don't have erratic readings when the button is pressed. However, here we only care about the button actually being pressed so we do not need to add an additional debouncing code for the button.

Note that you can find all the code for this project inside the GitHub repository of the book:

https://github.com/marcoschwartz/arduino-secret-agents

Now that we have written down the code for the project, it's time to get to the most exciting part of the chapter: testing the alarm system!

Testing the alarm system


We are now ready to test our simple alarm system. Just grab the code for this project (either from the preceding code or the GitHub repository of the book) and put it into your Arduino IDE.

In the IDE, choose the right board type (for example, Arduino Uno) and also the correct serial port.

You can now upload the code to the board. Once it is done, simply pass your hand in front of the PIR motion sensor; the alarm should go off immediately. Then, simply press the push button to stop it.

To illustrate the behavior of the alarm, I simply used a battery pack to make it work when it is not connected to my computer. The following is the result when the alarm goes off:

If this works as expected, congratulations, you just built your first secret agent project: a simple alarm system based on Arduino!

If it doesn't work well at this point, there are several things you can check. First, go through the hardware configuration part again to make sure that your project is correctly configured.

Also, you can verify that when you pass your hand in front of the PIR sensor, it goes red. If this is not the case, most probably your PIR motion sensor has a problem and must be replaced.

Summary


In this first chapter, we built a simple alarm based on Arduino with only a few components.

There are several ways to go further and improve this project. You can add more functions to the project just by adding more lines to the code. For example, you can add a timer so that the alarm only goes off after a given amount of time, or you can build a mode where a push of the button actually activates or deactivates the alarm mode.

In the next chapter, we are going to build another project that is very useful for secret agents: an audio recording device based on Arduino!

Left arrow icon Right arrow icon

Key benefits

  • • Discover the limitless possibilities of the tiny Arduino and build your own secret agent projects
  • • From a fingerprint sensor to a GPS Tracker and even a robot– learn how to get more from your Arduino
  • • Build nine secret agent projects using the power and simplicity of the Arduino platform

Description

Q might have Bond’s gadgets– but he doesn’t have an Arduino (not yet at least). Find out how the tiny Arduino microcomputer can be used to build an impressive range of neat secret agent projects that can help you go undercover and get to grips with the cutting-edge of the world of espionage with this book, created for ardent Arduino fans and anyone new to the powerful device. Each chapter shows you how to construct a different secret agent gadget, helping you to unlock the full potential of your Arduino and make sure you have a solution for every tricky spying situation. You’ll find out how to build everything from an alarm system to a fingerprint sensor, each project demonstrating a new feature of Arduino, so you can build your expertise as you complete each project. Learn how to open a lock with a text message, monitor top secret data remotely, and even create your own Arduino Spy Robot, Spy Microphone System, and Cloud Spy Camera This book isn’t simply an instruction manual – it helps you put your knowledge into action so you can build every single project to completion.

What you will learn

• Get to know the full range of Arduino features so you can be creative through practical projects • Discover how to create a simple alarm system and a fingerprint sensor • Find out how to transform your Arduino into a GPS tracker • Use the Arduino to monitor top secret data • Build a complete spy robot! • Build a set of other spy projects such as Cloud Camera and Microphone System

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 20, 2015
Length 170 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781783986088
Vendor :
Arduino
Category :
Concepts :

Table of Contents

16 Chapters
Arduino for Secret Agents Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewer Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
A Simple Alarm System with Arduino Chevron down icon Chevron up icon
Creating a Spy Microphone Chevron down icon Chevron up icon
Building an EMF Bug Detector Chevron down icon Chevron up icon
Access Control with a Fingerprint Sensor Chevron down icon Chevron up icon
Opening a Lock with an SMS Chevron down icon Chevron up icon
Building a Cloud Spy Camera Chevron down icon Chevron up icon
Monitoring Secret Data from Anywhere Chevron down icon Chevron up icon
Creating a GPS Tracker with Arduino Chevron down icon Chevron up icon
Building an Arduino Spy Robot Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.