#include <LiquidCrystal.h>
#include <DHT.h>
#include <Servo.h>
#define DHTPIN 9
#define DHTTYPE DHT11
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
DHT dht(DHTPIN, DHTTYPE);
Servo servoMotor;
const int potPin = A0;
const int ledPin = 8;
void setup() {
lcd.begin(16, 2);
dht.begin();
servoMotor.attach(10);
pinMode(ledPin, OUTPUT);
}
void loop() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("KELOMPOK 04");
float temperature = dht.readTemperature();
if (isnan(temperature)) {
lcd.setCursor(0, 1);
lcd.print("Error reading");
delay(2000);
return;
}
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
int potValue = analogRead(potPin);
int angle = map(potValue, 0, 1023, 0, 180);
servoMotor.write(angle);
if (temperature >= 25) {
digitalWrite(ledPin, HIGH); // Turn on LED if temperature is above 25°C
} else {
digitalWrite(ledPin, LOW); // Turn off LED otherwise
}
delay(2000);
}