Getting started with Internet of things using Arduino and Google helps us to explore the new upcoming technological revolution. This tutorial describes how to experiment Internet of things using Arduino and Google. 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 using Arduino and Google. The interesting aspect of Internet of things is that we can experiment IoT 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 sheet.
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 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 using 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
Internet of things using Arduino and Google: Authorize Arduino using OAuth
In this first step, we have to authorize our Arduino board to send data to Google 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 account so that you can access the Google Developer console. Before digging into the details about exploring Internet of things using Arduino and Goole, it is necessary you have a Google API project. Moreover, it is necessary to enable Google API Sheet 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 as shown in the step above. Now click on 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 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 click on run now button, 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 sheet
The last step is sending the data acquired by the sensor to Google. 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 Internet of things using Arduino and Google. 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 Internet of things 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.
|Published on Java Code Geeks with permission by Francesco Azzola, partner at our JCG program. See the original article here: Getting started with Internet of things using Arduino and Google|
Opinions expressed by Java Code Geeks contributors are their own.