Go Down

Topic: Need help with sketch (Read 1 time) previous topic - next topic

truck56

This sketch prints temperature and humidity in serial monitor OK. I am not sure if I am using the right code to read the outputs of temp/humidity to  turn on and off the LED's. If the temperature falls below 60 degrees turn on ledpin8 and if above 80 degrees turn of ledpin8. Right now my room temp is 77 degrees, when I run the program ledpin8 goes high then low in one click it does not stay high till 80 degrees. Humidity(ledpin9) just goes high then low in less than a second. I just want to turn on ledpin8 when the temperature is below 60 degrees and turn off ledpin8 when the temperature  reaches 80 degrees.This is only my second sketch...noobie
Thanks





#include <dht11.h>

dht11 DHT11;

void setup()
{const int LEDPIN8 = 8;       // Temp
  const int LEDPIN9 = 9;       // Humidity
pinMode (LEDPIN8, OUTPUT); // Temp
pinMode (LEDPIN9, OUTPUT); // Humidity
 
const int THRESHOLD1 = 60;   // Temp lower limit turn on
const int THRESHOLD3 = 80;   // Temp upper limit turn off
const int THRESHOLD2 = 50;  // humidity lower limit turn on
const int THRESHOLD4 = 75;   // humidity upper limit turn off
float Temperature;
float Humidity;

  DHT11.attach(2);
  Serial.begin(9600);
 
 
}

void loop()
{  const int LEDPIN8 = 8;       // Temp
  const int LEDPIN9 = 9;       // Humidity
pinMode (LEDPIN8, OUTPUT); // Temp
pinMode (LEDPIN9, OUTPUT); // Humidity
 
const int THRESHOLD1 = 60;   // Temp lower limit turn on
const int THRESHOLD3 = 80;   // Temp upper limit turn off
const int THRESHOLD2 = 50;  // humidity lower limit turn on
const int THRESHOLD4 = 75;   // humidity upper limit turn off
float Temperature;
float Humidity;


  Serial.println("\n");

  int chk = DHT11.read();

  Serial.print("Read sensor: ");
  switch (chk)
  {
  case 0:
    Serial.println("OK");
    break;
  case -1:
    Serial.println("Checksum error");
    break;
  case -2:
    Serial.println("Time out error");
    break;
  default:
    Serial.println("Unknown error");
    break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, DEC);


  Serial.print("Temperature (F): ");
  Serial.println(DHT11.fahrenheit(), DEC);
 
 
 
 
  //Temperature
 
  Temperature = (DHT11.fahrenheit(), DEC);
 
   if (DHT11.fahrenheit(), DEC < THRESHOLD1)           // temp turn on led...less than 60 degrees
    digitalWrite(LEDPIN8, HIGH);
   
   
    if (DHT11.fahrenheit(), DEC > THRESHOLD3)           // temp turn off led.. more than 80 degrees
   
    digitalWrite(LEDPIN8,LOW);
   
   
    //Humidity
   
    Humidity = (DHT11.humidity, DEC);
   
     if (DHT11.humidity, DEC < THRESHOLD2)           // Humidity turn on led than 50 percent
    digitalWrite(LEDPIN9, HIGH);
   

  if (DHT11.humidity, DEC > THRESHOLD4)           // Humidity turn off led.. more than 75 percent
   
    digitalWrite(LEDPIN9,LOW);


 

 
  delay(200);
}


AWOL

#16
Oct 03, 2012, 11:13 am Last Edit: Oct 03, 2012, 11:17 am by AWOL Reason: 1
Quote
This sketch prints temperature and humidity in serial monitor OK.

I very, very much doubt that.

Did you read the response and rewritten code in your other thread on this subject?

Please, USE CODE TAGS when posting code.

Edit (After finding the other thread in the recycle bin, and dragging it out again)
Also, if people have taken the time and trouble to respond to your questions, don't you think it a little rude to put their responses in the bin, and start over again with the original rubbish?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

truck56

Quote
This sketch prints temperature and humidity in serial monitor OK.
Quote  from AWOL I very, very much doubt that.

You have done nothing to help. Now you call me a liar.I have rewritten the code using  others input and thought to repost a fresh sketch and not to make the other post 10 pages. personally I don't think you know how to write crap if you can't figure what I am trying to do. Maybe you should put the bottle up!

AWOL

#18
Oct 03, 2012, 11:40 am Last Edit: Oct 03, 2012, 11:42 am by AWOL Reason: 1
Code: [Select]
Serial.print("Humidity (%): ");
 Serial.println((float)DHT11.humidity, DEC);


 Serial.print("Temperature (F): ");
 Serial.println(DHT11.fahrenheit(), DEC);

Liar?
No.

Confused? Most likely.

Read the stuff that I wrote earlier, and try not to delete it this time.

Quote
You have done nothing to help

You mean like, rewriting your code for you?

I did do that, but you chucked it in the bin.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

tuxduino

Quote
I have rewritten the code using  others input


No you didn't.

Now how about being less arrogant and actually fixing your code ?

Nick Gammon


personally I don't think you know how to write crap if you can't figure what I am trying to do. Maybe you should put the bottle up!


This is just rubbish.

Read this before posting a programming question


Apologize or get banned.

Nick Gammon

I'll give you 15 minutes. Then you can complain to Head Office.

Go Up