Please see the project logs for extensive documentation! The code and all schematic/design files are available on GitHub (see link on the left side). Please also watch the demo video!
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
Please see the project logs for extensive documentation! The code and all schematic/design files are available on GitHub (see link on the left side). Please also watch the demo video!
Before we start, go watch the video that summarizes this whole project.
Some thoughts I want to share with you before the end of the contest. Working on the project for the passing weeks was a great experience and I'm very pleased with the results. Looking back at my original list of things I wanted to achieve with the project (go, read it yourself), I see that I can check all the boxes. While there are still some things to improve I feel that the project stands on solid grounds.
The contest has also been a great learning experience for me. Despite the fact that I have already done a couple of projects I encountered a couple of firsts, including that I
I also immensely enjoyed the documentation and I will clearly revive my website in the next weeks and continue documenting my projects there and here on hackaday.io.
As for the next steps, I will work a bit more on the software and on understanding the gas sensor. When this is done I will do a redesign of the board and build a custom case for the SniffingTrinket.
If anything at all I hope that people will use this project and the documentation to learn and start building their own cool stuff.
Just a very short post concerning the main firmware. You can find the sketch in my GitHub. There are two sketches, CalibrateSniffingTrinket.ino for the calibration of the MQ135 sensor (see last post) and SniffingTrinket.ino as the general purpose sketch. You need a couple of libraries to get the sketches running:
Just install the libraries, compile the code and upload it to the trinket. I won't go much into details of the code, as the code itself is heavily commented and you should be pretty easily able to understand it. I will just give quick overview of the main loop of the SniffingTrinket.ino
At the beginning of the loop the sensor values are read out.
// Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius float t = dht.readTemperature(); // Read temperature as Fahrenheit - in case you still don't use the SI //float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // Read out the Gas Sensor float ppm = gasSensor.getPPM();
The next step is setting the LEDs to the correct color value. This is done by calling a dedicated function for each LED.
// Set the LEDs accordingly setLedOutput(t, TEMPLED); setLedOutput(h, HUMLED); setLedOutput(ppm, AIRLED);Check if we have to sound the alarm
// Check if the alarm level has been reached
if(t > TEMPALARM ||
h > HUMALARM ||
ppm > CO2ALARM)
tone(ALARMPIN, 5000, 1000);
or if the button has been pressed.// Read if the button was pressed buttonState = digitalRead(BUTTONPIN); if(!buttonState) setMode();Thats about it. Now we just output some text to the serial/USB keyboard interface and redo this, forever (or till the batteries run out).
Have a look at the code and let me know if there is something that needs to be qualified. I have still some things in mind I want to change on the code, so have a look at the repository now and then!
This is the first of two logs about the software needed for the SniffingTrinket project. Because I guess that a general Arduino library for the MQ135 might be of use for other projects, I decided to split the software in a dedicated library and a sketch specifically for the SniffingTrinket. So, this is solely about the MQ135 lib, which, btw. you can find in my GitHub.
First, some theory: My interest in those cheap gas sensors was sparked by a video from Ben Krasnow who takes a look at a cheap breathalyzer with a very similar sensor. He links a paper in his blog post that goes into the theory of the operation of these sensors. In short, they consist of a heated piece of tin dioxide (doped with other stuff) that changes resistance as it reacts with the ambient gas (the heat accelerates the chemical reaction). There are several versions of these sensor, sensitive to several gas types. However, no sensor material is sensitive to a single gas only! I did some more research and found in principle two sensor of immediate interest to me: The MQ135 for "air quality" and the MQ811 for CO2. The MQ811 is much more expensive (30$ compared to 3$).
The datasheet claims that the MQ135 is sensitive for CO2, Alkohol, Benzene, NOx, NH3 and the Fig 3 shows the change in resistance depending on the concentration of these gases in the ambient air in ppm (of the total gas volume). It turns out the the general sensitivity is the roughly same for all the gases. This is where you think: Wait a minute! CO2 is the 4th most abundant trace gas in the earths atmosphere with about 400ppm concentration (N2, O2, and Ar are on place 1-3). All of the other gases the sensor detects are much less common than CO2 and luckily so, as they are harmful. This means, in a normal atmosphere the sensor mostly detects CO2 and with the right calibration we can use it as a cheap replacement for the MQ811 (which by the way is also sensitive to other gases). Turns out, somebody already hat a go at this: I will leave you with great explanation of David Gironi for the details, but mostly he just extracts data from the figures in the datasheet, throws some math at the problem and cross-checks the results with a different kind of sensor for CO2.
The Library I have written basically just implements his approach for the Arduino. It's pretty easy to use. Copy it to your Arduino library folder and put
#include "MQ135.h"
MQ135 gasSensor = MQ135(ANALOGPIN);
to your sketch. ANALOGPIN is the ADC input for the sensor readings (refer to the post with the SniffingTrinket schematic for explanation).
Before you can use the sensor, it has to be calibrated. For this, connect the sensor to your circuit and leave it powered on for 12-24 h to burn it in. Then put it into outside air, preferably at 20°C/35% rel. hum. (humidity is not so crucial). Read out the calibration value as such
float rzero = gasSensor.getRZero();
Wait until the value has somewhat settled (30min-1h). Remember, this is an ADC measurement so you might not want to wait some time between reading the sensor and also do some averaging. Once you have determined your RZero, put it into the MQ135.h. Note: Different sensors will likely have different RZero!
#define RZERO 76.63
float ppm = gasSensor.getPPM();
The library also provides functions to apply the temperature/humidity correction that is shown in Fig 4 of the datasheet, but I do not trust the datasheet there, so this should not be used for the moment.If you want to know more, look at the code. I tried to make it very readable and self explaining and provided lots of comments. If you do not understand something, ask: I will happily explain it.
The contest comes to an end and I am tying up some loose ends - one of them the power supply.
The Sniffing Trinket is intended for indoor air quality monitoring and with this in mind as well as the knowledge that USB plugs are a common sight everywhere these days, a USB port or wall plug is probably the first choice for the power supply (come on, even most cars now have a USB power supply).
However, as this is not truly EDC and there might be situations where you want to monitor the air quality and you don't have a USB power supply, there is also an alternative battery power option.
Instead of designing my own solution I decided to go with a module you can buy pretty cheap: Just put "5V USB step up" into ebay or alibaba or any other site and you get those modules for about 1 Euro (1.5$) in single quantity delivered. You can't build something like that cheaper yourself. These modules take anywhere from 1V to 5V input and put out 5V with up to 600mA - perfect to power your little gadget. I haven't tested them properly but I suspect (from my own painfull experience with step-up converters) that they are not that efficient - but they should be good enough to power the SniffingTrinket for a couple of hours from 2 AA batteries. Additionally, the modules are small, about the size of a USB connector. So here is how to build one:
You need
Construction is pretty simple. Just solder the red wire from the battery clip to the + pad on the step up converter board and the black wire to the - pad (if you just use wires, connect them to the battery holder with the correct polarity). Connect the clip to the battery holder. Put in the batteries. I additionally glued down the step up converter board to the battery holder.
You can now connect the SniffingTrinket via a USB cable. I only have very long and stiff ones (therefore you can't see the whole cable), but you can get a smaller, more flexible one.
Alternatively, you can also desolder the bulky full size USB connector from the converter board, cut the board a little bit and run you own wires to the Trinket.
Congratulations, you can now monitor the air quality in the mines of Moria!
Hey all,
a couple of small updates from me. I have been heavily working on the project for the past couple of days and fighting with some annoyances. Good news is, I have them mainly fixed and at the moment I am preparing a "first (stable) version" of the project to be ready for the end of the contest. However, development will go on after that (although maybe somewhat slower).
I uploaded the first bunch of files containing all the hardware files (schematic, Gerbers) needed for KiCad and the MQ135 arduino library I created (more on that later) to github. The source code for the trinket will follow soon. The links to the repository are on the main project page on the left side.
As sort of a late christmas present to people interested in the project I decided to give away some of the Rev 0 PCBs I ordered . I got 10 PCBs made of which I won't need all for prototyping, so I decided that 5 of them are up for grab on a first come - first serve basis. There are some caveats, read them carefully:
Should you wish to get one PCB under those circumstances, write me a PM with your address and I will send you a quote with the shipping costs and my PayPal account. Once I get the money, I will post your letter.
Meanwhile have all fun with the remainder of the contest!
A quick follow up on the schematic of the project. I thought I do some documentation so that people can follow what I have been doing. I will quickly go through the different parts of the schematic step by step and add comments where necessary.
The whole hardware layout is done in KiCad and licensed under the CERN open hardware license v1.2. I will upload the files on github in the upcoming days so they can be accessed by everybody.
This is just a quick update: The boards have arrived yesterday and I had a first quick look. So far I have spotted just two small problems that can be fixed:
I have checked most of the other connections and not found an other problems but so far I have not tested the boards with all of the components. That will have to wait for another day or two.
Anyhow, I'm very happy with the result, considering that this is my first PCB. I also want to mention that I'm very pleased with the quick service of ITEAD for the manufacturing (not so with DHL who delivered the boards, but that is another story).
In the meantime I have some more work to do and wish you all a merry Christmas! As a present I will leave you with two photos of the actual boards.
So, last week I spend my time finishing the board layout and ordering the boards. The boards are currently manufactured and if all goes well I will have them before Christmas. Just that you can see how the boards will look like
For some reason, KiCad only renders the boards rectangular, but thy have rounded edges and a little cutout on one side.
Some comments on the design choices I made during the layout and how they affect the project:
Some lessons I learned for the next rev of the board:
Thats all for now. Let's cross our fingers that everything goes well and I will have the boards soon and did not make any terrible mistakes. Meanwhile I will work on the software part.
Hey there, I'm back and still living ...
The last couple of days I was finishing off with the schematic and starting out with board layout. Here is the (almost) finished schematic:
Small details might still change as I'm finishing up the board layout if I run out of board space or have tons of board space left. A couple of comments are in order:
Concerning the board layout, I have so far finished all the footprints and the basic outline of the board. Next up is placing of the components and routing. I have not yet decided on the size of the caps and resistors, I will try 0812 for easy hand soldering but might need to get down if space is rare (as it is, it seems). More on that soon - I plan to send off the board to be manufactured latest end of the week. So far I stick to my initial plan, yeah!
Some note before I part: KiCad suck. Honestly, it provided me with the worst user experience EVER over the weekend. Once it runs its fine, but finding a version that has everything running is a major pain. I'm no noob when it comes to compiling your own software, but it took me five hours using three operating systems (and two flavors of linux) to find a somewhat stable version. Really KiCad - this is the best you can do?
Just some small update: I have build up the circuit on a breadboard and tested all the components in software. So far I'm pretty satisfied with the results and think I will go on with this. A schematic will follow soon, so far just a pretty picture of the board all wired up and with blinking LEDs...
BTW, I had some thoughts about the power supply for the project and came up with some very nice idea ... more about that will also come soon.
Get together all your parts (see BOM). You also need a PCB: Download the Gerbers and get them produced yourself (at least for the moment). Note that the PCBs have as of now (Christmas 2014) a couple of (fixable) bugs. Alternatively, you can build the project on a breadboard or perfboard - use through-hole-components then. If you use a PCB, make sure to read an SMD soldering tutorial and use the right tools.
Start by soldering the three 100nF caps on the topside of the board (C1,C2,C3).
Solder R5, this is a 270 Ohm resistor (you may also use another value between 150 Ohm and 300 Ohm).
Create an account to leave a comment. Already have an account? Log In.
very interesting ... can you send the complete code of the project ???
thx
I used your library. It is the result of 0.04 ppm okay? I use MQ-135 for Arduino UNO.
Become a member to follow this project and never miss any updates
By using our website and services, you expressly agree to the placement of our performance, functionality, and advertising cookies. Learn More
I think you should use a Bosch bme280 for more accuracy,great project by the way