Introduction
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. One solution is to use WiFi breakout boards or shields, for example using the CC3000 WiFi chip, connect it to an Arduino board, and build your own code for the WiFi communication & remote interface. 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 project. We will automatically send data to a Google Docs spreadsheet, which can be accessed from anywhere.
Page last edited March 08, 2024
Connections
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 simple breakout board, but you can also use the newer Adafruit BMP180 sensor board, 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.
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.
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:
#include "DHT.h" #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BMP085_U.h>
#define DHTPIN 8 #define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE); Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
In the setup() function, we can initialise the BMP sensor:
bmp.begin()
// 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;
If that works, it means all your hardware connections are correct, and you can move to the next part of the project.
Page last edited March 08, 2024
Setting up your Temboo account
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:
Page last edited March 08, 2024
Arduino sketch
Now, we are going to build the Arduino sketch. You need to import all the libraries for the Arduino Yun web & bridge functionalities. You can read more about starting out with Temboo & Yun here: https://www.temboo.com/arduino/yun/
These are all the libraries used in this project:
#include <Bridge.h> #include <Temboo.h> #include <Process.h> #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BMP085_U.h>
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() part of the sketch, we initialise the Arduino Bridge library:
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.
Page last edited March 08, 2024
Using the project
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:
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!
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 also saw how to build automated email alerts based on the data in your home. 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 an SD card, using the Yun SD card reader.
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!
Page last edited March 08, 2024