Devices & Components
AA Batteries
DHT11 Temperature & Humidity Sensor (4 pins)
Wemos D1 Mini
Hardware & Tools
3D Printer (generic)
Soldering iron (generic)
Hot glue gun (generic)
Software & Tools
Arduino IDE
Project description
Code
The code of the weatherstation
c_cpp
1// include librarys 2#include <DHT.h> 3#include <ESP8266WiFi.h> 4#include <ESP8266WebServer.h> 5 6// define the dht data pin 7#define dhtpin 2 8#define dhttype DHT11 9// name of wifi 10#define ssid "WeerStation" 11// password for wifi 12#define password "P@$$w0rd" 13 14// port number 15ESP8266WebServer server(80); 16 17// store http request 18String header; 19 20// dht object 21DHT dht(dhtpin, dhttype); 22 23// temp and hum var 24float temp; 25float hum; 26 27// Current time 28unsigned long currentTime; 29// Previous time 30unsigned long previousTime; 31// Define timeout time in milliseconds 32#define timeoutTime 2000 33 34// Function to handle the root of the site 35void handleRoot() { 36 // Send a string to the server 37 server.send(200,"text/html", sendHTML()); 38} 39 40void setup() { 41 // Begin the serial and DHT 42 Serial.begin(115200); 43 dht.begin(); 44 45 // Connect to Wi-Fi 46 Serial.print("Connecting to "); 47 Serial.println(ssid); 48 WiFi.softAP(ssid, password); 49 50 // print ip 51 Serial.println(""); 52 Serial.println("WiFi connected"); 53 Serial.println("IP adress: "); 54 Serial.print(WiFi.softAPIP()); 55 56 // This will check if someone tries to connect to the root site 57 server.on("/", handleRoot); 58 59 // start server 60 server.begin(); 61} 62 63void loop() { 64 // This will handle the client 65 server.handleClient(); 66} 67 68// Construct the HTML for the webserver 69String sendHTML() { 70 71 // Read the temperature and humidity 72 temp = dht.readTemperature(); 73 hum = dht.readHumidity(); 74 75 // This is the HTML for the site 76 String ptr = "<!DOCTYPE html> <html>\ 77"; 78 ptr += "<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0, user-scalable=no\\">\ 79"; 80 ptr += "<title>Weer Station</title>\ 81"; 82 ptr += "<style>\ 83"; 84 ptr += "body {"; 85 ptr += "Text-align: center;"; 86 ptr += "}"; 87 ptr += "</style>\ 88"; 89 ptr += "</head>\ 90"; 91 ptr += "<body>\ 92"; 93 ptr += "<h1>Weerstation</h1>\ 94"; 95 ptr += "<h3>Temperature</h3>\ 96"; 97 ptr += "<p>"; 98 ptr += String(temp); 99 ptr += " *C</p>\ 100"; 101 ptr += "<h3>Humidity</h3>\ 102"; 103 ptr += "<p>"; 104 ptr += String(hum); 105 ptr += "%</p>\ 106"; 107 ptr += "</body>\ 108"; 109 ptr += "</html>\ 110"; 111 112 return ptr; 113} 114
The code of the weatherstation
c_cpp
1// include librarys 2#include <DHT.h> 3#include <ESP8266WiFi.h> 4#include 5 <ESP8266WebServer.h> 6 7// define the dht data pin 8#define dhtpin 2 9#define 10 dhttype DHT11 11// name of wifi 12#define ssid "WeerStation" 13// password 14 for wifi 15#define password "P@$$w0rd" 16 17// port number 18ESP8266WebServer 19 server(80); 20 21// store http request 22String header; 23 24// dht object 25DHT 26 dht(dhtpin, dhttype); 27 28// temp and hum var 29float temp; 30float hum; 31 32// 33 Current time 34unsigned long currentTime; 35// Previous time 36unsigned long 37 previousTime; 38// Define timeout time in milliseconds 39#define timeoutTime 2000 40 41// 42 Function to handle the root of the site 43void handleRoot() { 44 // Send a string 45 to the server 46 server.send(200,"text/html", sendHTML()); 47} 48 49void 50 setup() { 51 // Begin the serial and DHT 52 Serial.begin(115200); 53 dht.begin(); 54 55 56 // Connect to Wi-Fi 57 Serial.print("Connecting to "); 58 Serial.println(ssid); 59 60 WiFi.softAP(ssid, password); 61 62 // print ip 63 Serial.println(""); 64 65 Serial.println("WiFi connected"); 66 Serial.println("IP adress: "); 67 68 Serial.print(WiFi.softAPIP()); 69 70 // This will check if someone tries to 71 connect to the root site 72 server.on("/", handleRoot); 73 74 // start server 75 76 server.begin(); 77} 78 79void loop() { 80 // This will handle the client 81 82 server.handleClient(); 83} 84 85// Construct the HTML for the webserver 86String 87 sendHTML() { 88 89 // Read the temperature and humidity 90 temp = dht.readTemperature(); 91 92 hum = dht.readHumidity(); 93 94 // This is the HTML for the site 95 String 96 ptr = "<!DOCTYPE html> <html>\ 97"; 98 ptr += "<head><meta name=\\"viewport\\" 99 content=\\"width=device-width, initial-scale=1.0, user-scalable=no\\">\ 100"; 101 102 ptr += "<title>Weer Station</title>\ 103"; 104 ptr += "<style>\ 105"; 106 ptr 107 += "body {"; 108 ptr += "Text-align: center;"; 109 ptr += "}"; 110 ptr 111 += "</style>\ 112"; 113 ptr += "</head>\ 114"; 115 ptr += "<body>\ 116"; 117 ptr 118 += "<h1>Weerstation</h1>\ 119"; 120 ptr += "<h3>Temperature</h3>\ 121"; 122 ptr 123 += "<p>"; 124 ptr += String(temp); 125 ptr += " *C</p>\ 126"; 127 ptr += "<h3>Humidity</h3>\ 128"; 129 130 ptr += "<p>"; 131 ptr += String(hum); 132 ptr += "%</p>\ 133"; 134 ptr += 135 "</body>\ 136"; 137 ptr += "</html>\ 138"; 139 140 return ptr; 141} 142
Downloadable files
The layout of the weatherstation
The layout of the weatherstation
The layout of the weatherstation
The layout of the weatherstation
Documentation
The pins to secure the top to the base
The pins to secure the top to the base
the top of the casing
the top of the casing
the top of the casing
the top of the casing
The pins to secure the top to the base
The pins to secure the top to the base
The base of the casing
The base of the casing
Comments
Only logged in users can leave comments