nawfaldo
Published © GPL3+

Temperature detector

We can see our room temperature with low budget

BeginnerShowcase (no instructions)1 hour525
Temperature detector

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
Female/Female Jumper Wires
Female/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Code

Untitled file

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 = "redmi"; // Your wifi name
const char *pswd = "redmiwaw43"; // 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

nawfaldo
9 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.