Temp, Humidity CO2 sensor and library.

I'm hoping somebody is still looking at this. I want to modify this library to work with hardware serial but there are some things I don't understand. Specifically, the constructor looks very strange.

Can you explain what is strange in your opinion?

Hello and sorry I havent replied to any posts, i havent touched an arduino for a long time, so tonight i took my COZIR sensor and arduino and had a play around, i indeed got some of the problems that many of the users have been having, i was able to reproduce the errors and quickly found out that the sensor need calibrated, i will include the library to this post that i used tonight and also put some functions in and comment them out so in Setup() you can do calibration or change digital filter.

Here is the code i used for my main sketch

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

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

void setup()
 // czr.SetDigiFilter(64);

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); 

Some of the problems people have been having is due to not calibrating the sensor at first use

Here is a step by step
uncomment czr.SetOperatingMode(CZR_POLLING);
Upload Sketch
comment czr.SetOperatingMode(CZR_POLLING);
and uncomment czr.CalibrateFreshAir();
Upload Sketch
comment czr.CalibrateFreshAir();
Upload sketch
and if you want to change digital filter do the same, as the settings are kept on the sensor you never need to do these again unless you want to. I have found if i uncomment them all the sensor plays up and gives bad values until i comment out and upload the sketch again, i dont know why this is, it would have been such a better sensor if it were polling by default.

I have attached the lib i used tonight to this post


cozir.zip (2.99 KB)

Here's what I have:

Arduino Uno R2 + Cozir Ambient + DirtGambit's work: running Arduino Uno R3 + Cozir Ambient + DirtGambit's work: running Arduino Mega 2560 R3 + Cozir Ambient + DirtGambit's work: fail

I'm guessing I need a logic inverter, to get a 5V signal on the Mega, since all else failed.

O, and thanks DirtGambit, you made the Cozir sensor a lot easier to use!


Thanks 34R7 but its Rob Tillaart you need to thank too.

Im glad your having success with the sensor, I tried using the sketch that GSS provided and I couldnt get it to work at all, the library still needs work and Im sure very soon it will happen.

Good luck with your projects.

Dankuwel, Rob Tillaart!

I just ordered a logic converter, I'll let you know what's the outcome!


Hi, I have tried DirtGambit's library, tried all the possibilities ( 5v, pins, and so on ) what can be found here, but the same problem:

Celcius : 0.00
Fahrenheit : 32.00
Humidity : 0.00
CO2 : 0
Digital Filter : 0

I am trying this with Mega board...

Maybe there is a problem with the sofwareserial...? When using sim900 shield, there was a hwserial lib instead of the swserial... Do you have any idea? It would be great to make it work on mega...

Dear All,

I have found the solution to use this sensor with mega 2560! As Softwareserial notes: "Note: Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69"

So let's connect the RX pin of the sensor to mega pin 51, and TX pin of the sensor to mega pin 50 and use DirtGambit's sketch with modification:

SoftwareSerial nss(50,51); // TX and RX pins

And smile when you realise this is working fine after calibration!

Thanks, vespapierre! Works like a charm now!

Happy to hear that!!! Great! Note: if you are using MEGA 2560 board, and you are using ICSP pins ( for example wiznet shield ), than do not use 50 - 51 pins, because ICSP using in this case 50-51-52 pins. So in case try using other pins from the availables( for example 11-12). Usually pin10 is wiznet, pin4 is sd, pin13 is onboard led on mega... Anyway I do not know what and where is 62, 63, 64, 65, 66, 67, 68, 69 ... :~

Anyway I do not know what and where is 62, 63, 64, 65, 66, 67, 68, 69 … :~

Pin 54 is A0, so pin 62 is A8, 63 is A9, 64 is A10… I just tried out A8-A9, and it works perfectly!
Hope thIS gives you some more options.

aaah thanks! I am testing on pins 11-12. works also perfect :)

Hello All. New to this forum and arduino so im at a loss for what im doing wrong.

I've used the new code/re calibration last listed to yield positive CO2 readings, yet my humidity and temperature readings are all 0. Is this an error within the sensor or my doing?

Hi everybody , Recently I've got the cozir wide range

I just read the datasheet and the process to do the calibration part is the same I've used the library provided by DirtGambit and robtillaart ,my doubt is about this process we need to calibrate the sensor each time I turn on the arduino device or I do need to recalibrate the sensor ?

Thanks for your support.


hector915: I've used the library provided by DirtGambit and robtillaart

Where are these libraries available? They do not seem to be attached to this thread. :(

Hi, I have the same issue as roder have.. I can not find the library cozir.h attached with the post

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

Dear robtillaart, I can not find the cozir.h file attached with the first post. Could you please guide me how can I download this file.

Regards, Abbas

I have to search for the latest version I have, "I'll be back"

Attached my latest cozir 0.1.03 lib version. There is a sketch included which compiles.
Disclaimer: I still do not have such sensor so I cannot test it in real life …

Is it OK to include this library in my Github repo?

cozir0.1.03.zip (93.6 KB)

Thanks a lot Rob for the file. I tried to run it but on monitor nothing is displaying. I am using 1.0.5 version. May be its compatibility issue ?