Saturday 15 February 2014

Ghetto Real-time Carbon Monoxide Data Logger

*This article is of course the ramblings of a hobbyist and not to be taken as fact. You do these things at your own free will. Free will is a great thing mind you…
Something a little different. I feel I have been concentrating too much on my ghetto fpv quadcopter development, and need to do something a little bit different for a while. I have a multifuel/woodburning stove in my house and I’m very happy with it. It’s a huge Morso stove like this one:
It was bought new, and was fitted professionally, and it works flawlessly. For this privilege, it set me back several thousand pounds. I don’t need to worry if the stove is damaged, old, worn, or if the flue pipe is leaking, and various other possible scary possibilities.
Anyway, a friend of mine earlier this year, decided they too would like a wood burning stove for their house. My friend is well travelled, and has lived in some strange places, and tiny remote villages. It is fair to say that he lives a somewhat alternate lifestyle now, and believes in political conspiracy, and corporate state control. To him, everything is a lie :)

So, he decided he was going to build a woodburning stove. He bought a second-hand stove on ebay for just over £150 pounds (it’s an old 4kw stovax brunel 1a – rrp £1250). The stove looks old, worn, and needs a new baffle plate & fire bricks.
Anyway, he bought a chimney flue kit and smashed in his chimney to build his own fireplace, scaled his own roof, cleaned the chimney, and fitted the flue himself. Amazing! I thought. But mad. His stove cost him a total of about £600 to buy, fit the flue, and do the building work on the chimney. Mine cost me about £5000.
We talked about the legalities about building your own stove, and it seems, as long as you follow some general guidelines, you can indeed build your own stove without relying on a company to do it for you. No matter if a Gas company comes knocking at your door telling you otherwise (It is suggested by my friend, that it is in the interests of British Gas to try to prevent you from building a stove, and seeking out any problem they can to enable them to stop you, so you have to rely on using gas). But my friend has been out in the woods too long perhaps?
Anyway, he wasn’t completely irresponsible it seems, as he bought a couple of carbon monoxide alarms and fitted one on each floor of his house. 2
      3Which led us to an idea….
We looked at these alarms, and read their instructions. It seems that what they do, is detect certain carbon monoxide levels, for certain durations. They are more of a ‘life saving’ device, than a device used for data monitoring.  It seems that health & safety guidelines suggest that you should not be exposed to carbon monoxide for durations explained below:

It seems that according to the alarms he bought, the instructions suggest that the alarm will trigger if exposed to a minimum of 30ppm of Carbon Monoxide for a period of 8-hours. So, you have to wait 8-hours for the alarm to even trigger for a low level. The alarms will only trigger immediately if levels of over 4000ppm are detected.

This worried my friend and me a little bit. What we were concerned with, was low-level poisoning and it’s effects. It seems low-level poisoning can damage brain function and repair, effectively contributing to a certain level of brain damage that might be not too dissimilar to excessive alcoholism and brain damage. This is what we concluded, after several strong pints of ale and some discussion.
What we wondered was how we could read low level ppm in real-time? Like on a graph?

The alarms he bought; one has an LCD display that, when the test button is pressed, will display the ppm reading. You also get a quick short blast of the alarm too, just for good measure. It seems that pressing the button every minute to record a ppm reading (with the added alarm sound blasting your ear) is a bit impractical. What we need is a device that can record ppm and log it every few seconds.
So, me, with my electronic skills, suggested I build something that does exactly that.

It seems, that in the Arduino prototyping platform, there is a range of common gas detecting sensors available which record anything from Methane (parp) & carbon dioxide; to smoke & carbon monoxide. These sensors come under the range of MQ(X) sensors. The X being a number 1-9 to the according sensor. You can read about them here.
They are available on ebay for a couple of quid. 1234
The MQ7 sensor that reads carbon monoxide in the range of 10-10000ppm can be connected to Arduino using only three of it’s four pins.
We can then write a program to read the sensor every, say 5 seconds and give us a ppm reading. Enough of these readings, and we can plot a graph to show how well the stove is working, if there is any damage to the stove, if there are any leaks, if someone opens a house door, if the fire is raging, or dying down. All these factors should affect low-level carbon monoxide readings in some way.

So, if we connected the MQ7 sensor to the Arduino Uno like in this diagram:

