Go Down

Topic: Creating hysteresis with DHT11 sensor.. (Read 1 time) previous topic - next topic

Hackdub

I'm building a simple fan controller...I want the fan to switch on at 27c and go off at 25c, hence creating a 2c hysteresis..

at the moment with the code below the fan goes on off around 27.... is this due to the else command .. do I create a >27 and <25 scenarios and put the else between?

Code: [Select]
{
    if(t>=27)
    {//lcd.setCursor(0, 0);
    //lcd.print("*  hot *  ");
    digitalWrite(fan, HIGH);
    lcd.setCursor(15, 0);
  lcd.print("F");}
  else
    {//lcd.setCursor(0, 0);
   // lcd.print("  Just Right       ");
    digitalWrite(fan, LOW);
    lcd.setCursor(15, 0);
  lcd.print("_");
  }
  {
    if(t<=25)
   
    {//lcd.setCursor(0, 0);
    //lcd.print("It's Freezing");}
    digitalWrite(fan, LOW);}

  }


Second question. I'm using the DHT 11 sensor, the temp is only shown in single 1c units, no decimal.. Im using the library from http://learn.adafruit.com/dht/using-a-dhtxx-sensor

thanks for any help


Riva


I'm building a simple fan controller...I want the fan to switch on at 27c and go off at 25c, hence creating a 2c hysteresis..

at the moment with the code below the fan goes on off around 27.... is this due to the else command .. Yes
do I create a >27 and <25 scenarios and put the else between?
Just have a >=27 and <=25 with no else condition.

Second question. I'm using the DHT 11 sensor, the temp is only shown in single 1c units, no decimal.. Im using the library from http://learn.adafruit.com/dht/using-a-dhtxx-sensor
You don't show code for this but your probably using int instead of float and loosing the .x part.

Hackdub

Ok so code 
Code: [Select]
{
    if(t>=27)
    {
    digitalWrite(fan, HIGH);
    lcd.setCursor(15, 0);
    lcd.print("F");}
 
    if(t<=25)
    {digitalWrite(fan, LOW);}

  }



Hackdub

#3
Feb 13, 2013, 12:33 pm Last Edit: Feb 13, 2013, 12:50 pm by Hackdub Reason: 1
Code for reading sensor = I'm using float, but it only shows in 1c increments.

Code: [Select]
float h = dht.readHumidity();
 float t = dht.readTemperature();
 // check if returns are valid, if they are NaN (not a number) then something went wrong!
 if (isnan(t) || isnan(h)) {
   Serial.println("Failed to read from DHT");
 }
 else {
   Serial.print("Humidity: ");
   Serial.print(h);
   Serial.print("  %   ");
   Serial.print("Temp: ");
   Serial.print(t);
   Serial.println("C");
 }


 // set the cursor to column 0, line 1
 // (note: line 1 is the second row, since counting begins with 0):
 lcd.setCursor(8, 1);
 lcd.print("H:");
 lcd.print(h);
 lcd.print("%");
 //delay(2000);
 lcd.setCursor(0, 1);
 lcd.print("T:");
 lcd.print(t);
 //lcd.print("C");
 //delay(2000);

 {
   if(t>=25)
   {//lcd.setCursor(0, 0);
   //lcd.print("* hot *  ");
   digitalWrite(fan, HIGH);
   lcd.setCursor(15, 0);
 lcd.print("F");}
 else
   {//lcd.setCursor(0, 0);
  // lcd.print("  Just Right       ");
   digitalWrite(fan, LOW);
   lcd.setCursor(15, 0);
 lcd.print("_");
 }
 {
   if(t<=23)
   
   {//lcd.setCursor(0, 0);
   //lcd.print("It's Freezing");}
   digitalWrite(fan, LOW);}

 }

holmes4

You must make use of the auto format option on the IDE. It makes code so much more readable. (And helps keep PaulS at bay).

Mark

Go Up