-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch_jan09a.ino
128 lines (115 loc) · 3.22 KB
/
sketch_jan09a.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
123
124
125
126
127
128
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#include <WiFi.h>
#include "ThingSpeak.h"
const char *ssid = "ZARONE 5G"; //Your wifi ssid
const char *pass = "zarone.HBF#"; //Your wifi passphrase
const char* server = "api.thingspeak.com";
unsigned long Channel_ID = 1427538; // Channel ID
const char *WriteAPIKey = "17MUQ90S3BKG9ARH"; // Your write API Key
WiFiClient client;
#define DHTPIN 27
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight();
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
pinMode(34, INPUT);
Serial.begin(9600);
delay(200);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Air Quality");
lcd.setCursor(0,1);
lcd.print("Monitor System");
delay(1500);
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
Serial.print(".");
delay(3500);
}
Serial.println("\nConnected.");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Connected to :");
lcd.setCursor(0,1);
lcd.print(ssid);
}
else {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Fail to connect");
lcd.setCursor(0,1);
lcd.print("to ");
lcd.setCursor(2,1);
lcd.print(ssid);
}
lcd.clear();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Humidity : ");
Serial.println(h);
Serial.print("Temperature :");
Serial.println(t);
int MQ135 = analogRead(34); //For NH3, NOx, Alcohol, Benzene, Smoke, CO2
MQ135 = map(MQ135,0,4095,0,300);
Serial.print("MQ135: ");
Serial.println(MQ135);
int x = ThingSpeak.writeField(Channel_ID, 1, h, WriteAPIKey);
int y = ThingSpeak.writeField(Channel_ID, 2, t, WriteAPIKey);
int z = ThingSpeak.writeField(Channel_ID, 3, MQ135, WriteAPIKey);
delay(300);
//lcd.clear();
if (MQ135<50) {
lcd.setCursor(0,0);
lcd.print("Air Quality : ");
lcd.setCursor(0,1);
lcd.print("GOOD");
}
if (MQ135>50 && MQ135<100) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Air Quality : ");
lcd.setCursor(0,1);
lcd.print("MODERATE");
}
else if (MQ135>100 && MQ135<150) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Air Quality : ");
lcd.setCursor(0,1);
lcd.print("Good");
}
else if (MQ135>150 && MQ135<200) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Air Quality : ");
lcd.setCursor(0,1);
lcd.print("Moderate");
}
else if (MQ135>200 && MQ135<300) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Air Quality : ");
lcd.setCursor(0,1);
lcd.print("UNHEALTHY");
}
else if (MQ135>300 && MQ135<500) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Air Quality : ");
lcd.setCursor(0,1);
lcd.print("HAZARDOUS");
delay(200);
}}