Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- const char* ssid = "Be Happy";
- const char* password = "1234567890";
- ESP8266WebServer server(80);
- String page = "";
- int data, data1;
- int counter;
- int currentState = 0;
- int previousState = 0;
- String data2 = "NULL";
- void setup() {
- pinMode(D2, INPUT);
- pinMode(D3, INPUT);
- Wire.begin(2, 0);
- lcd.init();
- lcd.backlight();
- lcd.print("Pulse Counter");
- delay(1000);
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- Serial.println("");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Connected to ");
- lcd.setCursor(0, 1);
- lcd.print(ssid);
- delay(1000);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("IP address: ");
- lcd.setCursor(0, 1);
- lcd.print(WiFi.localIP());
- delay(1000);
- if (data1==1)
- data2 = "ON";
- if (data1 ==0)
- data2 = "OFF";
- server.on("/", []() {
- page = "<h1>Unit-II</h1><h2>Status:</h2> <h4>" + data2 + "</h4><h3>Pulse:</h3> <h4>" + String(counter) + "</h4><script>location.reload();</script>";
- server.send(200, "text/html", page);
- });
- server.begin();
- Serial.println("Web server started!");
- }
- void loop() {
- data1 = digitalRead(D3);
- data = digitalRead(D2);
- if (data1 == HIGH) {
- if (data == HIGH) {
- currentState = 1;
- }
- else {
- currentState = 0;
- }
- if (currentState != previousState) {
- if (currentState == 1) {
- counter = counter + 1;
- Serial.print("Unit-II ");
- Serial.println("ON");
- Serial.print("Pulse= ");
- Serial.println(counter);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Unit-II");
- lcd.setCursor(9, 0);
- lcd.print("ON");
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print("Pulse= ");
- lcd.setCursor(7, 1);
- lcd.print(counter);
- }
- }
- previousState = currentState;
- }
- else {
- Serial.print("Unit-II ");
- Serial.println("OFF");
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Unit-II ");
- lcd.setCursor(9, 1);
- lcd.print("OFF");
- }
- server.handleClient();
- }
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="stylesheet.css">
- <title>Machine Data</title>
- </head>
- <body>
- <iframe src="http://192.168.43.XXX">
- </iframe>
- <iframe src="http://192.168.43.XXX">
- </iframe>
- </body>
- </html>
Add Comment
Please, Sign In to add comment