Then we upload this sketch to it >>>>> This Sketch
The sensor will print out ppm data every 5 seconds.
The code works like this:The sensor it seems, needs to heat up for at least three minutes to allow it to read data properly, so the sketch begins with the following text displayed in Serial Monitor: “Sensor Heating…” for 3 minutes until the sensor is hot enough. The Arduino then makes an initial sensor reading. This initial sensor reading is made at neutral ‘carbon monoxide free’ area – i.e. outside in the open air, or similar place. The arduino then makes another reading after 5 seconds have passed, then another after a further 5 seconds, and so on.
The arduino makes a calculation:
ppm reading = (5-second Sensor reading - Initial sensor reading) + 5
The ‘5’ value is used because it is assumed that a normal house will have a natural ppm reading of 2-5ppm.
It is also assumed that a house with a woodburning stove in it, will have a normal ppm reading of 7-15ppm depending on the type of stove, fuel burning used, ventilation etc.
Once we have the arduino set up and recording data, we can open the Serial Monitor and log data until we are happy:
As you can see, in my office, the readings are a normal 5ppm on average. When my wood stove is on, the readings increased to between 7-10ppm.

I decided to take the arduino round to my friends house to sample some data:
My friends stove readings were recorded over a 4-hour period. The readings went up to a high of 18ppm, and a low of 4ppm. During this period, doors were closed and opened – affecting projected room heat, and ventilation. When the door to the kitchen was opened, the reading would drop as there is a wall vent installed there.
The stove ppm would increase when the wood was burning fiercely, and the ppm reading would decrease as the fire died down to ashes -As you can see at the end of the data.
All very interesting!
In the future, I am going to repeat the sensor data recording, and use readings from the monoxide alarm that has an LCD as a comparison.
Also, in the future, I will blog a tutorial that will record the sensor data remotely over wireless Ethernet, and I will be able to view the graph in real-time using a web browser. Now this is an exciting idea.
In the mean time, feel free to have a play with the existing code, and try your own calibration experiments.

Listen to this too:

Data Logging Information:
The setup above is simple. You simply run the sketch, open Serial Monitor on your computer, collect the data, ctrl + A to select all data, ctrl + C to copy, then paste it into excel or wherever.

Saving the data to a file.
If you have a serial terminal program like CoolTerm on your computer, you can also capture to a file. To do so, open CoolTerm, and choose your serial port in the Options menu. Click the Connect icon, then from the Connection Menu, choose Capture to TextFile… and Start. Give your file a name and save.
Note: if you want the file to start from the beginning of your sketch, hold down the reset until you’ve started capture.
To stop capture, choose Connect > Capture to TextFile… > Stop. Then you can use your file in any application you want. Change the file extension to .csv and you can open it in a spreadsheet and graph as above.
Saving Data to a micro SD Card.
Sometimes you want to save data when you’re not connected to a personal computer. Attaching a micro SD card to an Arduino is fairly straightforward. There are several different shields that have SD cards on board, and the Arduino Ethernet has a micro SD card on the board. The SD card library makes it simple to save files to the SD card.

Insert a freshly formatted micro sd card into your Arduino Ethernet Shield. Attach the Ethernet Shield to the Arduino Uno, connect the MQ7 sensor to the three pins (5v, GND, A0), then upload the MQ7_SDCardDataLogger sketch. This sketch reads the MQ7 sensor, and if there is an SD card present and initialized, it saves the results to a file called “DATALOG.CSV”. Transfer this file to your computer and use it as you wish. You can open it in a spreadsheet and graph it as you did above, or anything else you wish. If you just want the raw data, and no text ("ppm" "sensor heating" etc) use this file. It will take a sensor reading from the moment the logger is switched on, every 1 second, which will show how as the sensor heats up, the value quickly drops then levels out:

You can use this to make your own calibration ideas, to obtain 'true' ppm values. 

Adding an LCD display & RTC Clock to this would pretty much make a complete device. Maybe I'll update this in the near future.
Saving Data online to Plotly.
If you have an Arduino ethernet shield, you can upload your data directly to Plotly in real-time. You may have heard buzzwords such as 'The Internet of Things' or 'Big Data' recently, and this is one example of this quest for finding new data about our lives. Anyway, Plotly will save your data, and allow you to make and format a graph style so that any data will be loaded into it automatically. It will even record the time that the reading was made (very handy to know without carrying a stopwatch or using a real-time-clock in your circuit). My tutorial is coming soon, but in the while we wait have a look at this tutorial so you can get to grips with using Plotly.
You can also extend the use of the Ethernet Shield with Plotly, by making it wireless. Devices like the TP-Link TL-WR702N, and this other even cheaper ebay device, can be set up as a wifi repeater, and it's Ethernet port connected directly to the Arduino. It makes this a very cheap wireless solution to send data to Plotly (considering the price of the official arduino wifi shield £80?!). You can even wirelessly tether the cheap ebay router with a mobile phone and use the 3g/4g signal, meaning you aren't even limited to house wifi connections. There are also some low-cost mini pocket routers which also connect with 3g usb dongles. There's some really neat possibilities for sensor-based data gathering. Want to collect emissions data on your local road? Or perhaps logging potential local fracking emissions? Have fun and if you think this is cool:

1 comment:

Horatio Thomas said...

Wow, this is mind blowingly interesting. Any recs for a good data science platform that can be used by the man at home, not just big companies...