Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Android Things Projects
Android Things Projects

Android Things Projects: Efficiently build IoT projects with Android Things

eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

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
Table of content icon View table of contents Preview book icon Preview Book

Android Things Projects

Creating an Alarm System Using Android Things

In this chapter, we will build an alarm system using Android Things. The target of this project is creating a system that detects movements using PIR sensors and when this event happens the Android Things app will send a notification to the user smartphone. The principles of this project are commonly used in real alarm systems we have in our homes, but we will build it with a totally new operating system. This is an interesting project because it uses, at the same time, sensors and cloud platforms. Through this project, we will explore how to use GPIO pins in Android Things and how to interact with two states sensors.

The main topics covered in this chapter are:

  • How to use build an alarm system
  • How to use GPIO pins and PIR sensors
  • How to handle events from a GPIO pin
  • How to build an app that is independent of the board
  • How to notify...

Alarm system project description

An alarm system is a complex system that uses several sensors to keep our home safe. At the heart of these types of systems, there are sensors that are able to detect motion. In other words, these sensors can detect if an object is moving in their detection area. When this happens, they notify this event. In this chapter, we will create a real-life project that uses these sensors to detect motion and notifies the event to the smartphones. At the end of this project, we will be able to detect if someone is entering our home without our authorization. Once you have built this project, you can expand it, adding more sensors so that you can monitor several rooms. Moreover, this project can be used as a starting point and can be expanded, adding new features as we will see in the following sections. The following figure describes how this Android Things...

How to close the connection with a GPIO pin

In this last step, we will learn how to close the connection with a GPIO pin. This is an important step because in this way, we free the resources and remove all the listeners we added to the GPIO pins.

An Android Things app has a life cycle very similar to an Android app. The place where we implement these actions is the Activity onDestroy method. In this method we have to:

  • Remove all the listeners attached to the GPIO pins
  • Close the connection to the GPIO pins

So, open MainActivity.java again and look for the onDestroy method and modify it:

@Override
protected void onDestroy()
{ super.onDestroy(); Log.d(TAG, "onDestroy");
if (gpioPin != null) {
gpioPin.unregisterGpioCallback(sensorCallback);
try {
gpioPin.close(); gpioPin = null;
}
catch(Exception e) {}
}
}
...

Handle different boards in Android Things

There are two important aspects that we have not covered:

  • How to select the pin to connect the peripherals to
  • How to identify the pin name

Regarding the first aspect, in Raspberry Pi 3 and Intel Edison, but in general for all the boards, the pins do not provide the same features. In other words, we cannot connect the peripherals to a pin by choosing it randomly. We have to select the pin according to the peripheral specifications. In this context it is important to know the pinout of the boards so that we can identify the right pins for our peripherals.

The second aspect is relevant when we want to develop an Android Things app that will run on different boards. As we said in the previous chapter, from the code point of view, this is not a problem because the Java language at the base of Android Things SDK guarantees us that we can run...

How to implement the notification system

Now we are ready to implement the last part of this project: the notification system. In the next paragraphs, we will describe how to send a notification to the user smartphone when motion is detected. As the messaging system, this IoT project uses Google Firebase. This is a cloud platform developed by Google providing several interesting services. We will use the Notification service.

There are several ways we can send a notification from the Android Things app to a user smartphone. To keep things simple, we will use topic. You can imagine a topic like a channel. After a device subscribes to a topic, it will receive all the messages published to this channel. In our project, the user smartphone behaves like a subscriber receiving messages from the channel, while the Android Things app behaves like a publisher publishing the messages.

Now...

Android companion app

In order to receive the notifications, we have to install an Android companion app on our smartphone. Just to simplify the system, this Android app will:

  1. Subscribe to the channel used by the Android Things app to send notifications.
  2. Implement a service to listen to the incoming notification.
  3. Show the notification to the user.

If you do not know how to receive notifications in Android you can visit https://firebase.google.com/docs/android/setup to know more. The source code of the Android companion app is provided with this book's source code. The app interface is very simple because we simply have to subscribe to the topic and wait for the incoming notifications.

To install the app, just open the project using Android Studio and connect your smartphone to your PC/Mac. Add the google-services.json file to your app module. This file is the same one that...

Alarm system project description


