Internet of Things Programming Projects

Book description

A practical project-based guide to help you build and control your IoT projects

Key Features

  • Leverage the full potential of IoT with the combination of Raspberry Pi 3 and Python
  • Build complex Python-based applications with IoT
  • Work on various IoT projects and understand the basics of electronics

Book Description

The Internet of Things (IOT) has managed to attract the attention of researchers and tech enthusiasts, since it powerfully combines classical networks with instruments and devices.

In Internet of Things Programming Projects, we unleash the power of Raspberry Pi and Python to create engaging projects. In the first part of the book, you'll be introduced to the Raspberry Pi, learn how to set it up, and then jump right into Python programming. Then, you'll dive into real-world computing by creating a?Hello World? app using flash LEDs.

As you make your way through the chapters, you'll go back to an age when analog needle meters ruled the world of data display. You'll learn to retrieve weather data from a web service and display it on an analog needle meter, and build a home security system using the Raspberry Pi. The next project has a modern twist, where we employ the Raspberry Pi to send a signal to a web service that will send you a text when someone is at the door. In the final project, you take what you've learned from the previous two projects and create an IoT robot car that you can use to monitor what your pets are up to when you are away.

By the end of this book, you will be well versed in almost every possible way to make your IoT projects stand out.

What you will learn

  • Install and set up a Raspberry Pi for IoT development
  • Learn how to use a servo motor as an analog needle meter to read data
  • Build a home security dashboard using an infrared motion detector
  • Communicate with a web service that sends you a message when the doorbell rings
  • Receive data and display it with an actuator connected to the Raspberry Pi
  • Build an IoT robot car that is controlled through the internet

Who this book is for

