Professional Documents
Culture Documents
#define PIN_DATA_OUT A0 //Connect the IO port of the GP2 sensor analog A0 output
#define PIN_LED_VCC 2 //The pin in the GP2 sensor that supplies power to the
internal Led
int redLed = 9;
int relay = 5;
/**
*/
double getOutputV() {
digitalWrite(PIN_LED_VCC, LOW);
delayMicroseconds(DELAY_BEFORE_SAMPLING);
delayMicroseconds(DELAY_AFTER_SAMPLING);
digitalWrite(PIN_LED_VCC, HIGH);
delayMicroseconds(DELAY_LED_OFF);
return outputV;
}
/**
*/
if (ugm3 < 0) {
ugm3 = 0;
return ugm3;
/**
*/
double aqiL = 0;
double aqiH = 0;
double bpL = 0;
double bpH = 0;
double aqi = 0;
//According to the correspondence between pm2.5 and aqi were calculated aqi
aqiL = 0;
aqiH = 50;
bpL = 0;
bpH = 35;
} else if (ugm3 > 35 && ugm3 <= 75) {
aqiL = 50;
aqiH = 100;
bpL = 35;
bpH = 75;
aqiL = 100;
aqiH = 150;
bpL = 75;
bpH = 115;
aqiL = 150;
aqiH = 200;
bpL = 115;
bpH = 150;
aqiL = 200;
aqiH = 300;
bpL = 150;
bpH = 250;
aqiL = 300;
aqiH = 400;
bpL = 250;
bpH = 350;
aqiL = 400;
aqiH = 500;
bpL = 350;
bpH = 500;
}
//formula: aqi = (aqiH - aqiL) / (bpH - bpL) * (desity - bpL) + aqiL;
return aqi;
/**
*/
String gradeInfo;
gradeInfo = String("Perfect");
gradeInfo = String("Good");
} else {
return gradeInfo;
void setup() {
Serial.begin(115200);
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(orangeLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
void loop() {
delay(1000);
Serial.println(analogSensor);
digitalWrite(redLed, HIGH);
digitalWrite(orangeLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(relay, LOW);
else
digitalWrite(redLed, LOW);
digitalWrite(orangeLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(relay, HIGH);
delay(100);