Book Image

Internet of Things with the Arduino Yún

By : Marco Schwartz
Book Image

Internet of Things with the Arduino Yún

By: Marco Schwartz

Overview of this book

<p>Internet of Things (IoT) is currently a growing trend in the technology space, and the Arduino Yún is the perfect board to get started with building IoT projects. This book covers many of the powerful features of the Arduino Yún via four exciting projects. The first project is all about sending weather measurements data to a Google Docs spreadsheet for easy online visualization. The second one is about building an energy consumption meter and controlling devices remotely. The third focuses on the field of security, by helping you to build a camera that is triggered by motion and that uploads pictures automatically to Dropbox. Finally, the last project is in relation with the field of robotics, and focuses on building a robot that is controlled via Wi-Fi. <br /><br />The main focus of this book is to teach everything you need to know to build complex projects using the Arduino Yún, organized around the fields of home automation, security, and robotics.</p>
Table of Contents (11 chapters)

Preface

The Internet of Things (IoT) is a growing topic in the tech world, and more and more hardware projects that are funded using crowd-funding campaigns include some connected objects. Such objects can be smart watches that connect to the Web, the weather station, cameras, energy monitoring devices, and even robots. Many industry giants such as Google and Samsung are also entering the market with connected objects and wearable devices.

On the other hand, millions of people around the world use the Arduino platform to create hardware projects. Because Arduino is so easy to use, it allows not only hobbyists, but also artists and people without a tech background to create amazing hardware projects. The platform is always evolving with new solutions that allow people to create more and more complex DIY projects.

One of the latest boards from Arduino—the Arduino Yún—mixes these two worlds harmoniously. This board's release was appreciated by hobbyists around the world who wanted to develop connected objects. Indeed, developing applications for IoT has always been quite complex and requires a lot of expertise in both hardware and web applications development. However, we are going to see why using the Arduino Yún can make the process much easier.

The Arduino Yún is the same size as the Arduino Uno, which is the most common Arduino board. However, the difference is that it features a small Linux machine that runs on a separate processor as well as an onboard Wi-Fi chip so you can connect the board to your local Wi-Fi network.

The clever thing they did with the Arduino Yún board is create a Bridge library that allows you to call functions of the Linux machine from the usual Arduino microcontroller that is also present on the board. This way, you can use the powerful features of the Linux machine by programming in the same way as you would on the Arduino Uno board. You can, for example, write whole programs in high-level languages such as Python, and call them from an Arduino sketch.

The fact that the board also has onboard Wi-Fi changes everything. The board was developed in close collaboration with the Temboo web service, which provides many libraries to interface the board with other web services such as Google Docs, Gmail, and Dropbox.

For all these reasons, using the Arduino Yún will allow you to build connected applications without requiring you to be an expert in the field. Using the power of the embedded Linux machine, the Wi-Fi connection, and the Temboo libraries, you will be able to easily create your own IoT devices. To show you what exactly the Arduino Yún can do, I have built four exciting projects using this board, and you too will be able to build these projects after reading this book.

What this book covers

Chapter 1, Building a Weather Station Connected to the Cloud, introduces you to the Internet of Things features of the Arduino Yún. In this chapter, we are going to build a weather measurement station (which measures the temperature, humidity, and light levels) that sends data to the Web. The project will send data to a Google Docs spreadsheet via Temboo and log the results in the spreadsheet where they can be displayed graphically. The nice thing about this project is that this data can then be accessed from anywhere in the world just by logging into your Google account and going to the spreadsheet.

Chapter 2, Creating a Remote Energy Monitoring and Control Device, focuses on energy management by creating a project to switch a device on and off (like a lamp), measuring its energy consumption and storing this data to the Web. We are going to interface a current sensor to measure the energy consumption of the device that is connected to the project. The project will also be able to switch the device on and off remotely, and we are going to build an interface for you to control this switch from your computer and mobile device.

Chapter 3, Making Your Own Cloud-connected Camera, allows us to build our own DIY version of a wireless security camera by connecting a standard USB webcam to the Arduino Yún. We will perform two exciting applications with this project: first, we will automatically upload pictures from the camera when some motion is detected in front of it, and then we are going to make the camera stream video live from YouTube, so you can monitor what is going on in your home from anywhere.

