Internet of Things With Arduino Blueprints - Sample Chapter
Internet of Things With Arduino Blueprints - Sample Chapter
Internet of Things With Arduino Blueprints - Sample Chapter
$ 39.99 US
25.99 UK
P U B L I S H I N G
Pradeeka Seneviratne
ee
pl
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
Sa
m
Pradeeka Seneviratne
Preface
Arduino is a small single-chip computer board that can be used for a wide variety of
creative hardware projects. The hardware consists of a simple microcontroller, board,
and chipset. It comes with a Java-based IDE that allows creators to program the
board. Arduino is the ideal open hardware platform to experiment with the world of
Internet of Things. The credit card-sized Arduino board can be used via the Internet
to make useful and interactive Internet of Things (IoT) projects.
Internet of Things with Arduino Blueprints is a project-based book that begins with
projects based on IoT and cloud computing concepts. This book covers up to eight
projects that will allow devices to communicate with each other, access information
over the Internet, store and retrieve data, and interact with userscreating smart,
pervasive, and always connected environments. It explains how wired and wireless
Internet connections can be used with projects and explains the use of various
sensors and actuators. The main aim of this book is to teach you how Arduino can
be used for Internet-related projects so that users are able to control actuators, gather
data from various kinds of sensors, and send and receive data wirelessly across
HTTP and TCP protocols.
Finally, you can use these projects as blueprints for many other IoT projects and put
them to good use. By the end of the book, you will be an expert in the use of IoT with
Arduino to develop a set of projects that can relate very well to IoT applications in
the real world.
Preface
Chapter 2, Wi-Fi Signal Strength Reader and Haptic Feedback, briefly introduces Arduino
Wi-Fi shield basics, vibration motors, and haptic feedback. You will learn how
to make advanced vibration patterns using vibration motors with a haptic motor
controller and the Adafruit haptic library according to the Wi-Fi signal strength
received by the Arduino Wi-Fi shield.
Chapter 3, Internet-Connected Smart Water Meter, focuses on building a flow
sensor-based water meter in conjunction with the Arduino Ethernet shield to
measure water flow rate and volume, and then display them on an LCD screen.
In addition, you will learn how to convert this water meter to a web server and
request readings through the Internet of Ethernet.
Chapter 4, Arduino Security Camera with Motion Detection, explains how to incrementally
develop a Arduino Ethernet shield-based security camera with the Adafruit TTL Serial
JPEG camera and the VC0706 camera library. In addition, you will learn how to add
motion detection functionality and upload the captured images to Flickr.
Chapter 5, Solar Panel Voltage Logging with NearBus Cloud Connector and Xively, briefly
introduces the NearBus cloud connector and Xively, while focusing on building a
solar panel voltage logger with the Arduino Ethernet shield with a few electronic
components. Also, you will learn how to log the output voltage of a solar panel in
combination with NearBus and Xively, and then display real-time data that can be
viewed through a web browser.
Chapter 6, GPS Location Tracker with Temboo, Twilio, and Google Maps, briefly
introduces the GPS shield and how to use the TinyGPSPlus library and the Google
JavaScript API library to build a real-time location tracker to display the current
location of the GPS shield on Google Maps. You will also learn the basics of Temboo
and Twilio cloud services.
Chapter 7, Tweet-a-Light Twitter-Enabled Electric Light, introduces Python, a more
powerful programming language that can be used to read Twitter tweets and write
data to a computer's serial port accordingly. Finally, you will learn to build an
electric light switch that can be controlled using Twitter tweets to turn the switch
on and off.
Chapter 8, Controlling Infrared Devices Using IR Remote, focuses on building an infrared
remote control with the Arduino Ethernet shield and a few electronic components
that can be controlled through the Ethernet or Internet to control IR-enabled devices
remotely. You will learn how to record and reproduce IR commands using the
Arduino IR remote library. In addition, you will learn how to add IR functionality to
non-IR enabled devices.
How to connect the Arduino GPS shield with the Arduino Ethernet board
How to install and use TinyGPSPlus library with the Arduino Ethernet board
How to extract location data and time with Arduino GPS shield in
conjunction with TinyGPSPlus library
About Google Maps JavaScript API that displays the current location on
Google Maps with GPS data
How to get GPS location data by SMS with Twilio and Temboo
[ 127 ]
Hardware requirements
products/10273)
Software requirements
[ 128 ]
Chapter 6
The Arduino GPS shield kit: Image taken from SparkFun Electronics Image courtesy of
SparkFun Electronics (https://www.sparkfun.com)
[ 129 ]
DLINE: This connects the GPS module's serial lines to the Arduino
software serial (D2 and D3). See the solder marks label next
to the UART/DLINE switch.
The Arduino GPS shield PCB: Image courtesy of SparkFun Electronics (https://www.sparkfun.com)
Chapter 6
3. Open the Arduino Serial Monitor by going to Tools | Serial Monitor. The
following output will be displayed:
In each entry, the current location is displayed with latitude, longitude, and
date/time. Next, you will learn how to use these values to display the location
on Google Maps.
[ 131 ]
The following steps will explain you how to display the Arduino GPS shield's
current location on Google Maps:
1. Open a new Arduino IDE and paste the sample code B04844_06_02.ino
from the Chapter 6 code folder. Verify and upload the sketch to your
Arduino Ethernet Shield or Arduino Ethernet board.
2. The code consists a mix of Arduino, HTML, and JavaScript. Let's look at
some important points of the code.
The latitude and longitude values should be replaced with the real
time returning values of the Arduino GPS shield as follows:
var myLatlng = new
google.maps.LatLng(gps.location.lat(),gps.location.lng());
3. Open your web browser and type the IP address of the Arduino Ethernet
Shield and navigate to the site. Read Chapter 1, Internet-Controlled
PowerSwitch, for information on how to find the IP address of your Arduino
Ethernet Shield. Example: http://192.168.10.177.
4. Your web browser will display your GPS shield's current location on the
Google Map, as shown in the following screenshot:
[ 132 ]
Chapter 6
The current location of the Arduino GPS shield is displayed on the Google Map with a marker icon
In the next section, you will learn how to send the current GPS location by SMS to
the client using Twilio and Temboo.
[ 133 ]
Fill out the form with the relevant information and then click on the Get Started
button. You will be navigated to the Human Verification page:
1. In this page, select your country from the drop-down list and type your
phone number in the textbox.
2. Click on the Text Me button. You will be navigated to the Enter Verification
Page. Meanwhile, your mobile phone will receive an SMS message
containing a verification code.
3. In the Enter Verification Page, enter the verification code and click on the
Submit button.
After successfully verifying your Twilio account, you will be navigated to the
Twilio Getting Started page. This means that you have successfully created
a Twilio account.
[ 134 ]
Chapter 6
ACCOUNT SID
AUTH TOKEN
You will need the ACCOUNT SID and AUTH TOKEN in the next section when
you connect your Twilio account with Temboo. However, the default account type
is a trial account with limited API calls allocated. If you want to get the full benefit
of Twilio, upgrade the account.
[ 135 ]
Twilio test API credentials: Test Account SID and Test Auth Token
In this page, under API Credentials, you can find the Test Account SID and Test
Auth Token to test your apps with Twilio.
[ 136 ]
Chapter 6
[ 137 ]
Chapter 6
5. Fill out the following textboxes with your Twilio API settings:
Body: You can type any text message here in order to test
From: Type Twilio Sandbox number (use your Twilio phone number)
To: The destination phone number (use your phone number that
associated with the Twilio account)
3. Save the B04844_06_03.ino sketch in your local drive inside a new folder.
Copy the code generated in the HEADER FILE section under the Twilio
SendSMS section, and paste it into a new Notepad file. Save the file as
TembooAccount.h in the same location.
4. Verify the sketch. If you get a compiler error indicating that the
TembooAccount.h header file is missing, restart the Arduino IDE and open
the B04844_06_03.ino sketch again and then verify. This will probably
solve the issue.
5. Upload the sketch into your Arduino Ethernet board.
6. You will receive the first SMS including the GPS location data from your
device. Wait for 30 minutes. You will receive the second SMS. You can
change the delay between SMS messages by modifying the following
code line as shown:
delay(1800*1000); // wait 30 minutes between SendSMS calls
The value 1,800 seconds is equal to 30 minutes. To convert the 1,800 seconds into
milliseconds, multiply it by 1,000.
Summary
In this chapter, you learned how to connect the Arduino GPS shield with Arduino
Ethernet Shield while displaying the current location using Google maps with
Google Maps JavaScript API. You also used Twilio and Temboo APIs to send
SMS messages with GPS location data to the user.
In the next chapter, you will learn how to build a garage door light that can be
controlled using Twitter tweets with the combination of Python and Python-Twitter
(a Python wrapper around the Twitter API).
[ 140 ]
www.PacktPub.com
Stay Connected: