Basic Arduino sketch for YYS SC8 NDIR CO2 sensor

Hi there for anyone wanting a cheap industrial grade NDIR CO2 sensor. work really well and quite sensitive. YYS SC8 NDIR CO2 sensor. you can buy on alibaba or aliexpress for around $8 ( plus shipping). but you can get in range of 0pmm to 5000ppm,400ppm to 5000ppm, 0ppm to 10000ppm or 0pmm to 40000ppm
easy to work with only requires 3 wires (PWM) or 4 wires (UART) ,
here the basic PWM arduino sketch for it

int pin = 2;
unsigned long duration;

void setup() {
  Serial.begin(115200);
  pinMode(pin, INPUT);
}

void loop() {
  duration = pulseIn(pin, HIGH, 1004000);
   if ( duration != 0) {
    duration = ((duration -2000)*5)/1000;
    Serial.println(duration);}
}

it out put new data about every second
reference:

Accuracy effective Range
(Keep Consistency Error)
400~5000 ppm
Maximum Range 400~5000 ppm
Resolution 1 ppm
Maximum Consistency Error
(400~5000ppm)
±(50ppm+5% of Reading)
Response Time
(Environmental change)
<3 minutes for 90% step change
typical
Minute(min)
Single Update <3 (Typical 1s) Second(s)
Update or Warmup Time 8s(update time)
<25s (operational)
<3min(90% accuracy)
<10min (maximum accuracy)
DC Power Supply Typ:5.0 Min:4.5 Max: 5.5 Volt(V)
Active Current 150mA peak ,70mA average Milliampere(mA)
Interface Level L <0.8 @3.3 H >[email protected] Volt(V)
Working Temperature Range -10~+60 ℃
Working Humidity Range 0~95% non condensed
Storage Temperature Range -40~+85 ℃
Maximum storage
Temperature &Humidity
70/85 ℃/%
Life Time ≥10 Year(Y)
Physical Size Millimeter(mm33×19.7×8.9 )

if you want to work with the UART as never tried an arduino sketch but here the information:

SC8-CO2-5KV1.4_datasheets.pdf (384.7 KB)

1 Like

Very nice! How are those sensors calibrated? I only used SCD3x/4x before and theY have automatic as well as manual calibration options.

the same - automatic every24 hrs looking for the lowest co2 levels and adjusting from there. or manual by sending an UART command

here the basic UART/PWM sketch done on a esp8266 platform

const byte numBytes = 32;
int pin = D5;
unsigned long duration;

byte receivedBytes[numBytes];
byte numReceived = 0;
int cnt = 0;

boolean newData = false;

void setup() {
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");

 
}

void loop() {
    duration = pulseIn(pin, HIGH, 1004000UL);
   if ( duration != 0) {
  
    duration = ((duration)*5)/1000;
    Serial.print("PWM ppm  ");
    Serial.println(duration);}
    recvBytesWithStartEndMarkers();
    showNewData();


}

void recvBytesWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    byte startMarker = 0x42;
   
    byte rb;


    while (Serial.available() > 0 && newData == false) {
        rb = Serial.read();

        if (recvInProgress == true) {
          
            if (ndx != 15) {
                receivedBytes[ndx] = rb;
                ndx++;
                cnt = ndx;
                if (ndx >= numBytes) {
                    ndx = numBytes - 1;
                               
                }
            }
            else {
                receivedBytes[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                numReceived = ndx;  // save the number for use when printing
                ndx = 0;
                newData = true;
            }
        }

        else if (rb == startMarker) {
            recvInProgress = true;
       
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        for (byte n = 0; n < numReceived; n++) {
            Serial.print(receivedBytes[n], HEX);
            Serial.print(' ');
        }
        Serial.println();
        showGroupsOfBytes();
        newData = false;

    }
}

void showGroupsOfBytes() {
    if ( receivedBytes[0]==0x4D )  {  
     if (cnt == 15) {
int ppm =   (receivedBytes[5]*256+receivedBytes[6]);
Serial.print("UART ppm  ");
Serial.println(ppm);


}     
       }
         cnt = 0; 
       }

the PWM out put a little faster then the UART but the output are roughly the same

uartco2

the CO2 levels are a bit high due to the fact I am basically breathing right next to the device. - next to add in the particulate sensor that should be here in the next couple days for a better home air quality sensor