How do you make a 12v fan and a DHT22 communicate?

I am using a DHT22 and a 12v fan and I was wondering if someone could help me with the coding to make it so that when the DHT22 reads anything above 80 degrees Farenheit it will turn the fan on? Thank you in advanced for any help!

In this forum you post your code and post your wiring and any other information and we try to help.

An alternative is to post in "Gigs and Collaborations" and expect to pay for the result.

An Arduino cannot handle a 12 volt device directly and I did not see anything about a transistor or a relay or a shield.

Hi !

What you need to do:

  1. Arduino IDE and DHT.h library.
  2. You need 12 V power supply for 12 V fan. Transistor, MOSFET or Relay to control 12V powering for your fan.
  3. if/else function for programming.

It is not too difficult to find more info about DHT 22 sensor and arduino in google !

Thanks! I already have the fan and DHT22 connected, I just need help with the coding so that the DHT22 will turn on the fan when it reaches a certain temp/humidity

Here is the pseudocode:

repeat
{
read the DHT
if the temperature is greater than the setpoint, turn on the fan
else turn it off
}

There is more detail, like hysteresis, but you should try to code this and post it for further help. Study the DHT22 examples.

Hello again !

I wrote this code for you :wink: I tested it, works very well !

Enjoy !

#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 >= 26.6) { // 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 { // if Fahrenheit < 80 turn fan pin OFF.

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

}

Is the code right when i will turn on the fan on 27C an turn off on 26C

#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
 }

}

At the very least, this is not good C/C++ and should come out:

(t <= 26.0)

Tacking onto an old thread is probably a bad thing also.