Naufal Faqiih Ashshiddiq
Published © GPL3+

Making a Temperatur and controll it using WEBSITE!

Coding is so FUN! you can make a Temperature progress in Wbsite!

BeginnerFull instructions provided1 hour315
Making a Temperatur and controll it using WEBSITE!

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×3
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Code

DHT11 Thing Speak

C/C++
// Download ESP8266 and DHT in your Arduino libraries

#include <ESP8266WiFi.h>
#include <DHT.h>

#define dhtpin 5 // Pin D1
#define DHTTYPE DHT11

DHT dht (dhtpin, DHTTYPE);
WiFiClient client;

String apiKey = "TM83AXXIJ2ZTRG2F"; // You will get apiKey in the Website

const char *ssid = "Naufal"; // Your wifi name
const char *pswd = "Naufal2020"; // Your wifi password
const char *server = "api.thingspeak.com"; // The website

void setup() {
  Serial.begin(115200);
  delay(10);
  dht.begin();
Serial.println ("Connecting to ");
  Serial.println(ssid);
WiFi.begin(ssid,pswd);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(".");
   
  }
  Serial.println("");
  Serial.println("WiFi connected");
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h)||isnan(t)){
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
if(client.connect(server, 80)) {
  String postStr= apiKey;
  postStr += "&field1=";
  postStr += String(t);
  postStr += "&field2=";
  postStr += String(h);
  postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
 Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" degrees Celcius, Humidity: ");
    Serial.print(h);
    Serial.print("%. Send to Thingspeak.");
  }
  client.stop();
  Serial.println("Waiting...");
  delay(1000);
}

Credits

Naufal Faqiih Ashshiddiq
7 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.