Professional Documents
Culture Documents
NODEMCU ESP8266
void loop() {
client.println("<body><h1
delay(500);
lcd.clear(); style=\"color:orange;\"> Air Quality Measurement
lcd.setCursor(0, 0); </h1>");
#include <ESP8266WiFi.h>
#include <LiquidCrystal.h> lcd.print("Pollution=");
const int rs = D0, en = D1, d4 = D4, d5 = D5, d6 = D6, d7 = D7; air_quality = ((analogRead(A0)/1024.0)*100.0); client.println("<body><p style=\"color:blue;\">
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); lcd.print(air_quality); Pollution Content(in percentage) = " +
lcd.print("%"); String(air_quality) +" %"+ " </p>");
const char *ssid = "Mamameya"; // Enter your WiFi Name Serial.println(air_quality); if(air_quality <= 20.0 ){
const char *pass = "244466666"; // Enter your WiFi Password client.println("<body><p style=\"color:green;\">
//// put your main code here, to run repeatedly: Normal </p>");
WiFiServer server(80); } else if (air_quality > 20.0 && air_quality <
WiFiClient client = server.available();
70.0){
double air_quality; if ( client.connected()) { // loop while the client's connected
// HTTP headers always start with a response code (e.g. client.println("<body><p style=\"color:purple;\">
void setup() {
HTTP/1.1 200 OK) Medium </p>");
Serial.begin(115200);
lcd.begin(16, 2); client.println("HTTP/1.1 200 OK"); } else {
delay(10); client.println("Content-type:text/html"); client.println("<body><p style=\"font-size:200%;
Serial.println("Connecting to "); client.println("Connection: close"); color:red\"> Danger!!! </p>");
lcd.print("Connecting.... "); client.println("Refresh: 3"); // update the page after 4 sec }
Serial.println(ssid); client.println();
WiFi.begin(ssid, pass); client.println("</body></html>");
while (WiFi.status() != WL_CONNECTED) // turns the GPIOs on and off delay(1000);
{ lcd.setCursor(0,1);
delay(550); lcd.print("Sending Data" );
lcd.clear();
Serial.print("."); lcd.setCursor(0, 0);
lcd.print("."); // Display the HTML web page
client.println("<!DOCTYPE html><html>"); lcd.print("Pollution=");
}
Serial.println(""); client.println("<head><meta name=\"viewport\" lcd.print(air_quality);
Serial.println("WiFi connected"); content=\"width=device-width, initial-scale=1\">"); lcd.print("%");
Serial.print("IP Address: "); client.println("<link rel=\"icon\" href=\"data:,\">"); }
Serial.println(WiFi.localIP()); }
server.begin();
}
WORKING
In the beginning, the nodeMCU is operated in station mode and waits for an active LAN to connect. After connecting to a LAN, it
will display the IP address by which we can visit the webpage and monitor the data. We display the IP address over the serial
monitor. Note down the IP address and enter this IP address in your web browse to monitor the pollution content on the
webpage. To check the working of the MQ sensor, you can just test it by providing any gas near to it. As shown in the video below,
I just used a lighter to test the working of the MQ sensor. If the pollution content is more than 20% of the maximum value, then I
considered it as normal. If the value is more than 20% and less than 70% of the maximum value, then it is medium, and if the
value is more than 70% of the maximum value, then it is considered as dangerous level.