Getting started with IoT using Arduino and Google cloud platform helps us to explore the new upcoming technological revolution. This tutorial describes how to experiment IoT integrating Arduino and Google Cloud. IoT (aka Internet of things) is one of the most important technological trends nowadays. In this post, we want to explore how to build an IoT project utilizing Arduino and Google. The interesting aspect of Internet of things is that we can experiment IoT using simple development boards and existing IoT 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 sheet.
During this project, as said, we will explore how to build an IoT project based on Arduino and Google cloud and we will analyze how to integrate them. To help Arduino to send data to Google sheet 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 based on Arduino and Google, we have to follow these steps:
- Authorize our device using OAuth 2 and get the token to exchange data with Google
- Connect the sensor to the Arduino
- Send the data to the Google sheet using Temboo
Integrating Arduino and Google cloud platform using OAuth
In this first step, we have to authorize our Arduino board to send data to Google cloud platform using OAuth2 mechanism. To simplify this authorization process, we will use Temboo that provides a set of services to get the OAuth token. We have covered Temboo platform several times, building interesting IoT projects.
During this step, we assume you have already a Google cloud account so that you can access the Google Developer console. Before digging into the details of using Arduino and Goole cloud IoT project, it is necessary you have created a Google API project. Moreover, it is necessary to enable Google Sheet API in order to use the Google API. Once you have your project configured correctly, you should have a Client ID and Secret key. These two keys are very important and we will them later during the project. The final result is shown in the picture below:
Now it is time to focus our attention on the 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, the InitializeOAuth 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 cloud platform as shown in the step above. Now click on the 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 the access to Google Sheet. 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 FinalizeOAuth as shown below:
where the CallbackID value was retrieved in the step above. That’s all. Now if you send the request, you get the token, we will use during the project:
Now we have our token to use in the next API calls.
Connecting the sensor to Arduino
This is the easiest step, we have simply to connect the sensor to the Arduino. In this example, we will use a MKR1000 board, but you can use an Arduino Uno with WiFi shield. It is important to notice 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();
Sending the data to Google cloud platform: Google sheet
The last step is sending the data acquired by the sensor to Google cloud platform. To 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 all the information required 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 Run now button and get the code to use.
Just writing a few lines of code you have implemented an IoT system that uses Google cloud API. The code you get from Temboo has to be modified 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 the Google Cloud:
At the end of this post, you have built an IoT system and explored how to get started with IoT integrating Arduino and Google cloud. Writing a few lines of code, you have built an IoT system that sends data to the Google sheet. The interesting part of this project is the way you have implemented it. Getting started with IoT using Arduino and Google is very simple, just configuring a few cloud platform, without much knowledge about IoT, you have built your first IoT project.