Pages: [1]   Go Down
Author Topic: Interfacing with a CO2 sensor  (Read 2013 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,
I have been asked to make a simple carbon dioxide monitoring system. My only issue is that I am really only a programmer and have limited knowledge about electronics. In the data sheet, they have a diagram for interfacing with a external micro controller (http://cdn.shopify.com/s/files/1/0019/5952/files/Spec070426-K22-PWM_ed2-2000.pdf?1254409988). Although I have an idea of what to do, I do not want to damage the expensive sensor in anyway and would feel more comfortable if someone reaffirmed me.

I have already poked around online and seem to have stumbled on some working code already:

int  pin=14;
unsigned long duration;

void setup()
{
 pinMode(pin, INPUT);
  Serial.begin(115200);
}
void loop()
{
 unsigned long ppm; // adding for clarity

 duration = pulseIn(pin, HIGH); // get the raw reading
 ppm = duration - 177000UL; // subtract the 'zero point'
 ppm /= 500UL; // divide by the gain
 ppm += 350UL; // add the zero point back in

 Serial.print("  PPM Co2: ");
 Serial.print(ppm,DEC);
 Serial.print("  Raw Sensor: ");
 Serial.println(duration,DEC);
}


I am really hoping someone can give me a detailed explanation of what I need to do but any help is appreciated.

Eric
Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

1.
the co2 sensor and the arduino need to share a common ground voltage level...
how does ur power supply look like?

2.
the PWM output varies between 0V and V+ of the CO2 sensor...
the arduino needs below 30% of its supply voltage for a digital LOW...
the arduino needs above 70% of its supply voltage for a digital HIGH...
but the arduino doesnt like voltages below 0V or above its supply voltage...
maybe u need a voltage divider if the PWM output voltage can be higher than the arduino supply voltage...?

3.
i would use the following method to convert the PWM into the ppmCO2 value, because it doesnt depend on an accurate time (on my arduino i have an error of +0.3% IIRC... 0.3% of 1004ms (~=~3ms) corresponds to 6ppmCO2):
Code:
uint16_t pwm2ppm(uint8_t pin) {
  while (digitalRead(pin) == HIGH);
  while (digitalRead(pin) == LOW);
  uint32_t h,l;
  for (h=0; digitalRead(pin) == HIGH; h++);
  for (l=0; digitalRead(pin) == LOW; l++);
  // h+l <=> 1004msec
  // 1004*h/(h+l) <=> duty cycle D in msec
  // (D-177)/0.5 + 350 = ppmCO2
  return ((2*1004*h+1004)/(h+l)-2*177) + 350; // +1004 for proper rounding...(?)
}

maybe u should even disable interrupts...
http://arduino.cc/en/Reference/noInterrupts

-arne
« Last Edit: May 07, 2010, 09:48:03 am by RIDDICK » Logged

-Arne

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

btw:
1.
do u know where pin 14 is?
i think it is analog pin 0...

2.
after a reset all analog pins r configured as inputs...
so that u can be quite sure, that the sensor isnt damaged by them...
but maybe u want to put a resistor (2kOhm or so) between the arduino pin and the sensor PWM output... just to be sure... :-)

-arne
Logged

-Arne

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply. Here is a link to where I got the code from: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1257112824

In the post, he seems to have gotten correct input using just two resistors and the code provided but I wanted to be sure of where exactly he put them.
Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

according to the K22 datasheet (page 6 & 5) u dont need ur own pull-up resistor (4.7k to 5V), because the K22 already contains its own on-board...

the 10k is just for the case, that u re-conf pin #14 as output pin and give 5V on it... :-)
everything clearly above 125 Ohm should be safe here, because arduino pins can take 40mA...
according to the K22 datasheet there is already a 120 Ohm resistor on the K22 board...
the BC847 on the K22 can take even more than 40mA...

i like my approach (without pulseIn()) still better... :-)

-arne
« Last Edit: May 09, 2010, 04:47:08 am by RIDDICK » Logged

-Arne

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm so you are basically saying i can just connect the sensor without any resistors (unless i want to be on the safe side)?

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

also i think ill try the method described in the other post first because i know it has been tested and works. after i get it working ill be sure to try the method you described.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Hopefully you have gotten this interface working!

I am a representative from CO2Meter and have noticed this forum post. I'd just like to add that we have a guide written specifically for Arduino boards that will guide you through interfacing with the sensor over I2C:

cdn.shopify.com/s/files/1/0019/5952/files/Senseair-Arduino.pdf?1264294173

Using a purely digital form of communications will generally provide a higher degree of accuacy.

Let me know if you have any further questions!
Logged

Andrew Robinson
andrewbrobinson.com

California
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Woot
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

WOW very nice, a rep helping you out! Fantastic! Rare, but awesome!
Logged

Chris
Its hard to put the smoke back in the wires

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Andrew,
Thanks for the post! I did get the CO2 sensor working via PWM. The guide you linked seems very helpful. I thought about using I2C in the beginning but I wasn't too comfortable with it.

One question I have is what do you think a average house CO2 level should be? I read in around 600-750 ppm on average. I want to make sure I did my math right and it is calibrated.

Thanks, Eric
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Andrew,
  I just finally logged back on today and got your message.. yes 600-800 ppm is where most residences sit.
If you have your space filled with green plants like a greenhouse then the co2 can go lower as it is consumed by the respirating plants.


     gwen
ps good luck with that project
« Last Edit: June 30, 2010, 12:02:19 pm by gwen » Logged

Pages: [1]   Go Up
Jump to: