#include <LiquidCrystal.h>
#include <DHT.h>
#include <Servo.h>
#define DHTPIN 6
#define DHTTYPE DHT22
bool isClockwise = true;
const long interval = 5000; // Set the interval in milliseconds
unsigned long previousMillis = 0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
DHT dht(DHTPIN, DHTTYPE);
Servo myservo;
int pos = 0;
int iterationCount = 0;
void setup() {
// put your setup code here, to run once:
dht.begin();
lcd.begin(16, 2);
myservo.attach(3);
myservo.write(0);
lcd.setCursor(0, 0);
lcd.print(pos);
}
void rotateservo() {
// Determine the direction of rotation
if (isClockwise) {
// Rotate clockwise
myservo.write(90);
pos += 1;
lcd.setCursor(0, 0);
lcd.print(String("tcha9liba : "+ String(pos)));
} else {
// Rotate counterclockwise
myservo.write(0);
pos += 1;
lcd.setCursor(0, 0);
lcd.print(String("tcha9liba : "+ String(pos)));
}
// Toggle the direction for the next rotation
isClockwise = !isClockwise;
}
void loop() {
// put your main code here, to run repeatedly:
float h = dht.readHumidity();
float t = dht.readTemperature();
//lcd.setCursor(0, 0);
//lcd.print(String("humidity: ") + h + String("%"));
lcd.setCursor(0, 2);
lcd.print(String("TEMP : ") + t + String(" C*"));
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// Save the current time
previousMillis = currentMillis;
// Move the servo to the desired position
rotateservo();
}
}