Introduction: Indoor Environmental Quality Station +Bluetooth +Thingspeak

This Instructable describes an station to measure Indoor Environmental Quality (IEQ). This is a measure of comfort that is impacted by several factors such as
  • indoor weather including temperature, humidity (pressure would have been possible as well)
  • noise level
  • indoor air quality.
The initial goal of this project was to monitor IEQ in my baby's room. However, such an IEQ station can be used for various applications, such as checking if all your rooms are well-ventilated and with proper temperature regulation. And I'll show a variation that you can take outdoor to make a weather station !

Such a project is composed of several steps, a chain along which the information is carrier over different platforms, from sensors to user interface. Although there are plenty of tutorials on internet, I found that they tended to focus on one step or the other. Therefore with this Instructable, my goal is to show how these different bricks fit together from A to Z.

I hope it'll inspire and help you build your own project. As always - if you like this Instructable, Votes, Favs, and Comments are much appreciated !

Step 1: Environmental Datalogging Information Chain

Several steps are to be considered for a datalogging project. The logical chain is :

1) Sensors: which values are of interest, which sensor to choose ?
2) Platform: where are the sensors connected?
3) Logging: where is the data stored?
4) Communication: if the answer to 3) is not "locally", then how is the data transmitted?
5) Display: how is the data presented to the user in an understable form?

The next steps cover these questions and show the answers I have implemented :

2) Platform : Arduino
3) Datalogging on Thingspeak
4) Variation a) Communicating in direct serial communication to the computer, with USB cable
     Variation b) Bluetooth communication with computer
     Variation c) Bluetooth communication with android smartphone
5) Web display from Thingspeak

Step 2: Arduino and Sensors

As far as the platform is concerned, an Arduino Uno was a no-brainer. Cheap, easy to prototype with a breadboard, and dead simple to program.

Sensors, however, are a tougher choice. They range from low-end, cheap kind from eBay, to more expensive gear from specialized websites. My project was all about learning/testing, so I went for diverse but cheap sensors. It was fine for me, but I don't recommend it if you're planning to get the most out of your IEQ station. A few euros more can make a real difference in terms of reliability and usefulness !

Anyway, here is what I used, including prices from supplier www.robotshop.com/eu. Of course, feel free to adapt to your personal needs, the various codes in the next pages are very flexible in terms of data sources.
  • Temperature sensor TMP36 is from Arduino starter pack. Very good sensitivity, sufficient in this context.
  • Temperature and humidity sensor DHT11 (4.46€). The humidity sensor captures trends (ie, goes up when one blows in its direction) but I wasn't able to calibrate it against another reference. The temperature part, however, is weird and unreliable. The TMP36 is much better at this job. One could also consider the DHT22, 9.95€, hopefully of better quality.
  • Luminosity: standard photoresistor from Arduino starter box. Sufficient in this context.
  • Ambiant air quality: Seeedstudio VOC (volatile organic compounds) sensor (14.26€), detecting molecules such as formaldehyse, alccol, etc... I haven't been able to calibrate it against a known reference, nor have I separately measured the effect of each pollutant. However, I have found the variations when people enter/leave the room quite impressive.
The next step here will be to test whether it can detect lack of ventilation in a room full of Ikea furnitures, which release formaldehyde.

  • Ambient noise: I tested both the DFRobot (6.67€) and the Electronic brick (1.87€). Both based on the same sensor, but with additional components for filtering on the DFRobot one. The sensitivity of these sensors seems to low to pick "ambient noise" up, as opposed to sudden loud noise. The DFRobot does a slightly better job at it.

Step 3: Wiring

Here is the wiring schematics, corresponding to the code in the next page. Sorry for the inaccurate depiction of the sensor looks, the one I used are not available in Fritzing

Step 4: Arduino Code

The attached code does the following actions :

- it loads the library for the DHT11, which can be downloaded here

- in the loop section, every 30s, it reads the sensors 5 times, and average the values. For sound sensors, it seemed to me more relevant to use the maximum value instead of an average. Feel free to change it if it doesn't feel right for you.

- then, it writes on the Serial port a line composed of the following grammar :

( "Name of a variable" + "," + "Value of the variable" + ";" ) for all variables then line break.

This grammar (as well as the names of the variables you want to use, depending on your setup) will be carried over in the next steps of the chain, when "something" reads from the Serial port.

We'll find out what can be this "something", but first, let us talk about datalogging.

Step 5: Thingspeak Datalogging and Visualization

Thingspeak is a great datalogging service, with the aim of enabling the "Internet of Things". While there are other similar services out there, Thingspeak is dead simple to set up and perfectly suited for this project's needs.

After creating a Thingspeak acccount, one then creates a new "Channel" in which one can define all the variables it needs. The important point to notice there is the field numbers in the "Channel" tab. These are going to be used in the next step.

The second important point is the API Key, which can be found in the appropriately named "API keys" tab.

