Need help with sketch

Using a DHT11 on arduino1280, Trying to turn on LED when threshold met
When I compile it stops on
Temperature = (Temperature (°F): );
and says stray "/" in program, I can't find it
Sorry don't understand code tags yet, don't see #

#include <dht11.h>

dht11 DHT11;

void setup()
{
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 = 80; // Temp
const int THRESHOLD2 = 50; // humidity
Temperature = (Temperature (°F): );

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 (Temperature < THRESHOLD1) // heat
digitalWrite(LEDPIN8, HIGH);
else
digitalWrite(LEDPIN8,LOW);
else
digitalWrite(LEDPIN8,LOW);

//Humidity

Humidity = (float)DHT11.humidity, DEC);

if (Humidity > THRESHOLD2) // Humidity
digitalWrite(LEDPIN9, HIGH);

else
digitalWrite(LEDPIN9,LOW);

delay(20000);
}

truck56:
When I compile it stops on
Temperature = (Temperature (°F): );
and says stray "/" in program, I can't find it.

It's probably just confused because "Temperature = (Temperature (°F): );" is not a valid statement. What did you intend that line to do?

I want to compare it to the threshold1 to turn on the LED

Stray \ in program usually means you have a unicode character in there. Which is most certainly that degree symbol. Delete it.

It looks like this line

Temperature = (Temperature (°F): );

near the top of the file was supposed to be a variable declaration but some text from a later println got in there. You make assignments to Temperature and Humidity without having declared them. There is also a stray "{" before "const int THRESHOLD1". Try replacing this:

{const int THRESHOLD1 = 80;   // Temp
const int THRESHOLD2 = 50;  // humidity
Temperature = (Temperature (°F): );

with this:

const int THRESHOLD1 = 80;   // Temp
const int THRESHOLD2 = 50;  // humidity
float Temperature;
float Humidity;

BTW, variable names usually start with a lower case to distinguish them from class names.

When I set the (temp) threshold1 to 60 ( lower limit), which is below my room temp and threshold3 to 80(upper limit), Ledpin8 just flashes once and goes low, never comes on again, unless restart. I wonder if my IF statements are right? At least a LED comes on. The prog prints temp/humidity OK

#include <dht11.h>

dht11 DHT11;

void setup()
{
  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..60
const int THRESHOLD3 = 100;   // 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...less than 60
    digitalWrite(LEDPIN8, HIGH);
    //delay(4000);//works on temp
    
    if (DHT11.fahrenheit(), DEC > THRESHOLD3)           // temp turn off.. more than 80
    
    digitalWrite(LEDPIN8,LOW);
   
    
    //Humidity
    
    Humidity = (DHT11.humidity, DEC);
    
     if (DHT11.humidity, DEC < THRESHOLD2)           // Humidity turn on les than 50
    digitalWrite(LEDPIN9, HIGH);
    //delay(2000);//no work on hum
    

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


  

  
  delay(200);
}

Moderator edit: CODE TAGS

Serial.println((float)DHT11.humidity, DEC);

Trying to print a 32 bit float (which is, in reality a pointer to a function anyway) to ten decimal places is a trifle optimistic.

Why have you got all your "pinMode"s in "loop"?
I'd expect to see them in "setup".

What do you expect this if (DHT11.fahrenheit(), DEC < THRESHOLD1)     to do?

Uncompiled, untested.

#include <dht11.h>

const int LEDPIN8 = 8;       // Temp
const int LEDPIN9 = 9;       // Humidity
  
const int THRESHOLD1 = 60;   // Temp lower limit turn on..60
const int THRESHOLD3 = 100;   // Temp upper limit turn off
const int THRESHOLD2 = 50;  // humidity lower limit turn on
const int THRESHOLD4 = 75;   // humidity upper limit turn off
dht11 DHT11;

void setup()
{
  DHT11.attach(2);
  Serial.begin(9600);
  pinMode (LEDPIN8, OUTPUT); // Temp 
  pinMode (LEDPIN9, OUTPUT); // Humidity 
}

void loop()
{
  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;
  }

  float temperature = DHT11.fahrenheit();
  float humidity = DHT11.humidity ();
  
  Serial.print("Humidity (%): ");
  Serial.println(humidity);
 
  Serial.print("Temperature (F): ");
  Serial.println(temperature);
  
  if (temperature < THRESHOLD1)        
  {
    digitalWrite(LEDPIN8, HIGH);
  }
    
  if (temperature > THRESHOLD3)        
  {  
    digitalWrite(LEDPIN8,LOW);
  } 
   
  if (humidity < THRESHOLD2)           
  {
    digitalWrite(LEDPIN9, HIGH);
  }
    
  if (humidity > THRESHOLD4)           
  {
    digitalWrite(LEDPIN9,LOW);
  }  
  
  delay(200);
}

I'd be inclined to give the thresholds meaningful names like "LOWER_TEMPERATURE_THRESHOLD" etc.

What do you expect this
Code:

if (DHT11.fahrenheit(), DEC < THRESHOLD1)

to do? If the temp is lower than 60 turn on Ledpin6
Looks like my pinmodes are in setup
The sketch compiles and displays temp/humidity, just won't hold the Led's high between thresholds

If the temp is lower than 60 turn on Ledpin6

It doesn't do that. It compares the value 10 (aka "DEC") to the value 60 (aka "THRESHOLD1").

just won't hold the Led's high between thresholds

Now it is my turn to not understand. (that's a hint to you to post your observations)

What do you expect this

if (DHT11.fahrenheit(), DEC < THRESHOLD1)

to do?

If the temp is lower than 60 turn on Ledpin6

DEC is just an optional argument of Serial.print(), to ensure the first one is printed as a decimal number, not hex or binary or char.

It's not a typecast operator, like you seem to be using it:

Temperature = (DHT11.fahrenheit(), DEC);

A note about coding style always use brackets after if(), like this (I have not corrected your code, just added brackets):

if (DHT11.fahrenheit(), DEC > THRESHOLD3) {
    digitalWrite(LEDPIN8,LOW);
}
//delay(4000);//works on temp       <== where did this go ? Inside the "then" block or not ?

Humidity = (DHT11.humidity, DEC);

if (DHT11.humidity, DEC < THRESHOLD2) {
    digitalWrite(LEDPIN9, HIGH);
}

if (DHT11.humidity, DEC > THRESHOLD4) {
    digitalWrite(LEDPIN9,LOW);
}

DEC is just an optional argument of Serial.print(), to ensure the first one is printed as a decimal number, not hex or binary or char.

Or to tell how many decimal places to print the value with, if the value is a float. (or a function pointer cast to a float, which isn't recommended)

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

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?

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!

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.

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.

I have rewritten the code using others input

No you didn't.

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

truck56:
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.

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