#define LDR_PIN 34
#define LED_PIN 2
#define DCMOTOR_PIN 0
#include <ESP32Servo.h>
#define POTENTIOMETER_PIN 32
#define SERVO_PIN 15
#define ADC_RESOLUTION 4095
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
Servo myservo;
void setup() {
analogReadResolution(12);
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(DCMOTOR_PIN, OUTPUT);
myservo.attach(SERVO_PIN);
}
void loop() {
int potValue = analogRead(POTENTIOMETER_PIN);
int angle = map(potValue, 0, ADC_RESOLUTION, 0, 180);
myservo.write(angle);
delay(2000);
int ldrValue = analogRead(LDR_PIN);
Serial.println(ldrValue);
if (ldrValue < 2000) {
digitalWrite(LED_PIN, LOW);
} else {
digitalWrite(LED_PIN, HIGH);
}
float temp = dht.readTemperature(); // Read temperature in Celsius
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" Celcius");
delay(1000);
if (temp > 50) { // Define your temperature threshold here
digitalWrite(DCMOTOR_PIN, HIGH); // Turn on the LED if the temperature is above the threshold
} else {
digitalWrite(DCMOTOR_PIN, LOW); // Turn off the LED if the temperature is below the threshold
}
}