DHT11 code

I am relatively new to arduino, normally i fix these problems on my own however this is very confusing when i run the code below it says error compiling and will not indicate the line. I’ve looked up other ways to do this project and none of them have worked. Please help.

#include <DHT.h>
#include <DHT_U.h>

// include the library code:
#include <LiquidCrystal.h>

// set the DHT Pin
#define DHTPIN 12
int DHT11;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
dht.begin();

// Print a message to the LCD.
lcd.print(“Temp: Humidity:”);
}

void loop() {
delay(500);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// read humidity
float h = dht.readHumidity();
//read temperature in Fahrenheit
float f = dht.readTemperature(true);

if (isnan(h) || isnan(f)) {
lcd.print(“ERROR”);
return;
}

lcd.print(f);
lcd.setCursor(7, 1);
lcd.print(h);
}

when i run the code below

If it won’t compile, you can’t possibly run that code.

Copy and paste ALL of the output from the compiler. There is more to the output than your paraphrase.

If there truly isn’t, enable verbose mode when compiling.

Things like the Arduino you are compiling for and the OS you are using are important.

So I took your code down and I have the following comments.

  1. You have not specified the error. However, the DHT11 Lib also requires the Adafruit_sensor lib.
  2. One I got both libs I needed, I see the following compile error.

The int DHT11

 #define DHT11 11

               ^

C:\Users\rwinslow\Documents\Arduino\sketch_jun17a\sketch_jun17a.ino:11:5: note: in expansion of macro 'DHT11'

 int DHT11;

In this code block, I cleaned up the errors. Do not know if it will work as I do not have a sensor with me.

However, I think DHT11 is declared in the DHT Lib, you were attempting to redeclare it as something else.

This code cleans the errors, but I do not know if it will do what you wanted.

#include <DHT.h>
#include <DHT_U.h>



// include the library code:
#include <LiquidCrystal.h>

// set the DHT Pin
#define DHTPIN 12
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
DHT dht(DHTPIN, DHT11 );

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  dht.begin();

  // Print a message to the LCD.
  lcd.print("Temp:  Humidity:");
}

void loop() {
  delay(500);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // read humidity
  float h = dht.readHumidity();
  //read temperature in Fahrenheit
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(f)) {
    lcd.print("ERROR");
    return;
  }

  lcd.print(f);
  lcd.setCursor(7, 1);
  lcd.print(h);
}

[/code

@OP

Please, see this post.