An alarm system is a complex system that uses several sensors to keep our home safe. At the heart of these types of systems, there are sensors that are able to detect motion. In other words, these sensors can detect if an object is moving in their detection area. When this happens, they notify this event. In this chapter, we will create a real-life project that uses these sensors to detect motion and notifies the event to the smartphones. At the end of this project, we will be able to detect if someone is entering our home without our authorization. Once you have built this project, you can expand it, adding more sensors so that you can monitor several rooms. Moreover, this project can be used as a starting point and can be expanded, adding new features as we will see in the following sections. The following figure describes how this Android Things IoT project will work:

The following are the main steps:

  1. The PIR sensor scans the detection area looking for movement...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn to build promising IoT projects with Android Things
  • Make the most out of hardware peripherals using standard Android APIs
  • Build enticing projects on IoT, home automation, and robotics by leveraging Raspberry Pi 3 and Intel Edison

Description

Android Things makes developing connected embedded devices easy by providing the same Android development tools, best-in-class Android framework, and Google APIs that make developers successful on mobile. With this book, you will be able to take advantage of the new Android framework APIs to securely build projects using low-level components such as sensors, resistors, capacitors, and display controllers. This book will teach you all you need to know about working with Android Things through practical projects based on home automation, robotics, IoT, and so on. We’ll teach you to make the most of the Android Things and build enticing projects such as a smart greenhouse that controls the climate and environment automatically. You’ll also create an alarm system, integrate Android Things with IoT cloud platforms, and more. By the end of this book, you will know everything about Android Things, and you’ll have built some very cool projects using the latest technology that is driving the adoption of IoT. You will also have primed your mindset so that you can use your knowledge for profitable, practical projects.

Who is this book for?

This book is for Android enthusiasts, hobbyists, IoT experts, and Android developers who want to gain a deeper knowledge of Android Things. The main focus is on implementing IoT projects using Android Things.

What you will learn

  • Understand IoT ecosystem and the Android Things role
  • See the Android Things framework: installation, environment, SDK, and APIs
  • See how to effectively use sensors (GPIO and I2C Bus)
  • Integrate Android Things with IoT cloud platforms
  • Create practical IoT projects using Android Things
  • Integrate Android Things with other systems using standard IoT protocols
  • Use Android Things in IoT projects

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2017
Length: 232 pages
Edition : 1st
Language : English
ISBN-13 : 9781787280427
Vendor :
Google
Category :
Languages :

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

Product Details

Publication date : Jun 30, 2017
Length: 232 pages
Edition : 1st
Language : English
ISBN-13 : 9781787280427
Vendor :
Google
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 102.97
Android Things Projects
€32.99
Android System Programming
€36.99
ESP8266 Internet of Things Cookbook
€32.99
Total 102.97 Stars icon

Table of Contents

8 Chapters
Getting Started with Android Things Chevron down icon Chevron up icon
Creating an Alarm System Using Android Things Chevron down icon Chevron up icon
How to Make an Environmental Monitoring System Chevron down icon Chevron up icon
Integrate Android Things with IoT Cloud Platforms Chevron down icon Chevron up icon
Create a Smart System to Control Ambient Light Chevron down icon Chevron up icon
Remote Weather Station Chevron down icon Chevron up icon
Build a Spying Eye Chevron down icon Chevron up icon
Android with Android Things Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(1 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
Klemen Petrovčič Dec 22, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The book contains some recipes for connecting various sensors and actuators to one of the two DIY platforms presented in the book (Raspberry pi3 and Intel Edison), taking various measurements of physically quantifiable properties and sending them to an IoT platform. I would not say this is a book for beginners, because it assumes that the reader already has some knowledge of, at least, Android programming (since it is so simillar to programming for Android Things). On top of that, the reader should be familliar with some concepts/protocols (I2C, UART, logical operations) from embedded programming (writing an I2C driver is much harder than explained in this book) and basic Linux commands (for navigating the command line of the Raspberry Pi). The chapters at the end describe the usage of the MQTT application protocol (it introduces concepts like: broker, QoS, topics), which is widely popular among the maker/DIY community. The book is not filled with unnecessary theory and is packed with short tutorials, which can later be reused and extended by the readers.
Amazon Verified review Amazon
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.