0

Im getting this error message with my arduino code "request for member 'read11' in 'sensor', which is of non-class type 'DHT()'"

#include <DHT.h>


#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int greenPin = A0;
DHT sensor();

void setup()
{
  lcd.begin(16,2); //16 by 2 character display
}

void loop()
{
  delay(1000); //wait a sec (recommended for DHT11)
  sensor.read11(greenPin);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Humidity = ");
  lcd.print(sensor.humidity);
  lcd.setCursor(0,1);
  lcd.print("Temp = ");
  lcd.print(sensor.temperature);
}

I have downloaded the library it said to download, please help!

I took it from this website btw just to avoid copywright issues: https://www.hive-rd.com/blog/arduino-dht11-output-lcd-module/

1 Answers1

1

At the line

DHT sensor();

the use of parenthesis causes this line to get parsed as a forward declaration of a function sensor(), taking no arguments, returning type DHT. What you want is to just define sensor as a variable with type dht (note: the tutorial uses lower case.) The correct syntax would be:

#include <dht.h>
/* code */
dht sensor;

If you refer to the tutorial you linked, you'll see that's how it appears in the code example.

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96