#include <DHT.h>
#define DHTPIN 22
#define BUZZER_PIN 34
#include <Stepper.h>
//the sensor
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float t;
// Define the stepper motor pins for the two motors
#define STEPPER1_PIN1 19
#define STEPPER1_PIN2 18
#define STEPPER1_PIN3 5
#define STEPPER1_PIN4 17
#define STEPPER2_PIN1 16
#define STEPPER2_PIN2 4
#define STEPPER2_PIN3 0
#define STEPPER2_PIN4 2
// Stepper motor steps per revolution
#define STEPS_PER_REVOLUTION 2048 // Adjust this based on your motor specifications
// Create Stepper objects for the two motors
Stepper motor1(STEPS_PER_REVOLUTION, STEPPER1_PIN1, STEPPER1_PIN2, STEPPER1_PIN3, STEPPER1_PIN4);
Stepper motor2(STEPS_PER_REVOLUTION, STEPPER2_PIN1, STEPPER2_PIN2, STEPPER2_PIN3, STEPPER2_PIN4);
void setup() {
// Begin serial communication at a baud rate of 9600:
Serial.begin(115200);
// Set the motor speed (rpm)
motor1.setSpeed(15); // 15 RPM for motor 1
motor2.setSpeed(15); // 15 RPM for motor 2
}
void loop() {
// Read temperature and humidity from DHT22
float t = dht.readTemperature();
// Serial.print("h=");Serial.print(h,1);Serial.print("\t");
Serial.print("TEMPERATURE DETECTED: ");
Serial.print("temperature=");Serial.println(t,1);
delay(2000); //Collecting period should be : >1.7 second
// If the temperature exceeds 40°C, rotate motors and activate the buzzer
if (t >= 40) {
// Rotate both motors (for biaxial movement)
Serial.println("Temperature is high! Rotating motors...");
// Rotate motor 1 (X-axis)
motor1.step(2048); // Rotate 1 full revolution (adjust as needed)
// Rotate motor 2 (Y-axis)
motor2.step(2048); // Rotate 1 full revolution (adjust as needed)
// Activate Buzzer to warn user
digitalWrite(BUZZER_PIN, HIGH);
delay(1000); // Buzzer sound duration
digitalWrite(BUZZER_PIN, LOW);
}
}