-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAir_quality_Control.ino
66 lines (46 loc) · 1.27 KB
/
Air_quality_Control.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
#include <ESP8266WiFi.h>;
#include <ThingSpeak.h>;
char ssid[] = "k27"; //Your Network SSID
char password[]= "987654321"; //Your Network Password
int sensor = A0; //GAS Sensor Connected at A0 Pin, MQ135 sensor for air quality
unsigned long myChannelNumber = 868392; //Your Channel Number (Without Brackets)
const char * myWriteAPIKey = "7LO7B1H83O0R5OJQ"; //Your Write API Key
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10); // Connect to WiFi network
while(WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, password);
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
ThingSpeak.begin(client);
pinMode(sensor,INPUT);
}
void loop()
{
int val = analogRead(sensor); //Read Analog values and Store in val variable
Serial.println(val); //Print on Serial Monitor
if (val>500)
{
Serial.println("Bad air quality.")
}
else
{
Serial.println("Air is safe to breathe")
}
delay(1000);
int x = ThingSpeak.writeField(myChannelNumber, 1,val, myWriteAPIKey); //Update in ThingSpeak
if(x == 200)
{
Serial.println("Channel update successful.");
}
else
{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
delay(3000);
}