#include <DHT.h>
#include <Stepper.h>
const int stepsPerRevolution = 1000;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int potpin = A0;
int val;
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const float temperatureThreshold = 50.0;
void setup() {
myStepper.setSpeed(100);
Serial.begin(9600);
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.println(temperature);
if (temperature >= temperatureThreshold) {
Serial.println("Temperature above threshold, rotating stepper motor...");
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
//delay(1);
}else{
Serial.println("Temperature below threshold, motor stopped.");
}
//step one revolution in the other direction:
//Serial.println("counterclockwise");
//myStepper.step(-stepsPerRevolution);
//delay(1000);
}