mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-29 00:17:16 +02:00
improved examples code
This commit is contained in:
@ -10,25 +10,45 @@ Plantower PMS5003 (Fine Particle Sensor)
|
||||
|
||||
Please install ESP8266 board manager (tested with version 3.0.0)
|
||||
|
||||
If you have any questions please visit our forum at https://forum.airgradient.com/
|
||||
|
||||
If you are a school or university contact us for a free trial on the AirGradient platform.
|
||||
https://www.airgradient.com/schools/
|
||||
|
||||
Kits with all required components are available at https://www.airgradient.com/diyshop/
|
||||
|
||||
MIT License
|
||||
*/
|
||||
|
||||
#include <AirGradient.h>
|
||||
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
ag.PMS_Init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
int PM2 = ag.getPM2_Raw();
|
||||
Serial.print("PM2: ");
|
||||
Serial.println(ag.getPM2());
|
||||
void loop() {
|
||||
|
||||
delay(5000);
|
||||
int PM2 = ag.getPM2_Raw();
|
||||
|
||||
Serial.print("PM2.5 in ug/m3: ");
|
||||
Serial.println(String(PM2));
|
||||
|
||||
Serial.print("PM2.5 in US AQI: ");
|
||||
Serial.println(String(PM_TO_AQI_US(PM2)));
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
int PM_TO_AQI_US(int pm02) {
|
||||
if (pm02 <= 12.0) return ((50 - 0) / (12.0 - .0) * (pm02 - .0) + 0);
|
||||
else if (pm02 <= 35.4) return ((100 - 50) / (35.4 - 12.0) * (pm02 - 12.0) + 50);
|
||||
else if (pm02 <= 55.4) return ((150 - 100) / (55.4 - 35.4) * (pm02 - 35.4) + 100);
|
||||
else if (pm02 <= 150.4) return ((200 - 150) / (150.4 - 55.4) * (pm02 - 55.4) + 150);
|
||||
else if (pm02 <= 250.4) return ((300 - 200) / (250.4 - 150.4) * (pm02 - 150.4) + 200);
|
||||
else if (pm02 <= 350.4) return ((400 - 300) / (350.4 - 250.4) * (pm02 - 250.4) + 300);
|
||||
else if (pm02 <= 500.4) return ((500 - 400) / (500.4 - 350.4) * (pm02 - 350.4) + 400);
|
||||
else return 500;
|
||||
};
|
||||
|
Reference in New Issue
Block a user