-
Notifications
You must be signed in to change notification settings - Fork 0
/
FULLSTACK.ino
122 lines (93 loc) · 2.61 KB
/
FULLSTACK.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
int measurePin = A5;
int ledPower = 12;
unsigned int samplingTime = 280;
unsigned int deltaTime = 40;
unsigned int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustavg = 0;
float avg; // value for moving average
unsigned long n; // number of samples
float t; // value for current sample
void setup()
{
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
for (int i = 1; i <= 60; i++)
{
delay(1000); // 1s
Serial.print(i);
Serial.println(" s (wait 60s for Device to warm up)");
}
Serial.println("Ready!");
}
void loop()
{
digitalWrite(ledPower,LOW);
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin);
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH);
delayMicroseconds(sleepTime);
calcVoltage = voMeasured*(5.0/1024);
dustavg = (0.17*calcVoltage-0.1)*1000;
if ( dustavg < 0)
{
dustavg = 0.00;
}
Serial.println("Raw Signal Value (0-1023):");
Serial.println(voMeasured);
Serial.println("Voltage:");
Serial.println(calcVoltage);
Serial.println("Dust avg [ug/m3] :");
Serial.println(dustavg);
// get sample
t = dustavg;
// update sample count
n++;
//calculate moving average
avg += (t - avg) / n;
Serial.println("Average Concentration [ug/m3] : ");
Serial.println(avg);
delay(3600000);
unsigned int sycn=',';
if ( avg == 0 ) {
Serial.println("AQI : 0 (Good)");
return 0;
}
else if ( avg <=120 ) {
int aqi=( 50 - 0 ) * ( avg - 0 ) / ( 120 - 0 ) + 0;
Serial.println("AQI : ");
Serial.println(aqi);
Serial.println("Good");
}
else if (avg <=354 ) {
int aqi= ( 100 - 51 ) * ( avg - 121 ) / ( 354 - 121 ) + 51;
Serial.println("AQI : ");
Serial.println(aqi);
Serial.println("Satisfactory");
}
else if (avg <=554 ) {
int aqi= ( 150 - 101 ) * ( avg - 355 ) / ( 554 - 355 ) + 101;
Serial.println("AQI : ");
Serial.println(aqi);
Serial.println("Moderately Polluted");
}
else if (avg <=1504 ) {
int aqi= ( 200 - 151 ) * ( avg - 555 ) / ( 1504 - 555 ) + 151;
Serial.println("AQI : ");
Serial.println(aqi);
Serial.println("Poor");
}
else if (avg <=2504 ) {
int aqi= ( 300 - 201 ) * ( avg - 2504 ) / ( 2504 - 1505 ) + 201;
Serial.println("AQI : ");
Serial.println(aqi);
Serial.println("Very Poor");
}
else if (avg <=3504 ) {
int aqi= ( 500 - 401 ) * ( avg - 2505 ) / ( 5004 - 2505 ) + 401;
Serial.println("AQI : ");
Serial.println(aqi);
Serial.println("Severe");
} }