Hackster is hosting Impact Spotlights: Industrial Automation. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Industrial Automation. Stream on Thursday!
Amaan Javed
Published

Wifi weather station

A wifi weather station for home/office it gives some imp information about the weather outside on webserver so it's accessible to every one

BeginnerWork in progress1 hour573
Wifi weather station

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering Station, 110 V
Soldering Station, 110 V

Story

Read more

Code

wifi weather station

Arduino
just paste ip of board on web browser
#include <ESP8266WiFi.h>
#include <dht11.h>
#define DHT11PIN 13//dht11 on D7
const char* ssid = "speed";//give your ssid 
const char* password = "12345678";//give your passkey
dht11 DHT11;
int led =  5;//ldr sensor on D1
int rain = 4;//rain sensor `on D2
int pos = 2;// light that turns on in day and turn off in night on D4
int rainval;
int val;
int dos;
int gas = 16;// web page controled light on D0
//
WiFiServer server(80);
void setup() {
  pinMode(led,INPUT);
  pinMode(rain,INPUT);
  pinMode(gas,OUTPUT);
  pinMode(pos,OUTPUT);
  WiFi.begin(ssid, password);// or you can also put the pass and ssid here to connect
  server.begin();
}
 
void loop() {
  
  int chk = DHT11.read(DHT11PIN);
  val = analogRead(led);
  dos = val/1023*100;
  rainval = digitalRead(rain);
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  String request = client.readStringUntil('\r');
  client.flush();
  if (request.indexOf("/action_page.php?fname=1") != -1)  {
    digitalWrite(gas, HIGH);
  }
 else if (request.indexOf("/action_page.php?fname=0") != -1)  {
    digitalWrite(gas, 0);
  }
  // if you know html then it will be easy to do that for you
  // you can also edit this as you want
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); 
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.println("<center>");
  client.println("<h1 style=background-color:DodgerBlue;>WEATHER STATION</h1>");
  client.println("</center>");
  client.println("<h3 style=color:DodgerBlue;>HUMI (%);</h3>");
  client.print((float)DHT11.humidity, 2); 
  client.println("<h3 style=color:GOLD;>TEMP (C):</h3>");
  client.print((float)DHT11.temperature, 2);
  client.println("<h3 style=color:DimGrey;>Light Intensity(%):</h3>");
  client.print(dos);
   client.println("<h3 style=color:Blue;>RAIN:</h3>");
    //if(rainval = 1) if you have rain se4nsor then you can re3move these slash
 //{
  client.print("Rain sens not connected");
 //}
 //else{
  //client.print("NO Raining");
  //}
  client.println("<h3 style=color:Coral;>Time:</h3>");
  if (dos = 0){// tghis is for light that turn off in night and turn in day
    client.print("NIGHT");
    digitalWrite(pos,0);
  }
  else{
    client.print("DAY");
    digitalWrite(pos,1);
  }
  client.print("<h3 style=color:Red;>Play Music:</h3>");
  client.print("<p><a href=https://youtu.be/tYQ1Okyi3g4>CLICK HERE</a></p>");// url of my fav music you can also replace this
  client.print("<h3 style=color:Crimson;>NEWS:</h3>");
  client.print("<p><a href=https://timesofindia.indiatimes.com/>CLICK HERE</a></p>");// url og toi page you can also edit this
  client.print("<form action=/action_page.php>");
  client.print("<label for=fname>Commands for Led:</label><br>");
  client.print("<input type=text id=fname name=fname><br><br>");
  client.print("<input type=submit value=Submit>");
  client.print("</form>");
  client.print("<center>");
  client.print("<h1 style=background-color:DodgerBlue;>BY AMAAN JAVED</h1>");
  client.print("</center>");
  client.println("</html>");
  delay(1); 
}

Credits

Amaan Javed
19 projects • 4 followers
Student
Contact

Comments

Please log in or sign up to comment.