Using this step-by-step tutorial, you will discover how to integrate Arduino and Google cloud platform. You will learn how to send temperature, pressure and other data to Google sheet using Arduino
This Arduino practical tutorial is a tutorial on how to integrate Arduino and Google cloud platform. In more details, this Arduino tutorial describes how to implement an Arduino sketch that sends data to Google Sheets.
This is a quite common scenario, where you have to send data acquired by Arduino to a remote IoT cloud platform. Let us suppose we have to monitor the room temperature and store these values somewhere in the cloud so that they can be elaborated later. This is a typical scenario where it is necessary to know how to send data from Arduino to the cloud. When it is necessary to send data from Arduino to the cloud there must be an IoT cloud platform that accepts these values and stores them. Usually, an IoT cloud platform exposes a set of API to simplify the data exchange process. The cloud IoT platform protects these APIs using an authentication mechanism. Therefore, it is necessary to implement all the code required on the Arduino side to accomplish the task of sending data to the cloud. There is another way of achieving the same result.
Using this guide about IoT with Arduino you can experiment, by yourself, the power of Arduino and how to connect it to Google cloud, building your first IoT project.
Quicky, in a few minutes and without knowledge of programming, it is possible to dive into the IoT and build an Arduino cloud data logger that uses Google Sheets to store data.
As stated before, this Arduino tutorial describes how to integrate Arduino and Google cloud. What will you learn?
You will learn:
- How to connect Arduino to sensors
- How to send data from Arduino to Google Cloud (Google sheets)
- How to use Temboo with Arduino
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 that uses Arduino and Google. The interesting aspect of Internet of things is that we can experiment IoT using simple development devices and existing IoT cloud platforms that provide services. It is not necessary to spend a lot of money to jump into the IoT ecosystem. The purpose of this project is building a cloud data logger that records the temperature and pressure and stores these values into Google cloud platform using Google sheet.
There are several scenarios where this Arduino project could be useful and it is necessary to connect Arduino to Google cloud. As stated before, we might want to track the temperature and the humidity of our room and store this information in a worksheet in order to elaborate the values somehow. Moreover, we could calculate the mean value of the temperature and the humidity during the days. We might want to plot these values using some charts. Therefore, this Arduino project has several applications and it is very useful. Nevertheless, it is a good starting point when you approach for the first time Arduino and how to use Arduino in IoT.
To integrate Arduino and Google cloud and 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.
Other useful resources
This Arduino programming tutorial has three simple steps to get the goal:
- 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 Cloud (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 how to integrate Arduino MKR1000 with Twitter using Temboo.
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 for this IoT project, it is necessary you have created a Google API project. Moreover, it is important to enable Google Sheet API in order to use this API with Arduino.
Once you have your project configured correctly using the Google cloud console, 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:
How to use Arduino and Temboo
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. By now you did not write a line of code. Just configuration as promised!
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 an Arduino 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.
This Arduino project, we are using a BMP280 sensor that measures temperature and pressure. However, it is possible to use other sensors too. You can connect all the sensors you like. This is just an example.
The wiring details are shown below:
The Arduino software code is very simple. This is only a little piece of code to use. Create a new Arduino sketch using your Arduino IDE (or any IDE you like) and add these lines at the beginning to read the sensor data:
#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();
If you want to optimize the way Arduino uses the battery without draining it fast, you can read this article describing how to manage device power in IoT.
Sending the data to Google cloud platform (Google Sheet)
The last step is sending the data acquired by the sensor to Google cloud platform. Therefore, we will use another Temboo choreo (AppendValue) under Google>Sheets.
After clicking on this choreo, Temboo shows a form where 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:
Once you have added all the information required, Temboo will generate all the code you need to integrate Arduino and Google cloud platform. Just writing a few lines of code you have implemented an IoT system that uses Google cloud API. It is necessary to modify the Temboo code adding the values read from the sensor, using the piece code previously described.
Finally, running 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 integrate 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. Configuring Google cloud platform, without much knowledge about IoT, you have developed your first IoT project.