loading

Indoor Environmental Quality station +Bluetooth +Thingspeak

Picture of 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 !
 
Remove these adsRemove these ads by Signing Up

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

Picture of 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

Picture of 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

Picture of Thingspeak datalogging and visualization
screenshot new channel.jpg
screenshot API keys.jpg
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

Picture of 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

Picture of 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 !
diy_bloke8 months ago

great project. I agree on the reliability of the DHT11, sometimes it just jumps 4 degrees. I have it next to a BMP180 (pressure+temperature) and that in fact shos a much more stable output that is closer to what i actually measure with a thermometer

donmatito (author)  diy_bloke8 months ago

Thanks for the feedback and info. Will keep in mind

Just as illustration: the top left 'temperatuur' is from the DHT11. The blue line at the bottom right is the BMP180. They are right next to eachother. The DH11 is far off and is all over the place.

dht11-bmp.PNG
JakaK diy_bloke6 months ago

I suggest using dht22 rather dht11. Dht22 is still affordable but beter in accuracy

diy_bloke JakaK6 months ago

i could, but I got the BMP180 cheaper than the DHT22 :-)

Thanks for the great write up! Its awesome!
miguipda2 years ago
Hi, you just made a part of the project I thing to use. But I just discovered this board that could help all of us by allowing to have a Arduino (Due) on the main board on which a linux could be executed and then use it as a home server.
http://www.udoo.org/
http://www.udoo.org/features/
http://www.udoo.org/getting-started/

How to adapt your Indoor Environmental Quality station to implement it on a Arduino Due ?

Sincerely thanks and have a nice day,

Miguipda ;-)
donmatito (author)  miguipda2 years ago
It's cool, you could certainly consider the Arduino part similarly to mine, and use the linux part to implement web communication. Furthermore, you'd have local storage. So yeah, I think it is a great platform. But I have not considered how to implement it in details, sorry.
Ok.
Now a question.
Ok all of this allow us to get environmental information.
But how could we add the way to activate a fan during a time (allowing to change the delay) when a specifiv value arrived.
By example if the humidity level exceed a defined variable (60 or 70 or 80%) then the fan to extract the air to outside must be activated.
And we could also add for some other excess (like CO2, like T°).

Sincerely thanks.
donmatito (author)  miguipda2 years ago
I suppose a simple IF - read Arduino port on humidity - THEN - write the port commanding the fan, would do it ?

I am not sure I understand your problem. Is it on the power supply by the Arduino ? If yes, then you might want to use a transistor
Hi,

by considering the arduino is powered by solar system (then battery) we may consider the fan could be connected to the same battery with a normally closed relay but becoming open (allowing power) to power the fan.

But my more interesting question is to allow people who use your system to decide when the fan (or something else by using a relay) could be activated following the desired condition.

Example a variable always to 0. This variable will be changed following the desired condition. Then if I desire the fan could be activated if the humidity is higher than 70% OR the CO2 exceed another value then the initial variable will be set to a value that could activate the fan for a specific time. I means if I just activate the fan when humidity is higher than 70% then I want the fan switch on during 15min. But when humidity and CO2 exceed the limitation the fan must be switch on during 30 min. That means the initial variable (starting to 0) will be increment from 0 to 1, 2, ...) following the factor of duration the fan will be start on. Then the time will become 15 min (minimal value) * initial variation = duration of the fan is switch on then switch off and the initial variable set back to 0.

As I still did not tried using Arduino I do not know if this is possible.

Could you help us by creating this usefull tool ?

Sincereluy thanks and have a nice day,

Miguipda ;-)
donmatito (author)  miguipda2 years ago
Cool ideas ! They seem relatively easy to implement. However, I think you should try yourself ! Arduino is all about learning, and having a project is the best way to be motivated to learn.
Your project is amazing.!!
we can now reduce the cost of Wifi and update data on cloud via Smartphone.
I am also working on Home automation project using bluetooh and smartphone.

i will be incorporating your ideas in my device equipped with temperature and humidity sensors.!!

www.pluggx.weebly.com

Thank you
donmatito (author)  nikhilisalive2 years ago
Great! Happy to help. Keep a kit for me on the side for when you're rich and famous
iobridge2 years ago
Hi Don... great project! I posted this on the ThingSpeak blog - http://community.thingspeak.com/2013/05/indoor-environmental-quality-station/ - good luck!
donmatito (author)  iobridge2 years ago
Thanks man. The community was useful to me, happy to contribute back