Pages: 1 [2]   Go Down
Author Topic: Need help with sketch  (Read 1540 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25752
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: October 03, 2012, 04:17:56 am by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25752
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
« Last Edit: October 03, 2012, 04:42:10 am by AWOL » Logged

"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.

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have rewritten the code using  others input

No you didn't.

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 [2]   Go Up
Jump to: