1

I'm getting the error message:

sketch_dec31d.ino: In function 'void setup()':
sketch_dec31d:20: error: expected unqualified-id before '.' token
sketch_dec31d.ino: In function 'void loop()':
sketch_dec31d:29: error: expected primary-expression before '.' token
sketch_dec31d:31: error: expected primary-expression before '.' token
sketch_dec31d:33: error: expected primary-expression before '.' token
sketch_dec31d:43: error: expected primary-expression before '.' token

This is the code:

#include <dht.h>     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
#define DHT11_PIN 2 

// Initialize DHT sensor for normal 16mhz Arduino


String TextForSms ;
String humidity = " Humidity: %";
String temperature = "   Temperature";
String sign = " *C";

char fromc; // character from computer

void setup() {
  Serial.begin(9600); 
 // Serial.println("DHT11 test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity();
  // Read temperature as Celsius
  int t = dht.readTemperature();
  // Read temperature as Fahrenheit
  int f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  int hi = dht.computeHeatIndex(f, h);



   TextForSms = TextForSms + t + "," + h + ",";
Serial.println(TextForSms); 
     TextForSms = ""; 
   delay(1000);   

}

closed as off-topic by Juraj, VE7JRO, per1234, gre_gor, MatsK Jan 8 at 14:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – Juraj, per1234, gre_gor, MatsK
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Please show the complete code and the complete error message. There isn't enough here for someone to help you. (One obvious error, but apparently not the one that got the error message, is an extra '}' on line 31. – JRobert Dec 31 '18 at 14:06
  • 1
    Which dht library do you use exactly? This one: github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib ? Then look at the examples. If not, please provide a link to the used library – chrisl Dec 31 '18 at 14:27
0

Probably the error is in line

dht.begin();

You did not declare the variable dht, probably of type DHT11 ? You can find the correct class name in the dht.h header file.

After checking this (random) website compute heat index arduino about DHT11 I see the line:

DHT dht(DHTPIN, DHTTYPE);

Which you also have to add, probably as:

DHT dht(DHT11_PIN, DHTTYPE);

Not the answer you're looking for? Browse other questions tagged or ask your own question.