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
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 chainSeveral 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.
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 codeThe 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:
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 informationThe 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) variantIn 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.
Step 10: Conclusion and ideas for improvementThis 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 !