Esp Data Transferring System
This esp controlled system can take data from the surroundings and send it in real time to a webpage.
Components and supplies
1
Jumper wires (generic)
1
Male/Female Jumper Wires
1
NODE MCU ESP8266 12-E
1
9V Battery Clip
1
USB-A to Micro-USB Cable
1
Grove - Barometer Sensor (BMP280)
1
BH1750 light intensity sensor
1
9V battery (generic)
2
Solderless Breadboard Half Size
Apps and platforms
1
Fritzing
1
Arduino IDE
1
Arduino Web Editor
Project description
Code
CODE FOR THE PROJECT
arduino
1#include <ESP8266WebServer.h> 2#include <Wire.h> 3#include <Adafruit_Sensor.h> 4#include 5 <Adafruit_BMP280.h> 6#include <BH1750.h> 7#define SEALEVELPRESSURE_HPA (1013.25) 8IPAddress 9 local_IP(192, 168, 10, 147 ); 10IPAddress gateway(192, 168, 10, 1); 11IPAddress 12 subnet(255, 255, 0, 0); 13IPAddress primaryDNS(8, 8, 8, 8); //optional 14IPAddress 15 secondaryDNS(8, 8, 4, 4); //optional 16Adafruit_BMP280 bmp; 17BH1750 lightMeter; 18float 19 temperature, lux, pressure; 20const char* ssid = "Amit"; // Enter SSID here 21const 22 char* password = "keshariyaji19"; //Enter Password here 23 24 25//change this 26 with the pin that you use 27 28ESP8266WebServer server(80); 29 30 31void setup() { 32 Serial.begin(115200); 33 delay(100); 34 Wire.begin(); 35 36 bmp.begin(0x76); 37lightMeter.begin(); 38 39 Serial.println("Connecting 40 to "); 41 Serial.println(ssid); 42 if (!WiFi.config(local_IP, gateway, subnet, 43 primaryDNS, secondaryDNS)) { 44 Serial.println("STA Failed to configure"); 45 46 } 47 48 WiFi.begin(ssid, password); 49 50 51 while (WiFi.status() != 52 WL_CONNECTED) { 53 delay(1000); 54 Serial.print("."); 55 } 56 Serial.println(""); 57 58 Serial.println("WiFi connected..!"); 59 Serial.print("Got IP: "); Serial.println(WiFi.localIP()); 60 61 62 server.on("/", handle_OnConnect); 63 server.onNotFound(handle_NotFound); 64 65 66 server.begin(); 67 Serial.println("HTTP server started"); 68 69} 70void 71 loop() 72 73{ 74 server.handleClient(); 75} 76 77void handle_OnConnect() 78 { 79 temperature = bmp.readTemperature(); 80 pressure = bmp.readPressure() / 81 100.0F; 82 lux = lightMeter.readLightLevel(); 83 server.send(200, "text/html", 84 SendHTML(temperature,lux,pressure)); 85} 86 87void handle_NotFound(){ 88 server.send(404, 89 "text/plain", "Not found"); 90} 91 92String SendHTML(float temperature,float 93 lux ,float pressure){ 94 String ptr = "<!DOCTYPE html> <html>\ 95"; 96 ptr 97 +="<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0, 98 user-scalable=no\\">\ 99"; 100 ptr +="<title>Trijal's Environment Sensing Station</title>\ 101"; 102 103 ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px 104 auto; text-align: center;background-color:red;}\ 105"; 106 ptr +="body{margin-top: 107 50px;} h1 {color:cyan ;margin: 50px auto 30px;}\ 108"; 109 ptr+= "p {font-size: 110 30px;color: violet ;margin-bottom: 20px;}\ 111"; ptr +="</style>\ 112"; 113 ptr 114 +="</head>\ 115"; 116 ptr +="<body>\ 117"; 118 ptr +="<div id=\\"webpage\\">\ 119"; 120 121 ptr +="<h1>TRIJAL'S ENVIRONMENTAL STATION</h1>\ 122"; 123 ptr +="<p>Temperature: 124 "; 125 ptr +=temperature; 126 ptr +="°C</p>"; 127 ptr +="<p>Light Intensity: 128 "; 129 ptr +=lux; 130 ptr +="lux</p>"; 131 ptr +="<p>Pressure: "; 132 ptr 133 +=pressure; 134 ptr +="hPa</p>"; 135 ptr +="</div>\ 136"; 137 ptr +="</body>\ 138"; 139 140 ptr +="</html>\ 141"; 142 143return ptr; 144 } 145
CODE FOR THE PROJECT
arduino
1#include <ESP8266WebServer.h> 2#include <Wire.h> 3#include <Adafruit_Sensor.h> 4#include <Adafruit_BMP280.h> 5#include <BH1750.h> 6#define SEALEVELPRESSURE_HPA (1013.25) 7IPAddress local_IP(192, 168, 10, 147 ); 8IPAddress gateway(192, 168, 10, 1); 9IPAddress subnet(255, 255, 0, 0); 10IPAddress primaryDNS(8, 8, 8, 8); //optional 11IPAddress secondaryDNS(8, 8, 4, 4); //optional 12Adafruit_BMP280 bmp; 13BH1750 lightMeter; 14float temperature, lux, pressure; 15const char* ssid = "Amit"; // Enter SSID here 16const char* password = "keshariyaji19"; //Enter Password here 17 18 19//change this with the pin that you use 20 21ESP8266WebServer server(80); 22 23void setup() { 24 Serial.begin(115200); 25 delay(100); 26 Wire.begin(); 27 bmp.begin(0x76); 28lightMeter.begin(); 29 30 Serial.println("Connecting to "); 31 Serial.println(ssid); 32 if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) { 33 Serial.println("STA Failed to configure"); 34 } 35 36 WiFi.begin(ssid, password); 37 38 39 while (WiFi.status() != WL_CONNECTED) { 40 delay(1000); 41 Serial.print("."); 42 } 43 Serial.println(""); 44 Serial.println("WiFi connected..!"); 45 Serial.print("Got IP: "); Serial.println(WiFi.localIP()); 46 47 server.on("/", handle_OnConnect); 48 server.onNotFound(handle_NotFound); 49 50 server.begin(); 51 Serial.println("HTTP server started"); 52 53} 54void loop() 55 56{ 57 server.handleClient(); 58} 59 60void handle_OnConnect() { 61 temperature = bmp.readTemperature(); 62 pressure = bmp.readPressure() / 100.0F; 63 lux = lightMeter.readLightLevel(); 64 server.send(200, "text/html", SendHTML(temperature,lux,pressure)); 65} 66 67void handle_NotFound(){ 68 server.send(404, "text/plain", "Not found"); 69} 70 71String SendHTML(float temperature,float lux ,float pressure){ 72 String ptr = "<!DOCTYPE html> <html>\ 73"; 74 ptr +="<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0, user-scalable=no\\">\ 75"; 76 ptr +="<title>Trijal's Environment Sensing Station</title>\ 77"; 78 ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;background-color:red;}\ 79"; 80 ptr +="body{margin-top: 50px;} h1 {color:cyan ;margin: 50px auto 30px;}\ 81"; 82 ptr+= "p {font-size: 30px;color: violet ;margin-bottom: 20px;}\ 83"; ptr +="</style>\ 84"; 85 ptr +="</head>\ 86"; 87 ptr +="<body>\ 88"; 89 ptr +="<div id=\\"webpage\\">\ 90"; 91 ptr +="<h1>TRIJAL'S ENVIRONMENTAL STATION</h1>\ 92"; 93 ptr +="<p>Temperature: "; 94 ptr +=temperature; 95 ptr +="°C</p>"; 96 ptr +="<p>Light Intensity: "; 97 ptr +=lux; 98 ptr +="lux</p>"; 99 ptr +="<p>Pressure: "; 100 ptr +=pressure; 101 ptr +="hPa</p>"; 102 ptr +="</div>\ 103"; 104 ptr +="</body>\ 105"; 106 ptr +="</html>\ 107"; 108 109return ptr; 110 } 111
Downloadable files
FRITZING FILE FOR THE PROJECT
FRITZING FILE FOR THE PROJECT
Comments
Only logged in users can leave comments