The way to upload data into your Thingspeak Channel is as simple as openning a URL. The documentation describes the full-fledged GET and POST commands, but the URL is a simpler version. If the API key is ABC123456789, the URL to update the field 1 and 2 with values 10 and 20 is the following:
"http://api.thingspeak.com/update?key=ABC123456789&field1=10&field2=20".

You can type such a URL in a browser to see the effect on your Channel, but of course the datalogging will require that we generate these calls automatically.

You can see in the screenshot that it also serves as a web-based visualization tool (private or public). Actually, one could push this Instructable one step further and use GET commands to retrieve and use the data (for analysis or else), but I chose to limit myself to this web visualization.

Step 6: Transmitting the Information

The following step is the connecting link between "my Arduino sends data on the Serial port" and "Thingspeak receives the data and updates a pretty chart".

This link can be many different things. I tried 3 variants
a) Directly over USB cable to a computer, read with a Processing code
b) Over Bluetooth to a computer
c) Over Bluetooth to a smartphone.

Other options I did not implement
- Wifi (shield too expensive)
- Storage on SD Card then transfer (too manual)

Step 7: USB to Computer (Processing) Variant

In this version, a Processing sketch simply listens to the Serial port, and aggregates data into a URL whenever the Serial port has data.

Then, it opens the URL, which triggers Thingspeak update.

Notice the two important fields which link Arduino and Thingspeak :
labels[] corresponds to the variable names defined in your Arduino code
fields[] corresponds to the field numbers in the Thingspeak Channel.

The API key and these fields are the only things to modify to adapt to your project.

Step 8: Bluetooth to Computer (Processing) Variant

In this variant, both the Arduino and Processing code are the same. Changes are on the hardware side : adding a Bluetooth module to your station, and a Bluetooth dongle to your computer as well if it is not already equiped with one. Also, adding a 9V battery, since the station will not be powered from the cable.

I would advise people like me who are not soldering since they are 3 years old, to go for a BT module on a breakout board. Typing "HC-05 Bluetooth Transceiver" on eBay will lead to you 10-15€ modules, shipping included from China.

One headache I had with mine, was that most breakout boards are wired so that the Rx pin of the module is to be wired to the Tx of the Arduino, and Tx to Rx. Mine was Rx Rx and Tx Tx - took me a while to figure it out.

When you plug the battery in, your computer can detect it (look for HC05 name). Connection password should be given by the supplier, but it is usually 1234 or 0000. A COM (Serial) port should be openned, which is the serial port to use in Processing.

A second headache, with Windows 7, is that the computer may not be able to communicate on this port. A solution for me was to "forward" the Bluetooth COM port (say COM10) to another virtual port (say COM4) using VPSE. The new port (COM4) can now be read in Processing. I don't know why it works !

Step 9: USB to Smartphone (Android) Variant

In this last variant, we are going to use an Android smartphone instead of a computer to act as the transmission wheel, between the Arduino station, and Thingspeak. In my personal case, the main rationale for this solution is that our home computer is a bit noisy, and we don't want to leave it active during the night. But more interestingly, in means you can take your IEQ station to the field  and turn it into a weather station !

So what's in this app ? I tried to comment the code as much as I could, but here are a few higlights.

  • The user interface is very basic - a text area to confirm the Bluetooth status, a list of BT devices detected, and a second text area where the data read from the Serial port will be displayed.
  • The main Activity UploadThingspeakAppActivity activates BT if not activated already, searches for BT devices in range, display them in a list.
  • When a BT device is selected, it creates a socket, using an identifier called UUID (for a Serial port, the UUID to use is 00001101-0000-1000-8000-00805F9B34FB)
  • The connection is managed in a separate Thread, ConnectedThread. This is is a recommended practice to avoid freezing the application. The instance of ConnectedThread is responsible for all the communication tasks with both the IEQ station and Thingspeak.
  • It connects to the socket and listens to the communication, character by character. When reaching end of line, it forms the URL required to update Thingspeak, and opens it. Notice how the fields String labels[] and String fields[] make the link between the Arduino code and your Thingspeak Channel, in the same way as in the Processing code.
  • The Manifest files requires the permissions to use the smartphone Bluetooth and Internet functions with

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET"/>

  • One last point : the user interface is kept open with android:keepScreenOn="true" in the layout. This prevents Android from pausing the application and cutting the connection. Note that switching to another application also shuts down the connection.
And of course, it is preferable to keep the phone connected to the charger while in use, because Bluetooth + Screen always On drains the battery ultra-quickly !


Step 10: Conclusion and Ideas for Improvement

This is the end of this Instructables. I want to credit in particular two tutorials which inspired and helped me

Arduino to Processing weather station by Larsi
Bluetooth Serial port communication on Android by Nononux

There are many other ideas that could be implemented in such a project, such as Wifi connectivity, SD card data saving, data analysis, etc...

One of the most critical would be energy saving, because 9V batteries are drained pretty quickly. I tried to implemented the Sleepy function from JeeLib library, with little success. It saves energy by turning off the UART (serial) port which messes up the communication when restarting. I am open for suggestions and enlightments from my estimated readers !

Instructables Green Design Contest

Participated in the
Instructables Green Design Contest