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
$32.99
Book Nov 2015 170 pages 1st Edition
eBook
$25.99 $17.99
Print
$32.99
Subscription
$15.99 Monthly
eBook
$25.99 $17.99
Print
$32.99
Subscription
$15.99 Monthly

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela