Daini
Published © CC BY

Weather station on screen

We can easily get the weather data of the city we live in with the help of smartphones

BeginnerFull instructions provided1 hour984
Weather station on screen

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic For this project

Code

Code

Arduino
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <DHT.h>

#define DHTPIN 0

DHT dht(DHTPIN,DHT11);

const char* ssid = "Rail Net";
const char* password = "sharan*123*";


const char* serverName = "http://api.thingspeak.com/update";
// Service API Key
String apiKey = "2SED294GR9XL0U7C";


unsigned long lastTime = 0;
unsigned long timerDelay = 10000;

void setup() {
  Serial.begin(9600);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
 
  Serial.println("Timer set to 10 seconds (timerDelay variable), it will take 10 seconds before publishing the first reading.");

  randomSeed(analogRead(0));
}

void loop() {
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  
  if ((millis() - lastTime) > timerDelay) {
   
    if(WiFi.status()== WL_CONNECTED){
      HTTPClient http;
      
     
      http.begin(serverName);
      

      http.addHeader("Content-Type", "application/x-www-form-urlencoded");

      String httpRequestData = "api_key=" + apiKey + "&field1=" + String(t)+ "&field2=" + String(h);           

      int httpResponseCode = http.POST(httpRequestData);
      
     
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
        

      http.end();
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    lastTime = millis();
  }
}

Credits

Daini
31 projects • 17 followers

Comments