In this article, you are going to build a weather measurement station that will automatically send data to the cloud using the Temboo service. When building home automation projects, we love to connect our devices together wirelessly and to the web, especially using WiFi. In my series of articles round the CC3000 chip, you discovered how to connect your projects to a local WiFi network, in a very “Do-It-Yourself” way. In this article, I will show you another approach using the Arduino Yun & Temboo.

Introduced in 2013 by Arduino, the Arduino Yun is a powerful Arduino board with onboard WiFi & a small Linux machine. Especially, it is really easy to interface with the web service Temboo, which is what we are going to use in this article. We will automatically send data to a Google Docs spreadsheet, which can be accessed from anywhere. Let’s dive in!

Hardware & Software Requirements

For this project, you will of course need the Arduino Yun board. You will also need a DHT11 (or DHT22) sensor, along with a 4.7K resistor, for humidity measurements. For pressure & temperature measurements, I used a BMP085 sensor on a breakout board, but you can also use the newer BMP180 sensor, which works with the same library. For light levels measurements, I used a photocell with a 10K Ohm resistor. Finally, I used a breadboard and some male-male jumper wires.

This is a list of all the components that were used in this project:

On the software side, you will need the Arduino IDE in the latest version (in Beta when this article was written). You will also need the DHT library, the BMP085 or BMP180 library, and the unified sensor library. To install a library, simply put the folder in your /libraries/ folder of you main Arduino folder. This tutorial also assumes that your Arduino Yun is already connected to your WiFi network. If you need help with that, please follow the dedicated tutorials on the Arduino website.

You will also need a Google account for the rest of the project. If you don’t have one yet, please create one, for example by going on the Google Drive page.

Hardware Configuration

The hardware connections for this project are actually quite simple: we have to connect the DHT11 sensor, and then the part responsible for the light level measurement with the photocell. First, connect the Arduino Yun +5V pin to the red rail on the breadboard, and the ground pin to the blue rail.

Then, connect pin number 1 of the DHT11 sensor to the red rail on the breadboard, and pin number 4 the blue rail. Also connect pin number 2 to pin number 8 of the Arduino Yun. To finish up with the DHT11 sensor, connect the 4.7k Ohm between pin number 1 and 2 of the sensor.

For the photocell, first place the cell in series with the 10k Ohm resistor on the breadboard. Then, connect the other end of the photocell to the red rail on the breadboard, and the other end of the resistor to the ground. Finally, connect the common pin to the Arduino Yun analog pin A0.

For the BMP085 or BMP180 sensor, connect the VIN pin to the +5V, GND to Ground, SCL to Arduino Yun pin number 3, and SDA pin to Arduino Yun pin number 2. The following picture summarises the hardware connection:





Testing Parts Individually

Before connecting the project to the cloud, we’ll test every sensors individually with a test sketch that simply uses the conventional Arduino part of the Yun. The first step in the code is to import the correct libraries:

#include "DHT.h" #include #include #include

We need to define the pin & type of the DHT sensor:

#define DHTPIN 8 #define DHTTYPE DHT11

And create the instances for the DHT sensor & BMP sensor:

DHT dht(DHTPIN, DHTTYPE); Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

In the setup() function, we can initialise the BMP sensor:

bmp.begin();

In the loop() part of the sketch, we make the different measurements, for example humidity, temperature & light level:

// Measure the humidity float humidity = dht.readHumidity(); // Measure light level int lightLevel = analogRead(A0); // Measure pressure & temperature from BMP sensor sensors_event_t event; bmp.getEvent(&event); float pressure = event.pressure;

These different measurements will then be printed on the Serial monitor. Of course, you can find the complete sketch on our GitHub repository for this project. You can now upload the sketch to the board & open the Serial monitor. This is what you should see:





If that works, it means all your hardware connections are correct, and you can move to the next part of the project.

Setting up Your Temboo Account

Before you can upload data to Google Docs, you need to have a Temboo account. Go over to the Temboo website and enter your email to start the account creation process:





You will also be prompted to enter an account name:





After that step, you will be asked to give a name to your first app, and you will be given an API key for your app. Please keep at hand your account name, app name, and API key, you will need them soon.

You will also need to follow a procedure to create a Google application, and at the end get a Google client ID, client secret & access token. The Temboo website explains this procedure very well, and you can find the whole procedure at:

https://www.temboo.com/library/Library/Google/Spreadsheets/

Putting Everything Together

It’s now time to build the software part of our project. First, we’ll do some configuration in Google Docs. Create a new spreadsheet in Google Docs, name it (I named mine “Yun”), and create the title of each columns in the first row, like the picture below:





Now, we are going to build the Arduino sketch. You need to import all the libraries for the Arduino Yun web & bridge functionalities:

#include #include #include #include #include #include

I also placed all my Temboo account information in a separate file, please make sure that you update your personal account information in this file:

#include "TembooAccount.h"

You also need to set your own informations about your Google account:

const String GOOGLE_CLIENT_ID = "your-google-client-id"; const String GOOGLE_CLIENT_SECRET = "your-google-client-secret"; const String GOOGLE_REFRESH_TOKEN = "your-google-refresh-token"; const String SPREADSHEET_TITLE = "your-spreadsheet-title";

In the setup() function, we start the Bridge between the Arduino part & the Linux machine with:

Bridge.begin();

We also start a date process, to automatically send the measurements date to Google Docs:

time = millis(); if (!date.running()) { date.begin("date"); date.addParameter("+%D-%T"); date.run(); }

In the loop() part, the most important line is:

runAppendRow(humidity, lightLevel, pressure, temperature, altitude);

Which calls the function to automatically send the data to the Google Docs spreadsheet. I won’t get into the details of these two functions, but of course you will find all the code in the GitHub repository of this project. The loop() of the Arduino sketch is repeated every 10 minutes with a delay() function, as these variables are usually changing slowly over time.

Finally, you are ready to test the project. Upload the code to the Arduino Yun board, open the Google Docs spreadsheet in your browser again, and wait a moment. After a while, the first measurement should appear:





I also used the built-in plotting functions of Google Docs to plot my data as it comes in. For example, I used the simple “Line” chart type to plot the light level. This is the result over some hours in the morning, showing that the light level is slowly rising:





And over the same period of time, I plotted the evolution of the temperature & humidity:





The really nice thing about this is that it is updated automatically as data comes in, and it can be accessed from anywhere: you just need your Google username & password!

How to go Further

You just learned in this project how to send measurements from your Arduino Yun board to Google Docs, so this data can be accessed from anywhere. You can of course improve this project in many ways. The first one is to add more sensors to the project, for example a wind speed sensor or a smoke sensor. You could even add an USB camera to store pictures on the Yun SD card.

You can of course use many Arduino Yun boards, for example in different parts of your home. You can also customise the email alert part: you can build more complex alerts based on the measured data, or set the project to email you the sensor data at a regular time interval. If you have other ideas to improve this project, please share! Note that you can find more applications built on this project, as well as 3 other exciting Internet of Things projects in my book Internet of Things with the Arduino Yun.