Simulasi Monitoring Suhu dengan Sensor DHT11 dan ESP32


Langkah Dasar

Instalasi DHT Sensor Library:

untuk menginstal libary dht11, klik sketch > include Library > Manage Library.
Arduino Library Installation - Selecting Manage Libraries in Arduino IDE
Setelah itu, cari di kotak pencarian dan ketik DHT sensor lalu pilih DHT sensor library by adafruit dan install
Adafruit DHT library Installation
setelah diinstall lalu ketik di kolom pencarian Adafruit Unifed Sensor
dan pilih dan instal Adafruit Unifed Sensor by Adafruit
Adafruit Unified Sensor library Installation




IoT Server 
 


Membuat Project IoT Server di Arduino IDE:
1. Buka Arduino IDE
2. buat project Baru (File > New Project)
3. lalu buat koding program untuk IoT Server di bawah ini

Coding server:

#include <WiFi.h>
#include <WebServer.h>
#include "DHT.h"

// Uncomment one of the lines below for whatever DHT sensor type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

//Put your SSID & Password//
const char* ssid = "your network name";  // Enter SSID here
const char* password = "your password ";  //Enter Password here

WebServer server(80);

// DHT Sensor
uint8_t DHTPin = 4;
           
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);           

float Temperature;
float Humidity;

void setup() {
  Serial.begin(115200);
  delay(100);

  pinMode(DHTPin, INPUT);

  dht.begin();         

  Serial.println("Connecting to ");
  Serial.println(ssid);

  //connect to your local wi-fi network
  WiFi.begin(ssid, password);

  //check wi-fi is connected to wi-fi network
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected..!");
  Serial.print("Got IP: ");  Serial.println(WiFi.localIP());

  server.on("/", handle_OnConnect);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");

}
void loop() {

  server.handleClient();

}

void handle_OnConnect() {

 Temperature = dht.readTemperature(); // Gets the values of the temperature
  Humidity = dht.readHumidity(); // Gets the values of the humidity
  server.send(200, "text/html", SendHTML(Temperature,Humidity));
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(float Temperaturestat,float Humiditystat){
  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>ESP32 Weather Report</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";
  ptr +="p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<div id=\"webpage\">\n";
  ptr +="<h1>ESP32 Weather Report</h1>\n";

  ptr +="<p>Temperature: ";
  ptr +=(int)Temperaturestat;
  ptr +="°C</p>";
  ptr +="<p>Humidity: ";
  ptr +=(int)Humiditystat;
  ptr +="%</p>";

  ptr +="</div>\n";
  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

4. Setelah dibuat program codingnya jangan lupa (File > Save As) dan buat nama project.
5. setelah disimpan, compile program klik (Sketch > Vertify/Compile) tunggu sampai selesai.
6. Sebelum di compile, lalu upload program dengan klik (Sketch > Upload).
7. tunggu sampai proses upload berhasil.
8. setelah berhasil, klik (Tools > Serial Monitor).
9. Lihat tampilan Serial monitor:




Komentar

Postingan populer dari blog ini

ESP32 dengan modul LoRa Menggunakan Arduino IDE sending and receive data sensor DHT11

MENGATUR INTENSITAS CAHAYA LED PADA ESP32

Sandeep Mistry Arduino LoRa Aplication Programming Interface