Chapter 4, Wi-Fi-controlled Mobile Robot, focuses on robotics. We are going to build a Wi-Fi-controlled mobile robot with two wheels and an ultrasonic distance sensor in front of it. Additionally, we are going to use the powerful features of the Arduino Yún to easily control this robot via Wi-Fi. To do this, we are going to build a web interface that will be used to control the movement of the robot, and this will also display the distance measured by the front sensor.

What you need for this book

The main focus of this book is the Arduino Yún board; so, of course, you will need one of the Arduino Yún boards to make all four projects of the book. Depending on the chapter, you will also need several hardware components. The details of these components required are given at the beginning of each chapter.

You will also need to have some software installed on your computer to make the projects work. The first one is the Arduino IDE's latest beta version (the only version that can work with the Yún). For all these projects, I used the Arduino IDE Version 1.5.6-r2, but all the newer versions should work as well. You can download the Arduino IDE at http://arduino.cc/en/main/software#toc3.

You will also need a web server running on your computer for some of the projects. I recommend that you use a software that integrates a web server and a database, and that handles all the details for you. If you are using Windows, I recommend using EasyPHP, which is available at http://www.easyphp.org/.

Under OS X, I recommend using MAMP, which is available at http://www.mamp.info/.

With Linux, you can follow the instructions to install a web server provided at http://doc.ubuntu-fr.org/lamp.

Make sure the server is running at this point; we are going to use it in several of the projects in this book.

All the projects assume that your Arduino Yún board is already configured and connected to your Wi-Fi network. To configure and connect the Yún to your Wi-Fi network, there are only a few steps to follow. The first one is to plug the Arduino board in to the wall and wait for a moment.

After a while, you should see that a new Wi-Fi network has appeared in the list of Wi-Fi networks on your computer, created by the Yún. Connect to it, open a browser, and type the following command:

arduino.local

This should open a page served by the Arduino Yún board. You will be prompted to enter a password for your Yún board; please enter one that you can remember easily, as you will need it many times while attempting the projects in this book.

Then, you will be taken to a new page that contains some information about your Yún board. You can change the name of the board (which we will use later in all the projects), and also set your Wi-Fi parameters. You have to set these parameters so that the board can connect to your home Wi-Fi network. Choose the correct network from the list, enter your password, and click on Configure & Restart.

The Yún will then restart and connect to your network. At this point, you can also reconnect your computer to the local Wi-Fi network. After a while, you can type the following command in your browser along with the name you gave your Arduino board:

myarduinoyun.local

You should be taken to the same page again, but this time, with the Yún board connected to your local Wi-Fi network. If this is working, it means the Yún board is ready to be used for all the projects in the book.

You will also need to open the REST API of the Yún. This setting is configured on the configuration page of the Yún, where you have to select OPEN, which is close to REST API ACCESS. Reboot the Yún board again when the option has been changed.

Note that you have two ways to program your Yún board: you can either plug it directly into your computer via micro USB, or plug it into the wall via a USB adapter and upload the sketches via Wi-Fi.

Who this book is for

If you want to build exciting applications for the Internet of Things using the Arduino platform, this is the book for you. If you are planning to build some cool projects to automate your home and monitor it remotely, you will love this book. You will learn how to measure data, control devices, monitor your home remotely using a USB camera, and build a Wi-Fi-controlled mobile robot.

As far as skills are concerned, this book assumes that you already have some knowledge of the Arduino platform (for example, with the Arduino Uno) and some basic knowledge of electronics and programming. Note that the book can also be used without any previous experience with the Arduino Yún and the onboard Linux machine.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The alert mechanism occurs in the new function called sendTempAlert that is called if the temperature is below the limit."

A block of code is set as follows:

[default]
String data = "";
data = data + timeString + "," + String(temperature) + "," + String(humidity) + "," + String(lightLevel);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[default]
if (client) {
  // Process request
  process(client);

  // Close connection and free resources.
  client.stop();
}

Any command-line input or output is written as follows:

# http://myarduinoyun.local/arduino/digital/8/1

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes, for example, appear in the text like this: "Just click on interface.html, and the interface should open and be scaled to your phone screen size."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. 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.

All the up-to-date code for the four projects of this book can also be found at https://github.com/openhomeautomation/geeky-projects-yun.

Downloading the color images of the book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/8007OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.