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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781787289246
Vendor :
Google
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.