Go Down

Topic: Temp, Humidity CO2 sensor and library. (Read 152503 times) previous topic - next topic

Dew321

Also, has anyone experienced changes in CO2 readings when the CO2 sensor is exposed to higher temperatures, like 40 deg C? I'm not sure how high a temperature would start altering the values somehow

robtillaart

@Dew321
Have you checked the datasheet for info?
if so what does it say?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Dew321

@robtillaart. Yep, I have, and that's what the trouble is. It should be that the co2 sensor handles up to around 50 deg C fine, but when I am using it near a heat source that's not even close to that range it begins to act strangely. For instance, the Co2 levels will suddenly drop to an abnormally low level, and it'll stay that way for a bit. Not sure if it's a problem with the sensor, or if the heat is affecting the environment around it

Dew321

Actually, I found this article (http://www.mdpi.com/1424-8220/13/6/7079) that describes how temperature and pressure will affect the reading of the sensor by giving an altered co2 levels (as would temp/press affects the number of co2 molecules read by the sensor, but not the actual concentration). Should be useful to anyone else who might be wondering why their sensor is giving different readings.
       However, would anyone have any idea for possible arduino code that could correct for this difference? And also my sensor is shooting up in co2 value much more than what is given in the article.
       

robtillaart

They are talking about a different sensor , possibly a different technique if I read correctly (just scanned it quickly). That means deviations are also different.

The only solution I can imagine is to define a lookup table that gives a correction factor for a certain temperature.

then you would get a formula something like

// e.g. temp from 40..200degrees in steps of 4 degrees
float correctionFactor[40]; 

index = constrain (readTemperature() - 40)/4, 0, 40);

CO2 = readCO2() * correctionFactor[ index ];


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

nitrojet

Rob, I notice your library is hard coded (would need to edit the cozir.h or cozir.cpp file) to use the software serial?

Is this the case and what would need to be changed to use hardware serial on say a Leonardo board?

Many thanks

robtillaart

you should be able to do something like this
Code: [Select]

#include <cozir.h>

#if defined(ARDUINO) && ARDUINO >= 100
  #include <SoftwareSerial.h>
  SoftwareSerial nss(3,2);
#else
  #include <NewSoftSerial.h>
  NewSoftSerial nss(3,2);
#endif


COZIR czr(nss);

COZIR czr2(Serial);



disclaimer: I do not have such sensor, only helped build the lib
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

nitrojet

Thank you for your quick response but I get the following

Arduino: 1.5.8 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

sketch1.ino:13:18: error: no matching function for call to 'COZIR::COZIR(HardwareSerial&)'
sketch1.ino:13:18: note: candidates are:
In file included from sketch1.ino:1:0:
C:\Users\Acer\Documents\Arduino\libraries\cozir/cozir.h:58:2: note: COZIR::COZIR(SoftwareSerial&)
  COZIR(SoftwareSerial&);// : CZR_Serial(nss)
  ^
C:\Users\Acer\Documents\Arduino\libraries\cozir/cozir.h:58:2: note:   no known conversion for argument 1 from 'HardwareSerial' to 'SoftwareSerial&'
C:\Users\Acer\Documents\Arduino\libraries\cozir/cozir.h:55:7: note: COZIR::COZIR(const COZIR&)
 class COZIR
       ^
C:\Users\Acer\Documents\Arduino\libraries\cozir/cozir.h:55:7: note:   no known conversion for argument 1 from 'HardwareSerial' to 'const COZIR&'
Error compiling.

robtillaart

#113
Jan 15, 2015, 06:48 pm Last Edit: Jan 15, 2015, 06:59 pm by robtillaart
dived into the library code, indeed hardware Serial is not supported.
Sorry

update: I might be able to patch the lib coming weekend to support HWSerial
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Made a 0.1.06BETA version of the Cozir library: see attachment

+ added support for HardwareSerial
+ removed pre 1.0 Arduino support ==> removed support for NewSOftSerial
+ added examples for HW Serial

as I do not have a sensor I cannot test:
- compiles for UNO, MEGA  (AVR only)

@nitrojet
Can you please give it a try, and report if it works / other remarks.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

nitrojet

Sorry, don't seem to be able to get it to work on a Mega2560, no code appears in the serial window, I assume that just calling the nss or sws instance causes the program to halt as it doesn't even display the

 Serial.print("Cozir SoftwareSerial: ");
 
and when I delete all cozir related, I am able to print to the serial window. Is it to do with level shifting required?

nitrojet

Just decided to run it all at 5v which is ok according to the datasheet and still no luck either software or hardware mode on the Arduino Mega2560

Very strange

robtillaart

Can you post the exact code you use?
And you are running it on a MEGA?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

nitrojet

Here is the software example

Code: [Select]
//
//    FILE: CozirDemoSoftwareSerial.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: demo of Cozir lib
//    DATE: 2015-jan-17
//     URL: http://forum.arduino.cc/index.php?topic=91467.0
//
// Released to the public domain
//

#include <cozir.h>

#include <SoftwareSerial.h>
//SoftwareSerial sws(3, 2);
SoftwareSerial sws(50,51); // TX and RX pins

COZIR czr(sws);

void setup()
{
  Serial.begin(9600);
  Serial.print("Cozir SoftwareSerial: ");
  Serial.println(COZIR_LIB_VERSION);
  Serial.println();

  delay(1000);
}

void loop()
{
  float t = czr.Celsius();
  float f = czr.Fahrenheit();
  float h = czr.Humidity();
  uint32_t c = czr.CO2();

  Serial.print("Celcius =\t");    Serial.println(t);
  Serial.print("Fahrenheit =\t"); Serial.println(f);
  Serial.print("Humidity =\t");   Serial.println(h);
  Serial.print("CO2 =\t");        Serial.println(c);
  Serial.println();

  delay(3000);
}





and here is the hardware example


Code: [Select]
//
//    FILE: CozirDemoHardwareSerial.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: demo of Cozir lib (>= 0.1.06)
//    DATE: 2015-jan-17
//     URL: http://forum.arduino.cc/index.php?topic=91467.0
//
// Released to the public domain
//

#include <cozir.h>
// <SoftwareSerial.h> is needed as the cozir lib uses it.
// even when only using HWserial
#include <SoftwareSerial.h>

// HARDWARE INSTANCE for MEGA
COZIR czr(Serial1);

void setup()
{
  Serial.begin(9600);
  Serial.print("Cozir HardwareSerial: ");
  Serial.println(COZIR_LIB_VERSION);
  Serial.println();

  delay(1000);
}

void loop()
{
  float t = czr.Celsius();
  float f = czr.Fahrenheit();
  float h = czr.Humidity();
  uint32_t c = czr.CO2();

  Serial.print("Celcius =\t");    Serial.println(t);
  Serial.print("Fahrenheit =\t"); Serial.println(f);
  Serial.print("Humidity =\t");   Serial.println(h);
  Serial.print("CO2 =\t");        Serial.println(c);
  Serial.println();

  delay(3000);
}


I am using a Arduino Mega 2560

robtillaart

#119
Jan 24, 2015, 11:55 am Last Edit: Jan 24, 2015, 11:56 am by robtillaart
could you please do the following -

Hardware Serial example comment the whole content of loop();

in the library comment the content of the constructor so it doesn't do (almost) anything.

Code: [Select]

COZIR::COZIR(HardwareSerial& hws) : CZR_Serial(hws)
{
    # hws.begin(9600);
    # init();
}


this way only part of the constructor is called and we can see where it blocks.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up