Page 1 of 1

CO2 sensor returns a garbage value after a few hours of working fine

Unread postPosted:Sat Sep 25, 2021 10:03 am
by alexthecalyx
Hi this is my first post, I hope my info and formatting is appropriate.

I just got a DFR CO2 sensor SEN0219 and it works fine for a few hours to a day and then returns ~34000ppm instead of a normal 4-600ppm for my bedroom.

I'm using the FireBeetle ESP32 with the shield for it.

I went with the serial wiring and coms option as per forum instructions on the product page--analog values are too noisy. I have wired it to read from the uart using pads 13(TX) and 18(RX) connected to D2/25(RX) and D3/26(TX) respectively. I am supplying the sensor with 5v VCC from the VCC shield pin (muiltimeter says 5V too). It's powered by a laptop's usb power port.

Why does this digital sensor crash after some time ???

Here is the copied code for serial coms between ESP and the CO2 sensor...

/***************************************************
* Infrared CO2 Sensor 0-50000ppm(Wide Range)
* ****************************************************
* The follow example is used to detect CO2 concentration.

* @author lg.gang([email protected])
* @version V1.0
* @date 2016-6-6

* GNU Lesser General Public License.
* See <http://www.gnu.org/licenses/> for details.
* All above must be included in any redistribution
* ****************************************************/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(25, 26); // RX, TX

unsigned char hexdata[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79}; //Read the gas density command /Don't change the order

void setup()
{

Serial.begin(115200);
while (!Serial) {

}
mySerial.begin(9600);

}

void loop() {
mySerial.write(hexdata,9);
delay(2000);

for(int i=0,j=0;i<9;i++)
{
if (mySerial.available()>0)
{
long hi,lo,CO2;
int ch=mySerial.read();

if(i==2){ hi=ch; } //High concentration
if(i==3){ lo=ch; } //Low concentration
if(i==8) {
CO2=hi*256+lo; //CO2 concentration
Serial.print("CO2 concentration: ");
Serial.print(CO2);
Serial.println("ppm");
}

}

}

}