#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
#include <ESP32Servo.h>
//channel id 2546324
//channel api 0B3ETEE5HRPI38C1
#include <WiFi.h>
#include "ThingSpeak.h"
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int DHT_PIN = 15;
const int SERVO_PIN = 2; // Define the pin for the servo
const char* WIFI_NAME = "Redmi Note 12 Pro 5G";
const char* WIFI_PASSWORD = "donnito1611";
const int MyChannelNumber =2546324 ;
const char* MyApiKey = "0B3ETEE5HRPI38C1";
const char* server = "api.thingspeak.com";
DHTesp dhtSensor;
Servo servo; // Use Servo type instead of ESP32_Servo_h
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32!");
lcd.init();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("Hello Donn");
lcd.setCursor(0,1);
lcd.print("Ini essay no 4");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
servo.attach(SERVO_PIN); // Attach the servo to the defined pin
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temperature, C = " + String(data.temperature, 2));
Serial.println("Humidity, % = " + String(data.humidity, 2));
Serial.println("Channel update successful");
Serial.println("");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ABE80 T,C =" + String(data.temperature, 0));
lcd.setCursor(0,1);
lcd.print("EXER8 H,% =" + String(data.humidity, 0));
// Check if temperature is above 35°C and humidity is above 85%
if (data.temperature >= 35 && data.humidity >= 85) {
// Perform servo movements
for (int angle = 0; angle <= 180; angle++) {
servo.write(angle);
delay(15);
}
for (int angle = 180; angle >= 0; angle--) {
servo.write(angle);
delay(15);
}
}
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}