MY PROGRAM IS COMBINED AMBIENT TEMPERATURE AND HUMIDITY MONITORING but I can't run it with this error "error: expected primary-expression before '.' token" in line 21, 23 and line 25
Here's my code:
//DHT11 Combined Ambient Temperature and Humidity Monitor
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHT11_PIN7
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup(){
lcd.begin(16,2);
lcd.clear();
lcd.print("Temp =");
lcd.setCursor(0,1);
lcd.print("Humidity =");
}
void loop(){
int chk=DHT.read(DHT11_PIN7); //line 21
lcd.print("Temp =");
lcd.print(DHT.temperature); //line 23
lcd.print("Humidity =");
lcd.print(DHT.humidity);//line 25
delay(1000);
}
Robin2
August 23, 2018, 6:51am
2
You have not created an instance called DHT for the DHT library.
There should be a line similar to this one which creates an instance called lcd (but I don't know the exact syntax for the DHT library)
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
...R
You included the DHT library but did not create a DHT object (probably like the below).
(DHT dht(DHTPIN, DHTTYPE);
nor is there a dht.begin() function in setup.
Look at the examples that come with the library to be sure of the syntax..
Personal preference only, but I'd avoid instantiating an object with the same (or similar) name as the class. I think it leads to confusion.
system
August 23, 2018, 12:07pm
5
gfvalvo:
Personal preference only, but I'd avoid instantiating an object with the same (or similar) name as the class. I think it leads to confusion.
It's like getting a Dog, and calling it dog.
Might has well have a baby Boy, and call it boy, so the parents can distinguish the boy from their instance of the Girl class, whom they named girl.