expected unqualified-id before 'if' Error

Code:

#include <dht.h>

dht DHT;

#define DHT11_PIN 7;

void setup()
{
  pinMode(13, OUTPUT);
};

if (DHT.temperature <= 26)
{
  void loop()
  {
    digitalWrite(13, HIGH);
    delay(100);
  }
}

Error:

sketch_mar29b:12: error: expected unqualified-id before 'if'

 if (DHT.temperature <= 26)

 ^

exit status 1
expected unqualified-id before 'if'

Got no idea whats causing this. I just started coding with Arduino today.

Hi,
The if statement should be inside the void loop().

#include <dht.h>

dht DHT;

#define DHT11_PIN 7;

void setup()
{
pinMode(13, OUTPUT);
}; <<<<<<======

if (DHT.temperature <= 26) <<<<=========
{
void loop()
{
digitalWrite(13, HIGH);
delay(100);
}
}

Also remove the ; that you have after the }.

Tom... :slight_smile:

#define DHT11_PIN 7;

Remove the ;

Hi,
I suggest you look in Examples in the IDE for example code that should come with that library.

Tom... :slight_smile:

It worked!

#include <dht.h>

dht DHT;

#define DHT11_PIN 7

void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  if (DHT.temperature <= 26)
  {
    digitalWrite(13, HIGH);
    delay(100);
  }
}

Left it as that. Thanks!

Gave you a karma for using code tags in your first post :wink: