Temp, Humidity CO2 sensor and library.

Hi, I thought I’d make a post about a sensor I recently purchased and its compatibility with arduino.
I was on the lookout for a sensor that would do temperature, humidity and co2. As I was looking for an all in one solution I settled on the cozir range of sensors http://www.cozir.com. After looking at the datasheet I thought it would interface easily with the arduino. I purchased mine directly from Gas Sensing Solutions. It works on the Arduino 3.3v, GND, and 2 digital pins for software serial TX,RX it took about 2 minutes to attach it and get it working.

As soon as I hooked it up I started the SoftwareSerial example and after a minor modification the sensor was outputting the environment variables in streaming mode, this is the default mode, in this mode it sends out a stream of data at about two per second, as I was wanting to get the data at a time that suits my sketch I put the sensor in polling mode, this allowed me more control over what was happening, once set in polling mode it stays on this mode until you change it which was handy as I could set the sensor up in a separate sketch then I don’t have to worry about including extra code in my project sketch.

I spoke with Rob Tillaart on the forum about it and he suggested a library be made, I had already hacked up my own library but it was a first version to get all the functionality of the sensor like changing digital filter and calibration into my project, Rob provided a blueprint library to start off with plus code which we worked on and tested for the last few weeks.

I have attached the library as a zip file in this post, It is 1.0 compatible. Thanks go out to Rob.

A few things to note, the sensor takes about 2 seconds to warm up, before that expect -100 for temp, putting a 2-3 second delay in setup stops this happening. Streaming mode hasn’t been implemented in this version of the library, you can easily choose streaming mode from within the library but if you do you’ll have to parse the data yourself, this will be getting worked on over the next few weeks. The digital filtered c02 value by default is set to 32, I found my graphs were moving quite a bit and after testing I have settled on 128, it gives a nice smooth output. Calibration with fresh air, nitrogen and known concentration are also implemented in this version of the lib and when you first power up the sensor you will have to calibrate it.

Please read the datasheet and software user guide before using this library.

Datasheet : http://www.co2meters.com/Documentation/Datasheets/COZIR-Data-Sheet-RevC.pdf
Software User Guide : http://www.co2meters.com/Documentation/Manuals/COZIR-Software-User-Guide-AL12-RevA.pdf

Here is a basic sketch to get it all outputting on the serial.

#include <SoftwareSerial.h>
#include "cozir.h"

SoftwareSerial nss(3,2);
COZIR czr(nss);

void setup()

void loop()
  float t = czr.Celsius();
  float f = czr.Fahrenheit();
  float h = czr.Humidity();
  int c = czr.CO2();
  int digi = czr.GetDigiFilter();
  Serial.print("Celcius : ");Serial.println(t);
  Serial.print("Fahrenheit : ");Serial.println(f);
  Serial.print("Humidity : ");Serial.println(h);
  Serial.print("CO2 : ");Serial.println(c);
  Serial.print("Digital Filter : ");Serial.println(digi);    


Cozir 0-1-01.zip (2.99 KB)

Some small remarks about the cozir library.

1) There are a few functions we commented out as they can "screw-up" the behavior of the device. We advice users to read the datasheet (twice) before uncommenting and using these functions. Mind you the Cozir-sensor is relative expensive (CO2 sensors all are) and you don't want to spoil it..

2) We implemented POLLING as primary acquisition strategy as this fits the single threading behavior of the Arduino best. We have some ideas to get the STREAMING mode working in a nice way but that will take a few days.

3) There is one function to get the value of the optional lightsensor, which is not clear with respect to units.

4) There are still some minor todo's in the code, that might be solved in a future version.

Comments and remarks are as allways welcome!

hey DirtGambit

the way you have displayed the results from your sensor is exactly what I am wanting to do. I am using SHT15 sensor(temp,humidity). Can you please post the code for graphing and display section. Robtillaart told me it is C# code and I need to download the compiler..I am a newbie at this stuff..Please help me out. I want to graph the history ; time on the x-axis and temp, humidity on to the y-axis and display on a web server. At the moment my web server displays current temp,humidity. I like your format of display.soo please post the code for me...

Thankz heaps :)

Hi Spandy, The images are screen grab/crop of a much larger application I developed to graph environmental variables, The library I use is zedgraph, they do an asp .net version for graphing on the web but I dont have any experience in using that, going by the tutorial it seems syntactically similar to what I have used developing this in c#. Mostly its just configuring how your graphs look, also for the timestamp I store this in unixtime then convert when Im filling up the arrays of data, sorry I cant be of much help, I havent developed anything for the web that uses graphing.

check out http://www.codeproject.com/Articles/5431/A-flexible-charting-library-for-NET

the examples dont look that great but zedgraph is so configurable it doesnt take long to change the look of your graphs.

Thank you..I will try it :)

I was interested in this sensor so I contacted GSS which relayed my request to their North American partner, AirTest Technologies. I was very impressed with the quick response time and they promptly provided me with information on their products.

For my purposes, the Corzir-A (Ambient) with a range of 0-2000 ppm is perfect. It also has optional temperature and humidity sensors. The part number for that combination is COZIR-A-2000-X-H and I'm told it's $183.

How does that compare to other CO2 sensors? It's definitely more than I was hoping to spend, but at the same time it may be worth the price if it simplifies my project.

Hi Gaines, I havent tested the cozir against any other Co2 sensor but it seems accurate enough, I usually calibrate via fresh air and that gives me a ball park figure for what Im using the sensor for, it certainly responds very well if the house has been empty all day and someone comes in it will pick up that very quickly. $183 is not a bad price, and its all in one, so no need for many libs, wires etc.

The only drawback from an arduino point of view is the sensor communicates through serial which makes the process a bit more difficult getting the data you want, it would have been nice to have a digital version, 3 pins and just asks the sensor for the values but this limits its application I suppose because GSS also supply a usb cable that fits directly to the sensor and can run via their software without the need for any dev board.

I do think its something GSS should consider, getting rid of the serial and going digital might lower the cost. Getting rid of streaming mode is another thing Id like to see, its a pain in the @$$. :)


Hi DirtGambit,

Can you determine the presence of someone with the sensor? detecting an intruder? how fast? Would be a nice new application !

Oh yeah for sure as long as it wasnt really time critical, it stays between 390 - 420ppm (+-10ppm) all day, within 5 minutes of someone coming into the livingroom it will quite happily go up to 550ppm especially if you go near the sensor, I had some friends round one night, 4 people in a smallish living room, I was shocked to see 1500ppm on the graph.

A few years ago there was a study into co2 concentration in old schools, the average co2 during school time was > 2000ppm in some of them, in this case peaks were found at 3500ppm (I read a study once that had peaks of 4500ppm), a few schools had really good results but they were still > 1200ppm and had very good ventilation.


5 minutes seems rather long, but in those 5 minutes it goes from ~400-550 so it rises ~30ppm/minute. That means that one could detect it within 60 seconds that the CO2 level has rissen, and if well positioned maybe within 30 seconds. WHat is the minimum time you can detect in your graphs? If it is within 1 minute it would be great (OK depends on size of the room etc.

Do you see the same change in temperature - gues not- and humidity - could be? Humans exhale water and CO2 (they are reverse trees :) so those two should change significantly from some average value.

Ideas pop in my mind, like counting people by means of their CO2 output. Fun!

At the top of this post there is a second photo. What is it? An enclosure for the sensor and antenna?

Also, Cozir mentions the sensor has a light sensor? Is it an LDR? Does anyone know?



Does anyone know?

You could contact the manufacturer … IIRC from the datasheet not all models support this (not sure)

I asked for ldr functionality in my sensor and was told it wasn't being supported anymore, the datasheets haven't been updated to reflect this. The ldr was an optional extra, so at order time you are just told the ldr isn't available. I liked the idea of an ldr, but i think these sensors are being targeted to the commercial sector (handheld devices) where an ldr might not be as useful as opposed to the arduino/electronics community where having one sensor do many things is desirable depending on what you are making. ldrs are 10 a penny so just hook one up along side the cozir, thats what i did.

The enclosure is from proto-pic.co.uk, it was lying around so i put it together and the antenna is connected to a bluesmurf module, it has a decent range with the antenna.

Does the cozir sensor still has a connector for the LDR?

This is disappointing. I thought I had found a sensor that would do so much. I am wondering if there are any with all four sensors as Cozir has stated in the documentation.

I would like to create a sensor module that will sense C02, temperature, humidity, light and motion and connect them all to an xbee network to stream on the Internet.

Is PIR a good sensor for motion? What is a good precision LDR?

I plan to place these modules on each floor of my home to detect variations in temperature and humidity, alert on C02 and motion, and adjust an LED to shed light in the room as it is needed.



I dont know rob, I havent opened the sensor to find out, also i dont know if they have altered the firmware of sensor to stop outputting null values if the sensor has no ldr fitted, the sensors output is always rh,Temp,unfiltered co2, filtered co2.

badwheels thats quite a demand from any all in one sensor, the cozir does most of what you need, if you were to have all those separate you would have quite a breadboard and be in wire/lib hell, your project sounds cool though good luck.

Hi all, Does anyone have an idea where to get COZIR.h library ?

yes. the lib is attached on the first post (it includes the .h file)

latest version I have is 1.03 - see attachment - but it is a long time since I edited in it. there may be some work in progress on some points in it.
Note that the calibration functions must be used careful and do not use them if you don’t understand their impact.

#all disclaimers apply :wink:

If you have comments remarks let us know.

cozir 1.03.zip (3.02 KB)

the attachment returns Error 503 Service Unavailable

Do you have code that works on an arm nxp lpc1769 ?

My CO2 readings seem high what’s the best way to calibrate this device. I only have outside air to calibrate against.

many thanks