0% found this document useful (0 votes)
196 views

Decoding PMS5003 Code

This document contains code for decoding data from a PLANTOWER PMS 5003 air quality sensor over a serial connection. It reads incoming serial data byte-by-byte, storing it in a buffer until the checksum is received. If the checksum matches, it prints the sensor measurements in ug/m3 for PM1.0, PM2.5 and PM10, followed by particle concentrations for several size ranges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
196 views

Decoding PMS5003 Code

This document contains code for decoding data from a PLANTOWER PMS 5003 air quality sensor over a serial connection. It reads incoming serial data byte-by-byte, storing it in a buffer until the checksum is received. If the checksum matches, it prints the sensor measurements in ug/m3 for PM1.0, PM2.5 and PM10, followed by particle concentrations for several size ranges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Decoding from PLANTOWER PMS 5003

// Arduino-like Programming
// (C) 2006, H.Inomatavoid loop()
{
if (Serial1.available()) {
cc = (unsigned char)Serial1.read();

switch (data_ptr) {
case 0:
if ( cc == 0x42 ) {
data_ptr = 0;
data_buf[data_ptr++] = cc;
chksum = cc;
} else {
// NOP
}
break; case 1:
if ( cc == 0x4d ) {
data_buf[data_ptr++] = cc;
chksum += cc;
} else {
data_ptr = 0;
// NOP
}
break;

case 30:
data_chk = data_buf[data_ptr++] = cc;
break;

case 31: // end of data


data_buf[data_ptr++] = cc;
data_chk = (data_chk * 256) + cc;
data_ptr = 0;

if (data_chk == chksum) {
Serial.println( "* PM1.0, PM2.5, PM10 ug/m^3" );
Serial.print( (data_buf[2]*256 + data_buf[3]), DEC );
Serial.print( "," );
Serial.print( (data_buf[4]*256 + data_buf[5]), DEC );
Serial.print( "," );
Serial.println( (data_buf[6]*256 + data_buf[7]), DEC );

Serial.print( (data_buf[8]*256 + data_buf[9]), DEC );


Serial.print( "," );
Serial.print( (data_buf[10]*256 + data_buf[11]), DEC );
Serial.print( "," );
Serial.println( (data_buf[12]*256 + data_buf[13]), DEC );

Serial.println( "* 0.3, 0.5, 1.0, 2.5, 5.0, 10 um" );


Serial.print( (data_buf[14]*256 + data_buf[15]), DEC );
Serial.print( "," );
Serial.print( (data_buf[16]*256 + data_buf[17]), DEC );
Serial.print( "," );
Serial.print( (data_buf[18]*256 + data_buf[19]), DEC );
Serial.print( "," );
Serial.print( (data_buf[20]*256 + data_buf[21]), DEC );
Serial.print( "," );
Serial.print( (data_buf[22]*256 + data_buf[23]), DEC );
Serial.print( "," );
Serial.println( (data_buf[24]*256 + data_buf[25]), DEC );
Serial.println( "" );
} else { // error
Serial.println( "Check Sum Error!" );
}
break;

default:
data_buf[data_ptr++] = cc;
chksum += cc;
}
}
}?

You might also like