Nodemcu+DHT22+Fan Code?

Hi i’m new in arduino and i have a little project,

I have a arduino nodemcu 8266 and a dht22 now i will controll a fan with the sensor values i find this code and edit it a little bit. 27 celsius turn on and 26 celsius turn it off… Is it ok?

 #include <dht.h> // include dht sensor library

#define dataPin 8 //DHT22 sensor signal input pin (You can change it as you want)
#define fanPin 13 // fan signal ouput pin (You can change it as you want)

dht DHT;

float t = 0;
float h = 0;

void setup() {

 pinMode(fanPin, OUTPUT); // set fan pin as output (5V) for your fan driver control (turning ON)


void loop() {

 int readData = DHT.read22(dataPin); //read temp and humidity values from dht22 sensor

 t = DHT.temperature; // name temperature as t
 h = DHT.humidity; // name humidity as h

 delay(2000); // delay for DHT22 sensor read from datasheet

 if (t >= 27.0) { // if Fahrenheit >= 80 turn fan pin ON. (80 Fahrenheit to Celsius is 26,6). (of course, there you can calculate with math functions from celsius to fahrenheit if you want ! )

   digitalWrite(fanPin, HIGH); //turn fan pin ON

 else (t <= 26.0) { // if Fahrenheit < 80 turn fan pin OFF.

   digitalWrite(fanPin, LOW); //turn fan pin OFF


What made you think that your question has anything to do with the working of this Website and Forum? I have suggested to the Moderator to move it to the Project Guidance section.

This sort of carelessness makes unnecessary work for the Moderators.


Oh sry don‘t notice that i‘m in the wrong sort