Skip to content

Commit 8580b83

Browse files
committed
Add correction for values
1 parent 3986a2d commit 8580b83

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

doc/correction.xlsx

29.3 KB
Binary file not shown.

src/SDS011.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525

2626
#include <SDS011.h>
2727

28+
#include <math.h> // for pow()
29+
2830
SDS011::SDS011() :
2931
_serial(nullptr),
3032
_onData(nullptr),
@@ -151,3 +153,29 @@ bool SDS011::_checkCRC(uint8_t buff[], uint8_t crc) {
151153
}
152154
return crc == crc_calc;
153155
}
156+
157+
float SDS011::correct(float pm2_5, float humidity, float factor, float exp) {
158+
if (humidity == 100 || factor == 0) return 0;
159+
float pm2_5_corr = pm2_5 / pow(factor * (100 - humidity), exp);
160+
return pm2_5_corr;
161+
}
162+
163+
float SDS011::correct(float pm2_5, float humidity, Correction correction) {
164+
float factor = 0.0;
165+
float exponent = 0.0;
166+
switch (correction) {
167+
case AMSTERDAM:
168+
factor = 2.3;
169+
exponent = -0.38;
170+
break;
171+
case AMERSFOORT:
172+
factor = 3.4;
173+
exponent = -0.4;
174+
break;
175+
case VENLO:
176+
factor = 3.9;
177+
exponent = -0.43;
178+
break;
179+
}
180+
return correct(pm2_5, humidity, factor, exponent);
181+
}

src/SDS011.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,13 @@ class SDS011 {
5757
onErrorHandler _onError;
5858
uint8_t _rxBuff[10];
5959
uint8_t _txBuff[19];
60+
61+
public:
62+
float correct(float raw, float humidity, float factor, float exp);
63+
enum Correction {
64+
AMSTERDAM,
65+
AMERSFOORT,
66+
VENLO
67+
};
68+
float correct(float raw, float humidity, Correction correction);
6069
};

0 commit comments

Comments
 (0)