#include <DHT.h>
// Declaration of the value DHT22 sensor
const int DHT_PIN = 2;
DHT dht(DHT_PIN, DHT22);
// Declaration of the value Control Stepper Motor
const int DIR = 3;
const int STEP = 4;
const int steps_per_rev = 1000;
//Declation of the value of the buzzer sensor
#define buzzer 5
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, STM32!");
dht.begin();
pinMode(STEP, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(buzzer, OUTPUT);
}
// Function for activation FAN
void activationFAN(){
digitalWrite(DIR, HIGH);
for(int i=0;i<steps_per_rev; i++){
digitalWrite(STEP, HIGH);
delayMicroseconds(2000);
digitalWrite(STEP, LOW);
delayMicroseconds(2000);
}
delay(1000);
digitalWrite(DIR, LOW);
for(int i=0; i<steps_per_rev;i++){
digitalWrite(STEP, HIGH);
delayMicroseconds(1000);
digitalWrite(STEP, LOW);
delayMicroseconds(1000);
}
delay(1000);
}
// Function for activation buzer
void activationBuzzer(){
tone(buzzer, 500, 1000);
delay(1000);
tone(buzzer, 100, 1000);
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
float humid = dht.readHumidity();
float temp = dht.readTemperature();
if(temp>=30 || humid>=50){
activationFAN();
activationBuzzer();
}
delay(3000);
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6