#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
#include "DHT.h"
#include <ArduinoJson.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
String serverName = "https://api.thingspeak.com/update?api_key=RSDPNUE5PN1GH1M5&field1=";
LiquidCrystal_I2C lcd(0x27,16,2);
#define DHTPIN 13
#define DHTTYPE DHT22
DHTesp dhtSensor;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
dht.begin();
pinMode(25,OUTPUT);
lcd.init();
lcd.backlight();
dhtSensor.setup(DHTPIN, DHTesp::DHT22);
WiFi.begin(ssid, password);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
int suhu = dht.readTemperature();
delay(1000);
if(suhu > 30){
lcd.clear();
lcd.print(" Suhu : " + String(suhu));
lcd.setCursor(0,1);
lcd.print("KEADAAN = PANAS");
digitalWrite(25,HIGH);
delay(2000);
}
if(suhu <= 30){
lcd.clear();
lcd.print(" Suhu : " + String(suhu));
lcd.setCursor(0,1);
lcd.print("KEADAAN = DINGIN");
digitalWrite(25,LOW);
delay(1000);
}
if(WiFi.status()== WL_CONNECTED)
{
HTTPClient http;
String serverPath = serverName + String(suhu);
http.begin(serverPath);
int httpResponseCode = http.GET();
if (httpResponseCode>0)
{
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else
{
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
}