Internet of Things Programming Projects is for Python developers and programmers who are interested in building their own IoT applications and IoT-based projects. It is also targeted at IoT programmers and developers who are looking to build exciting projects with Python.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Internet of Things Programming Projects
  3. Packt Upsell
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Installing Raspbian on the Raspberry Pi
    1. A brief history of the Raspberry Pi
    2. A look at operating systems for the Raspberry Pi
    3. Project overview
    4. Getting started
    5. Installing the Raspbian OS
      1. Formatting a microSD card for Raspbian
      2. Copying the NOOBS files to the microSD RAM
      3. Running the installer
    6. A quick overview of the Raspbian OS
      1. The Chromium web browser
      2. The home folder
      3. The Terminal
      4. Mathematica
      5. Sonic Pi
      6. Scratch and Scratch 2.0
      7. LibreOffice
    7. Summary
    8. Questions
    9. Further reading
  7. Writing Python Programs Using Raspberry Pi
    1. Project overview
    2. Technical requirements
    3. Python tools for Raspberry Pi
      1. The Terminal
      2. Integrated Development and Learning Environment
      3. Thonny
    4. Using the Python command line
    5. Writing a simple Python program
      1. Creating the class
      2. Creating the object
      3. Using the object inspector
      4. Testing your class
      5. Making the code flexible
        1. Example one
        2. Example two
    6. Summary
    7. Questions
    8. Further reading
  8. Using the GPIO to Connect to the Outside World
    1. Project overview
    2. Technical requirements
    3. Python libraries for the Raspberry Pi
      1. picamera
      2. Pillow
      3. sense-hat and sense-emu
    4. Accessing Raspberry Pi's GPIO
      1. Pibrella
      2. RPi.GPIO
      3. GPIO zero
    5. Setting up the circuit
      1. Fritzing
      2. Building our circuit
    6. Hello LED
      1. Blink LED using gpiozero
      2. Morse code weather data
    7. Summary
    8. Questions
    9. Further reading
  9. Subscribing to Web Services
    1. Prerequisites
    2. Project overview
    3. Getting started
    4. Cloud services for IoT
      1. Amazon Web Services IoT
      2. IBM Watson platform
      3. Google Cloud platform
      4. Microsoft Azure
      5. Weather Underground
    5. A basic Python program to pull data from the cloud
      1. Accessing the web service
      2. Using the Sense HAT Emulator
    6. Summary
    7. Questions
    8. Further reading
  10. Controlling a Servo with Python
    1. Knowledge required to complete this chapter
    2. Project overview
    3. Getting started
    4. Wiring up a servo motor to the Raspberry Pi
      1. Stepper motors
      2. DC motors
      3. Servo motors
      4. Connecting the servo motor to our Raspberry Pi
    5. Control the servo through the command line
    6. Write a Python program to control the servo
    7. Summary
    8. Questions
    9. Further reading
  11. Working with the Servo Control Code to Control an Analog Device
    1. Knowledge required to complete this chapter
    2. Project overview
    3. Getting started
    4. Accessing weather data from the cloud
    5. Controlling the servo using weather data
      1. Correcting for servo range
      2. Changing the position of the servo based on weather data
    6. Enhancing our project
      1. Printing out the main graphic
      2. Adding the needle and LED
    7. Summary
    8. Questions
    9. Further reading
  12. Setting Up a Raspberry Pi Web Server
    1. Knowledge required to complete this chapter
    2. Project overview
    3. Getting started
    4. Introducing CherryPy – a minimalist Python web framework
      1. What is CherryPy?
        1. Who uses CherryPy?
      2. Installing CherryPy
    5. Creating a simple web page using CherryPy
      1. Hello Raspberry Pi!
      2. Say hello to myFriend
      3. What about static pages?
      4. HTML weather dashboard
    6. Summary
    7. Questions
    8. Further reading
  13. Reading Raspberry Pi GPIO Sensor Data Using Python
    1. Project overview
    2. Getting started
    3. Reading the state of a button
      1. Using GPIO Zero with a button
      2. Using the Sense HAT emulator and GPIO Zero button together
      3. Toggling an LED with a long button press
    4. Reading the state from an infrared motion sensor
      1. What is a PIR sensor?
      2. Using the GPIO Zero buzzer class
      3. Building a basic alarm system
    5. Modifying Hello LED using infrared sensor
      1. Configuring a distance sensor
      2. Taking Hello LED to another level
    6. Summary
    7. Questions
    8. Further reading
  14. Building a Home Security Dashboard
    1. Knowledge required to complete this chapter
    2. Project overview
    3. Getting started
    4. Creating our dashboard using CherryPy
      1. Using the DHT11 to find temperature and humidity
      2. Using the Pi camera to take a photo
      3. Creating our dashboard using CherryPy
    5. Displaying sensory data on our dashboard
      1. Home security dashboard with a temperature sensor
      2. Home security dashboard with quick response
    6. Summary
    7. Questions
    8. Further reading
  15. Publishing to Web Services
    1. Project overview
    2. Getting started
    3. Publishing sensory data to cloud-based services
      1. Install the MQTT library
      2. Set up an account and create a device
      3. Reading sensory data and publishing to ThingsBoard
      4. Creating a dashboard in ThingsBoard
      5. Sharing your dashboard with a friend
    4. Setting up an account for text message transmission
      1. Setting up a Twilio account
      2. Installing Twilio on our Raspberry Pi
      3. Sending a text through Twilio
      4. Creating a new home security dashboard
    5. Summary
    6. Questions
    7. Further reading
  16. Creating a Doorbell Button Using Bluetooth
    1. Project overview
    2. Getting started
    3. Introducing Blue Dot
      1. Installing the bluedot library on the Raspberry Pi
      2. Pairing Blue Dot with your Raspberry Pi
    4. Wiring up our circuit
      1. What is an RGB LED?
      2. Testing our RGB LED
      3. Completing our doorbell circuit
    5. Reading our button state using Bluetooth and Python
      1. Reading button information using Python
      2. Creating a Bluetooth doorbell
      3. Creating a secret Bluetooth doorbell
    6. Summary
    7. Questions
    8. Further reading
  17. Enhancing Our IoT Doorbell
    1. Project overview
    2. Getting started
    3. Sending a text message when someone is at the door
      1. Creating a simple doorbell application with text messaging
      2. Creating a secret doorbell application with text messaging
    4. Summary
    5. Questions
    6. Further reading
  18. Introducing the Raspberry Pi Robot Car
    1. The parts of the robot car
    2. Building the robot car
      1. Step 1 – Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi
      2. Step 2 – Wiring up the motors
      3. Step 3 – Assembling the servo camera mount
      4. Step 4 – Attaching the head
      5. Step 5 – Assembling the DC motor plate
      6. Step 6 – Attaching the motors and wheels
      7. Step 7 – Wiring up the motors
      8. Step 8 – Attaching the camera mount, Raspberry Pi, and Adafruit servo board
      9. Step 9 – Attaching the buzzer and voltage divider
      10. Step 10 – Wiring up T.A.R.A.S
    3. Learning how to control the robot car
      1. Configuring our Raspberry Pi
      2. Python library for Adafruit Servo HAT
    4. Summary
    5. Questions
  19. Controlling the Robot Car Using Python
    1. Knowledge required to complete this chapter
    2. Project overview
    3. Getting started
    4. Taking a look at the Python code
      1. Controlling the drive wheels of the robot car
      2. Moving the servos on the robot car
      3. Taking a picture
      4. Making a beep noise
      5. Making the LEDs blink
    5. Modifying the robot car Python code
      1. Move the wheels
      2. Move the head
      3. Make sounds
    6. Enhancing the code
      1. Stitching our code together
    7. Summary
    8. Questions
    9. Further reading
  20. Connecting Sensory Inputs from the Robot Car to the Web
    1. Knowledge required to complete this chapter
    2. Project overview
    3. Getting started
    4. Identifying the sensor on the robot car
      1. Taking a closer look at the HC-SR04
    5. Reading robot car sensory data with Python
    6. Publishing robot car sensory data to the cloud
    7. Create a ThingsBoard device
    8. Summary
    9. Questions
    10. Further reading
  21. Controlling the Robot Car with Web Service Calls
    1. Knowledge required to complete this chapter
    2. Project overview
    3. Technical requirements
    4. Reading the robot car's data from the cloud
      1. Changing the look of the distance gauge
      2. Changing the range on the distance gauge
      3. Viewing the dashboard outside of your account
    5. Using a Python program to control a robot car through the cloud
      1. Adding a switch to our dashboard
      2. Controlling the green LED on T.A.R.A.S
      3. Using the internet to make T.A.R.A.S dance
    6. Summary
    7. Questions
    8. Further reading
  22. Building the JavaScript Client
    1. Project overview
    2. Getting started
    3. Introducing JavaScript cloud libraries
      1. Google Cloud
      2. AWS SDK for JavaScript
      3. Eclipse Paho JavaScript client
    4. Connecting to cloud services using JavaScript
      1. Setting up a CloudMQTT account
      2. Setting up an MQTT Broker instance
      3. Writing the JavaScript client code
      4. Running the code
      5. Understanding the JavaScript code
      6. Publishing MQTT messages from our Raspberry Pi
    5. Summary
    6. Questions
    7. Further reading
  23. Putting It All Together
    1. Project overview
    2. Getting started
    3. Building a JavaScript client to connect to our Raspberry Pi
      1. Writing the HTML code
      2. Writing the JavaScript code to communicate with our MQTT Broker
    4. Creating a JavaScript client to access our robot car's sensory data
      1. Writing the code for T.A.R.A.S
      2. Livestreaming videos from T.A.R.A.S
    5. Enhancing our JavaScript client to control our robot car
      1. Nipple.js
      2. HTML5 Gamepad API
      3. Johnny-Five
    6. Summary
    7. Questions
    8. Further reading
  24. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
    17. Chapter 17
    18. Chapter 18
  25. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Internet of Things Programming Projects
  • Author(s): Colin Dow
  • Release date: October 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789134803