stenwiersema
Published

WIFI Weather station

I have made a weather station for a school project

BeginnerShowcase (no instructions)586
WIFI Weather station

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
I used the pro version
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
AA Batteries
AA Batteries
With a casing of coarse
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
3D Printer (generic)
3D Printer (generic)
or wood

Story

Read more

Custom parts and enclosures

The base of the casing

the top of the casing

The pins to secure the top to the base

Schematics

The layout of the weatherstation

Code

The code of the weatherstation

C/C++
// include librarys
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

// define the dht data pin
#define dhtpin 2
#define dhttype DHT11
// name of wifi
#define ssid "WeerStation"
// password for wifi
#define password "P@$$w0rd"

// port number
ESP8266WebServer server(80);

// store http request
String header;

// dht object
DHT dht(dhtpin, dhttype);

// temp and hum var
float temp;
float hum;

// Current time
unsigned long currentTime;
// Previous time
unsigned long previousTime;
// Define timeout time in milliseconds
#define timeoutTime 2000

// Function to handle the root of the site
void handleRoot() {
  // Send a string to the server
  server.send(200,"text/html", sendHTML());
}

void setup() {
  // Begin the serial and DHT
  Serial.begin(115200);
  dht.begin();

  // Connect to Wi-Fi
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.softAP(ssid, password);

  // print ip
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP adress: ");
  Serial.print(WiFi.softAPIP());

  // This will check if someone tries to connect to the root site
  server.on("/", handleRoot);

  // start server
  server.begin();
}

void loop() {
  // This will handle the client
  server.handleClient();
}

// Construct the HTML for the webserver
String sendHTML() {

  // Read the temperature and humidity
  temp = dht.readTemperature();
  hum = dht.readHumidity();

  // This is the HTML for the site
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr += "<title>Weer Station</title>\n";
  ptr += "<style>\n";
  ptr += "body {";
  ptr += "Text-align: center;";
  ptr += "}";
  ptr += "</style>\n";
  ptr += "</head>\n";
  ptr += "<body>\n";
  ptr += "<h1>Weerstation</h1>\n";
  ptr += "<h3>Temperature</h3>\n";
  ptr += "<p>";
  ptr += String(temp);
  ptr += " *C</p>\n";
  ptr += "<h3>Humidity</h3>\n";
  ptr += "<p>";
  ptr += String(hum);
  ptr += "%</p>\n";
  ptr += "</body>\n";
  ptr += "</html>\n";

  return ptr;
}

Credits

stenwiersema
0 projects • 0 followers

Comments