Temperature and Humidity Controlled Fan

28 views
Skip to first unread message

avineil96

unread,
Mar 29, 2015, 5:06:53 AM3/29/15
to elec...@googlegroups.com
Hello all, 

I am making a simple temperature and humidity controlled fan using the DHT 11 sensor . The problem is that arduino is not giving any output . I measured it and it was a mere 32 mV even when the code said it to be HIGH. 
here is the code - 

#include <dht.h>

#define dht_dpin A0      //Output Pin for DHT11 sensor

dht DHT;
 
int led = 8;     // Output for a red LED
int TempMin = 21;     // Can be set according to a city's climate
int TempMax = 42;
int fan = 11;                 //Output voltage of fan from this pin
int fanSpeed;

void setup(){
  Serial.begin(9600);
  delay(1000);
  pinMode(fan,OUTPUT);
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);
}

void loop(){
  
 DHT.read11(dht_dpin);
 
   Serial.print("temperature = ");
   Serial.print(DHT.temperature);
   Serial.print("\n");
   Serial.print("Humidity = ");
   Serial.print(DHT.humidity);
   Serial.print("\n");
   
  if(DHT.temperature<TempMin){
    fanSpeed = (DHT.humidity - 20) * 4;
    if(fanSpeed<0)
    fanSpeed = 0;
    if(fanSpeed>255)
    fanSpeed = 255;
    analogWrite(fan,fanSpeed);
  }
  if((DHT.temperature>=TempMin)&&(DHT.temperature<=30))
  { 
    fanSpeed = 50 + (DHT.humidity - 20) * 4;
    if(fanSpeed<0)
    fanSpeed = 0;
    if(fanSpeed>255)
    fanSpeed = 255;
    analogWrite(fan,fanSpeed);    // Speed of Fan is set now
  }
  if((DHT.temperature>=30)&&(DHT.temperature<=33))
  {
    fanSpeed = 100 + (DHT.humidity - 20) * 2;
    if(fanSpeed<0)
    fanSpeed = 0;
    if(fanSpeed>255)
    fanSpeed = 255;
    analogWrite(fan,fanSpeed);
  }
  if((DHT.temperature>=33)&&(DHT.temperature<=36))
  {
    fanSpeed = 170 + (DHT.humidity - 50) * 2;
    if(fanSpeed<0)
    fanSpeed = 0;
    if(fanSpeed>255)
    fanSpeed = 255;
    analogWrite(fan,fanSpeed);
  }
  if((DHT.temperature>=36)&&(DHT.temperature<=38))
  {
    fanSpeed = 220 + (DHT.humidity - 20) * 2;
    if(fanSpeed<0)
    fanSpeed = 0;
    if(fanSpeed>255)
    fanSpeed = 255;
    analogWrite(fan,fanSpeed);
  }
  if((DHT.temperature>=38)&&(DHT.temperature<=TempMax))
  {
    fanSpeed = 230 + (DHT.humidity - 20) * 2;
    if(fanSpeed<0)
    fanSpeed = 0;
    if(fanSpeed>255)
    fanSpeed = 255;
    analogWrite(fan,fanSpeed);
  }
  if(DHT.temperature>TempMax)
  {
    fanSpeed = 255;
    analogWrite(fan,fanSpeed);
    digitalWrite(led,HIGH);
  }
  delay(2000);
}


Is there some problem in the code? I have ensured that all the grounds are common

Amaldev

unread,
Mar 30, 2015, 2:38:29 AM3/30/15
to elec...@googlegroups.com
Insufficient data.
1. Please add a schematic or pin connection configuration of the circuit.
2. You have not added the dht.h or dht.cpp files for anyone to take a look.
3. I think you need to connect the output of DHT 11 sensor pin to a digital pin and not an analog pin as you have connected(Or you are doing some internal pullup which is not clear from the given info). Please check the datasheet and confirm.

--
Amaldev.V
Research Assistant
Wadhwani Electronics Lab
Vision and Image Processing Lab
IIT Bombay
Ph No. +919820481964
website | linkedin

--
You received this message because you are subscribed to the Google Groups "Electronics Club IITB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elec-club+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashish Goyal

unread,
Mar 30, 2015, 2:38:30 AM3/30/15
to elec...@googlegroups.com
1. Check if fan is working by putting just analogWrite(fan,HIGH) in void loop()
2. If output is high in step 1 then you can try turning on onboard led when fanSpeed is 255 to debug

--
You received this message because you are subscribed to the Google Groups "Electronics Club IITB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elec-club+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Avineil Jain

unread,
Mar 31, 2015, 8:43:28 AM3/31/15
to elec...@googlegroups.com

Well, I did a few modifications to the code-
analogWrite function is written at the end of all the if statements

That worked for me, and the variable voltage was produced. Although, I am sure there must have been some other reason for not working!

Reply all
Reply to author
Forward
0 new messages