IR11BR C02 Sensor

Datasheet - https://www.sgxsensortech.com/content/uploads/2014/07/IR11BR-Certified-100percent-volume-CO2-Gas-Sensor.pdf
https://www.sgxsensortech.com/content/uploads/2014/07/DS-0247-IR1-Single-Gas-Series-Datasheet-V2.pdf
Application notes - IR11BR SGX Sensortech Gas Sensor - Infrared|SGX

Hi there, I am using this sensor with a Seeeduino Xiao and expansion board but am struggling to convert the information provided in the datasheets (application notes) into code, I am new to coding so any information to put me in the right direction is greatly appreciated. Cheers

Which board do you use to connect the sensor to the Xiao?

Please post the code you have, using code tags, and explain the problems you are having with it.

Hi there,

The expansion board i am using is this one: Seeed Studio XIAO Expansion board - Seeed Wiki

Cheers

Currently, I am just trying to use an interrupt to make a 4HZ squarewave at 50% duty cycle, to test this I am using an LED with it terminated to pin 10 and gnd. As I've said before I am new to coding and I am not too sure the best way to do interrupts so this is what I have got so far but as you can see it is not producing a square wave when it is "ON"

image

#include <TimerTC3.h>


bool isSensor1On = false;
char time = 0;

void setup() 
{
    //SerialUSB.begin(115200);
    //while(!SerialUSB);
    
    pinMode(10, OUTPUT);    

    TimerTc3.initialize(125000);
    TimerTc3.attachInterrupt(timerIsr);
}
 
void loop()
{
   int y1 = digitalRead(10);
   Serial.println(y1);
   
    time ++;
    if(time == 10)TimerTc3.detachInterrupt();
    else if(time == 20)
    {
       TimerTc3.attachInterrupt(timerIsr);
       time = 0;
    }
   delay(100);
}

void timerIsr()
{     
    digitalWrite(10, isSensor1On);
    isSensor1On = !isSensor1On; 
}

There is no reason to use an interrupt, as doing so usually causes more problems than it solves. You have already broken at least one rule: variables shared with interrupt routines (e.g. isSensor1On) must be declared volatile.

Why do you need a 4 Hz squarewave? The loop function can do this effortlessly. Here are two ways of doing so.

void loop() {
digitalWrite(10,1);
delay(125);
digitalWrite(10,0);
delay(125);
}

Or, without delay():

unsigned long timer = 0;
byte ledstate=0;

void loop() {
if (millis()-timer >= 125) {
digitalWrite(10,ledstate);
ledstate = !ledstate;
timer=millis();
}
}

In the application notes I believe it is asking for an interruption for the IR lamp.


PDF - https://www.sgxsensortech.com/content/uploads/2014/08/AN3-–-Design-of-Microcontroller-Software-for-Infrared-Gas-Sensors.pdf

That flow chart is simply one person's suggestion for how to proceed. No interrupt is required.

With most microcontrollers, a timer can be configured to automatically generate 4 Hz on certain I/O pins, without any need for the processor to be involved.

But in this case, you don't even need a separate timer. I've already showed you how to generate the 4 Hz in loop() (using the millisecond timer), with plenty of CPU time left over to do all the rest of the things in that flow chart.

To elaborate:

void loop() {
if (millis()-timer >= 125) {  //this if clause takes a couple of microseconds to execute
   digitalWrite(10,ledstate);  //4 Hz lamp blink
   ledstate = !ledstate;
   timer=millis();
   }
// here, do all the rest of the decision making and computing
}

That doesn't have a socket for the linked sensor or any circuitry to support it. So there must be another board you use to connect the sensor to the MCU.

I'm not sure what you mean here, Can you please elaborate

Thank you this works, Now how would I go about taking readings from the IR lamps at 125ms intervals. they are analog waves and it specifies to take reading when it is at max and min.

If you just have the naked detector, you will need an appropriate socket or connectors (as mentioned above) and some support electronics.

The Arduino cannot directly drive the lamp, and it cannot accurately measure the small voltages (25 mV) at the signal output. So, you need a lamp driver and signal amplifier.

Also, the signal is not simply related to the CO2 concentration, and that will require some computing. The corrections require that you know the temperature as well.

What is your plan for all of that?

There are several documents in this link, explaining all of the above in detail. Please study them carefully: Application notes

I have been reading the application notes and in "Infrared Sensor Application Note 4
Design of Electronics for Infrared Gas Sensors" states that it can be generated by a microprocessor with a crystal reference, and the seeeduino xiao has a 32,768Hz crystal installed so I thought that I could use this to drive the IR lamps. If not can you explain how this should be done as I have no idea, and yes I plan to use a MOSFET or op-amp to amplify the signals, and i also will be using an external thermocouple as my temperature reference. I am new to electronics and I still have a lot of reading to do as I am trying to understand how to make this sensor work for a project.

Any microprocessor will work.

To drive the lamps you need a simple transistor driver, like this (M is the lamp, D1 is not needed). Q1 could be 2N3904 or 2N2222:

You will need two non-inverting operational amplifiers, rail to rail output (very important) with gain of about 20 to bring up both the reference and the sensor output voltages to measurable levels, that is, somewhat less than 5V maximum.

Tutorial here: Non-inverting Operational Amplifier Configuration

I still have a lot of reading to do

Indeed you do. This is pretty advanced for a beginner project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.