Introduction
DFRobot released its latest high-precision infrared arduino CO2 sensor. The effectively measuring range is from 400 to 5000ppm. This sensor is based on non-dispersive infrared (NDIR) technology and has good selectivity and oxygen-free dependency. Besides, its service life could up to 5 years! It integrates temperature compensation and support DAC output. The current CO2 concentration can be read with only one digital port. Most importantly, the product is easy to use and is compatible with all types of microcontrollers and sensors.
In addition, this product is a high-performance sensor that combines the technology of mature infrared absorption gas detection with precision optical circuit design, as well as sophisticated circuit design. It has characteristics such as high sensitivity, high resolution, low power consumption, fast response, anti-water vapor interference, no poisoning, high stability and long life.
This sensor is directly compatible with the DFRobot Arduino IO expansion board thanks to its external DFRobot Gravity interface. This simplifies the use of the sensor as it is plug-and-play and no additional wiring required. This product could be widely used in HVAC, indoor air quality monitoring, industrial process and security protection monitoring, agriculture and animal husbandry production process monitoring, etc.
Feature
- Gas cell with gold plating, waterproof and anti-corrosion
- High sensitivity and low power consumption
- Excellent stability
- Temperature compensation and excellent linear output
- High cycle life
- Anti-water vapor interference and no poisoning
- No poisoning
Specification
- Gas Detection: Carbon Dioxide (CO2)
- Supply Voltage: DC (5.0±0.1)V
- Average Current: <40mA (@5V power supply)
- Peak Current: <125 (@5V power supply)
- Output Signal: PWM
- Preheating Time: 1min
- Response Time: T90 < 120s
- Operating Temperature: -10℃ - 50℃
- Operating Humidity: 0 - 95% RH (no condensation)
- Measuring Range: 400 - 5000 ppm
- Resolution: 1ppm
- Accuracy: ±(50ppm+5% reading)
- Dimension: 69mm×37mm/2.72×1.46"
Board Overview

Num | Label | Description |
---|---|---|
1 | Signal | Signal Output (0.4-2V) |
2 | VCC | + |
3 | GND | - |
Zero Calibration
- Method 1: Manual zero calibration
Short circuit the HD and GND of the sensor to calibrate it. It always needs to last for over 7 seconds at a low level. Make sure that the sensor runs stably for over 20 minutes at a concentration of 400ppm before the calibration. - Method 2: Automatic zero calibration
The automatic calibration function means that the sensor will intelligently determine the zero point according to the ambient CO2 concentration and automatically calibrate it after a period of continuous operation. The calibration starts from power-on and is performed once every 24 hours. The zero point for automatic calibration is 400 ppm. This calibration is suitable for office and home enviornment.
Tutorial
This tutorial is designed for you to learn how to use the infrared CO2 sensor to measure the current CO2 concentration in the air in 5 minutes.
Requirements
Hardware
- DFRduino UNO x 1
- DFRobot Gravity: Infrared CO2 Sensor x 1
- Gravity: IO Expansion Shield for Arduino V7.1 x 1
- Cable x 1
Software
- Arduino IDE Click to Download Arduino IDE from Arduino®
Connection Diagram

Sample Code
Download the Arduino code, and open the window monitor in the upper right corner to view the data.
/***************************************************
Infrared CO2 Sensor range : 400-4980ppm
* ****************************************************
This example The sensors detect CO2
@author qsjhyy(qsj.huang@dfrobot.com)
@version V2.0
@date 2021-8-17
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
* ****************************************************/
/*
* The Correspondence Table of AVR Series Arduino Interrupt Pins And Terminal Numbers
* ---------------------------------------------------------------------------------------
* | | DigitalPin | 2 | 3 | |
* | Uno, Nano, Mini, other 328-based |--------------------------------------------|
* | | Interrupt No | 0 | 1 | |
* |-------------------------------------------------------------------------------------|
* | | Pin | 2 | 3 | 21 | 20 | 19 | 18 |
* | Mega2560 |--------------------------------------------|
* | | Interrupt No | 0 | 1 | 2 | 3 | 4 | 5 |
* |-------------------------------------------------------------------------------------|
* | | Pin | 3 | 2 | 0 | 1 | 7 | |
* | Leonardo, other 32u4-based |--------------------------------------------|
* | | Interrupt No | 0 | 1 | 2 | 3 | 4 | |
* |--------------------------------------------------------------------------------------
*
* This example uses UNO to demonstrate.
* If you want to use other master controls, please configure the following two lines
*/
#define sensorIn 2 // Sensor PWM interface
#define interruptNumber 0 // interrupt number
unsigned long pwm_high_start_ticks=0, pwm_high_end_ticks=0;
float pwm_high_val=0, pwm_low_val=0;
volatile uint8_t flag=0;
void interrupt_rising()
{
pwm_high_start_ticks = micros(); // store the current micros() value
if(2 == flag){
flag = 4;
pwm_low_val = pwm_high_start_ticks - pwm_high_end_ticks;
}else{
flag = 1;
}
attachInterrupt(interruptNumber, interrupt_falling, FALLING);
}
void interrupt_falling()
{
pwm_high_end_ticks = micros(); // store the current micros() value
if(1 == flag){
flag = 2;
pwm_high_val = pwm_high_end_ticks - pwm_high_start_ticks;
}
attachInterrupt(interruptNumber, interrupt_rising, RISING);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(sensorIn, INPUT);
attachInterrupt(interruptNumber, interrupt_rising, RISING);
}
void loop() {
if(flag == 4){
flag = 1;
float pwm_high_val_ms = (pwm_high_val * 1000) / (pwm_low_val + pwm_high_val);
if (pwm_high_val_ms < 0.01){
Serial.println("Fault");
}
else if (pwm_high_val_ms < 80.00){
Serial.println("preheating");
}
else if (pwm_high_val_ms < 998.00){
float concentration = (pwm_high_val_ms - 2) * 5;
// Print pwm_high_val_ms
Serial.print("pwm_high_val_ms:");
Serial.print(pwm_high_val_ms);
Serial.println("ms");
//Print CO2 concentration
Serial.print(concentration);
Serial.println("ppm");
}else{
Serial.println("Beyond the maximum range :398~4980ppm");
}
Serial.println();
}
}
Result
Please wait at least 3 minutes (preheat process) until the data is stable. At this time, the sensor can display the CO2 concentration.
FAQ
Q. Can I use the CO2 sensor with 3.3V microcontroller? |
---|
A. Yes, but you need to power the CO2 sensor with a 5V power supply separately, and change the conversion formula in the code float voltage = sensorValue*(3300/1024.0); |
Q. Why is the reading of the CO2 sensor unstable? |
---|
A. The high sensitivity of the CO2 sensor may lead to relatively large fluctuations in the reading. The deviation of the reading can be reduced by taking the average of several values. |
If you have any questions about using this product, please check the FAQ list for that product for a corresponding solution.
And for any questions, advice or cool ideas to share, please visit the DFRobot Forum.
More Documents
Shopping from Gravity: Infrared CO2 Sensor For Arduino or DFRobot Distributor.