#include <DHT.h>
#define dirPin 3
#define stepPin 2
#define dhtPin A5
#define dhtType DHT22
DHT dht(dhtPin, dhtType);
const int stepsPerRevolution = 200;
const float targetTemperature = 25.0;
bool isMotorRotated = false;
void setup() {
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
if (!isnan(temperature)) {
if (temperature >= targetTemperature && !isMotorRotated) {
digitalWrite(dirPin, HIGH);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
isMotorRotated = true;
} else if (temperature < targetTemperature && isMotorRotated) {
digitalWrite(dirPin, LOW);
for (int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
isMotorRotated = false;
}
} else {
}
delay(1000);
}