-
Notifications
You must be signed in to change notification settings - Fork 1
/
AQNFINAL.ino
47 lines (41 loc) · 1.06 KB
/
AQNFINAL.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
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
const char* ssid = "WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
WiFiClient client;
unsigned long tsChannelID = 2118781; // ThingSpeak Channel ID
const char * tsWriteAPIKey = "F2JEFP42K5J4Q9O1"; //ThingSpeak Write API Key
int airQuality = 0;
const int fieldOne = 1;
int mq135 = A0; // smoke sensor is connected with the analog pin A0
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
setup_wifi();
}
void loop()
{
airQuality = analogRead(mq135);
Serial.println(airQuality);
pushData();
delay(15000); // send data every 15 seconds
}
void setup_wifi(){
WiFi.begin(ssid, password);
delay(10);
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(1000);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void pushData()
{
ThingSpeak.writeField(tsChannelID, fieldOne, airQuality, tsWriteAPIKey);
delay(100); // wait for the data to be written to ThingSpeak
}