#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
#define FAN_PIN 9
DHT dht(DHTPIN,DHTTYPE);
const float slope=10.0;
const float intercept =-200.0;
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200);
dht.begin();
pinMode(FAN_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
float h=dht.readHumidity();
float t=dht.readTemperature();
if (isnan(t) || isnan(h)){
Serial1.println("failed to read");
return;
}
Serial1.println("temperature");
Serial1.print(t);
Serial1.print("%");
Serial1.println("humidit");
Serial1.print(h);
Serial1.println("%");
float ps= slope*t+ intercept;
ps=constrain(ps,0,255);
analogWrite(FAN_PIN,ps);
delay(1000);
}