Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Things Projects

You're reading from  Android Things Projects

Product type Book
Published in Jun 2017
Publisher Packt
ISBN-13 9781787289246
Pages 232 pages
Edition 1st Edition
Languages
Author (1):
Francesco Azzola Francesco Azzola
Profile icon Francesco Azzola

Table of Contents (15) Chapters

Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Getting Started with Android Things Creating an Alarm System Using Android Things How to Make an Environmental Monitoring System Integrate Android Things with IoT Cloud Platforms Create a Smart System to Control Ambient Light Remote Weather Station Build a Spying Eye Android with Android Things

Chapter 7. Build a Spying Eye

In this chapter, we will build a spying eye. In more detail, we will build a project that uses an Android Things board to control a camera and a servomotor that we will use to rotate the camera. Through this project, we will learn how to use PWM pins. The Pulse Width Modulation (PWM) pin is a different kind of pin that we will use to control different types of peripherals such as servo motors. In more details, in this chapter we will explore:

  • How to use PWM pins in Android Things
  • How to control servo motors
  • How to use cameras

At the end of this chapter, we will build a fully working Android Things system that is able to acquire images using the camera and, at the same time, we will be able to control the camera direction using a servo motor.

Spying eye Android Things project overview


Before digging into the project details, it is worthwhile to have an overview of this project to know what we want to build and how it should work. The basic idea that stands behind this project is using a servo motor at the camera base. The camera and the motor are connected together so that while the Android Things app rotates the motor, we can change the camera orientation. By the way, a servomotor is a special motor type that we can control precisely in terms of its angular position.

The following figure visualizes the main project features:

As you can see from the preceding figure, in this project we want the Android Things board controlling the following at the same time:

  • The servomotor rotation
  • The camera that acquires the image

To access these features, this project exposes a simple UI interface. An important aspect is related to the camera support. Android Things supports CSI-2 protocol. There are some Android Things compatible boards that do...

Implementing the spying eye project in Android Things


It is time that we focused our attention on developing the project. Now we have all the information and the knowledge we need to build the Android Things app. This app can be divided into two different parts:

  • Control servomotor
  • Use camera in Android Things

In the first part, we describe, according to the information explained previously, how to control a servomotor while, in the second part, we will describe how to acquire images in Android Things using a camera. As you may remember, the servomotor is used in this project to rotate the camera so that we can explore a wider area. Moreover, this project has a UI that we can use to control the servo and take the picture. The user interface is very simple and intuitive; the result is shown in the following figure:

Basically, there are three buttons:

  • The left button is used to turn the camera to left rotating the servo
  • The right button is used to turn the camera to right rotating the servo
  • The button...

Summary


In this chapter, we have built a system based on servo motors and cameras. We have learned how to control a servo motor using Android Things. Moreover, you gained knowledge about PWM and the role it plays in this context. Now you have all the necessary information to implement Android Things apps to control new kinds of peripherals. You are mastering several peripherals such as LEDs, sensors, buttons, camera, motors, and so on.

In the next chapter, we will cover how to integrate Android and Android Things and how to create an Android companion app that remotely controls an Android Things app.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Android Things Projects
Published in: Jun 2017 Publisher: Packt ISBN-13: 9781787289246
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}