Вы находитесь на странице: 1из 9

Getting Started With IoT Using an Arduino

and Google
Let's build a simple IoT system that sends sensor data to Google Sheets via an
Arduino with a helping hand from the Temboo IoT cloud platform.

Acknowledgments to Francesco Azzola

Getting started with the Internet of Things using an Arduino and Google helps us to explore
this new technological revolution. This tutorial describes how to experiment Internet of things
using Arduino and Google. IoT is one of the most important technological trends nowadays.
In this post, we want to explore how to build an IoT project using Arduino and Google.

The interesting aspect of IoT is that we can experiment using simple development boards and
existing cloud platforms that provide some services. It is not necessary to spend a lot of money
to jump into the IoT ecosystem. The purpose of this project is building an IoT system that
records the temperature and pressure and stores these values into Google Cloud Platform using
Google Sheets.

During this project, as said, we will explore how to build an IoT project using Arduino and
Google and how to integrate them. To help Arduino send data to Google Sheets, this IoT project
uses Temboo. This is an IoT cloud platform that provides several integration services that
simplify the process of integrating different systems.

To build this IoT project using Arduino and Google, we have to follow these steps:

1. Authorize our device using OAuth 2 and get the token to exchange data with Google
2. Connect the sensor to the Arduino
3. Send the data to the Google sheet using Temboo

Authorizing Your Arduino Using OAuth


In this first step, we have to authorize our Arduino board to send data to Google using OAuth

(OAuth 2 is an authorization framework that enables applications to obtain limited access to user
accounts on an HTTP service, such as Facebook, GitHub, and Digital Ocean. It works by delegating
user authentication to the service that hosts the user account, and authorizing third-party applications to
access the user account. OAuth 2 provides authorization flows for web and desktop applications, and
mobile devices.)

2. To simplify this authorization process, we will use Temboo that provides a set of services to
get the OAuth token. We have covered the Temboo platform several times, building interesting
IoT projects along the way.
During this step, we assume you have already a Google account so that you can access
the Google Developer console. Before digging into the details about exploring IoT using
Arduino and Goole, it is necessary to have a Google API project.

Moreover, it is necessary to enable the Google Sheets API. Once you have your project
configured correctly, you should have a Client ID and a Secret key. These two keys are very
important, and we will use them later during the project. The final result is shown in the picture
below:

Now it is time to focus our attention on Temboo. If you do not have a Temboo account, go to
the Temboo homepage and create it for free. Once you have an account, log in and select the
OAuth 2 service on the left side of the menu.

Select on the left side of the menu, then the Initialize OAuth item under Utilities>
Authentication > OAuth2 and fill the form as shown in the picture below:
The Client Id is the one you get from Google as shown in the step above. Now click on the Run
Now button and wait for the response. If everything goes well, you will get the result you are
looking for:

This result is very important because we will use these values later. Now, you have to enable
access to Google Sheets. For this purpose, in your browser, copy and paste the first value, the
URL shown above. You should see an authentication request sent by Google and then a blank
page. It is almost done. The last step is using Finalize OAuth as shown below:
The CallbackID value was retrieved in the step above. That’s all. Now if you click on Run
Now, you get the token we will use during the project:

Now we have our token to use in the API calls.

Connecting a Sensor to Your Arduino


This is the easiest step, we simply have to connect a sensor to the Arduino. In this example,
we will use an MKR1000 board, but you can use an Arduino Uno with a Wi-Fi shield. It is
important to note that the board must be compatible with Temboo. The schematic is shown
below:

The code is very simple.

Add these lines at the beginning:

#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

Then, to read the values, you have to add:

float temp = bme.readTemperature();


float pressure = bme.readPressure();

That’s all.
Sending the Data to Google Sheets
The last step is sending the data acquired by the sensor to Google. For this purpose, we will
use another Temboo choreo called AppendValue under Google > Sheets. In the form you get
after clicking on this choreo, you have to add the required information, such
as ClientId, Token, and so on as shown in the picture below:

If you are wondering where you get the SpreadsheetID, you can get it from the URL when
accessing the sheet from your browser:
Now you can click on the Run Now button and get the code to use.

Just by writing a few lines of code, you have implemented an IoT system that uses the Google
Cloud API. The code you get from Temboo has to be modified by adding the values read from
the sensor using the code shown previously.

Now if you run the sketch, you will see that Arduino starts sending data to Google Cloud:

Summary
You have built an IoT system and explored how to get started with the Internet of Things using
Arduino and Google. Writing a few lines of code, you have built an IoT system that sends data
to Google Sheets. The interesting part of this project is the way you have implemented
it. Getting started with the Internet of Things using Arduino and Google is very simple, and by
just configuring a few cloud platform components, without much knowledge about IoT, you
have built your first IoT project.

---ALL THE BEST---


Getting Started with IoT Mode
IoT Mode allows you to easily generate code for a range of embedded hardware. Here we'll
walk you through how to use IoT Mode so that you can build your own smart devices. Want a
washing machine that texts when the laundry is done? Plants that tell you and Twitter when
they need water?

In this example we'll use Temboo to have our Arduino send an email through Gmail. We're
using an Arduino Uno with an Arduino Ethernet shield, but the process is the same for any
supported board with internet connectivity. If you want to follow along, you'll need an Arduino
or Arduino-compatible board and a way to connect it to the internet.

You can learn more about how other supported boards and shields work with Temboo on the
Hardware page.

Get Started

1First, make sure that you have the latest version of the Arduino IDE.

2Next log in to Temboo. If you don't have an account, you can create one.

3You'll also need a Gmail account, which you can create.

Entering IoT Mode

4Go to the Google > Gmail > SendEmail in our Library.

5At the top of the page you'll see the IoT Mode switch. Click to turn on IoT Mode. You'll see
that a menu with hardware options has appeared.

6Select the board and how it's connected from the hardware dropdown menus. We're using
the Arduino Uno with an Ethernet Shield.
7When the Arduino Ethernet shield is selected, a shield popup window will appear. Name your
shield, specify the kind of shield and add the MAC address identifying your shield. You can
often find the MAC address by looking at the back of your shield. When you press Save, the
shield will be added to your profiles so that you can use it later.

RUN THE CHOREO

8Fill in the required inputs with your Gmail account details as shown in the screen shot
below.
9You should see "success" in the OUTPUT section, and if you sent the email to yourself you
should see a new email in your inbox.

SETTING CONDITIONS

10If you'd like the Choreo to be triggered by a sensor event, or if you'd like the Choreo result
to trigger an actuator event, you can specify conditions above and below the Choreo inputs and
we'll generate the application logic you need.

USING THE CODE SNIPPETS

11Scroll down the Choreo page to the CODE box. Copy the code snippet and paste it into your
Arduino IDE.

12You'll also need to create the header file for your sketch, where your Temboo account
credentials and shield information are stored. Create a New Tab in the Arduino IDE and call
it TembooAccount.h.

13Scroll down the page to the HEADER FILE box. Copy and paste it into the
TembooAccount.h tab.

14That's it, now your code is ready to upload! Once you upload the sketch to your board, open
the serial monitor and you should see the email has been successfully sent. Check your inbox
again and you'll see that you've received the second test email.

What Next?

Now that you know how to use IoT Mode, you're ready to connect your hardware to 2000+
processes in the Temboo cloud.

_________________________________________________________________________________

Вам также может понравиться