expected primary-expression before '.' token

Here's my unfinished code
i keep getting this error
Arduino: 1.8.1 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/whelpleyc7808/Desktop/maybe/maybe.ino: In function 'void loop()':
maybe:21: error: expected primary-expression before '.' token
int chk = DHT.read11(DHT11_PIN7)
^
maybe:21: error: 'DHT11_PIN7' was not declared in this scope
int chk = DHT.read11(DHT11_PIN7)
^
maybe:27: error: expected primary-expression before '.' token
int chk = DHT.read11(DHT11_PIN);
^
maybe:29: error: expected ';' before 'Serial'
Serial.println(DHT.temperature);
^
maybe:31: error: expected ';' before 'Serial'
Serial.println(DHT.humidity);
^
maybe:35: error: 'temperature' was not declared in this scope
if(temperature < desiredTemp){
^
exit status 1
expected primary-expression before '.' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

what do I do?

maybe.ino (668 Bytes)

there are countless syntax errors in your code...

start by enabling your semicolon on your keyboard. :wink:

what do I do?

Post your code, in code tags

BulldogLowell:
there are countless syntax errors in your code...

start by enabling your semicolon on your keyboard. :wink:

Thanks but then what?

where did you end up with your code once you fixed all that?

post your updated code (in the body of your post using code tags so folks don't have to download)

#include <Adafruit_Sensor.h>;
#include <DHT.h>;
#define DHT11_PIN 7;
int sensorPin = 0; 
int desiredTempF= 56;
in mySwitch;
float desiredTemp = 28; 

void setup()
{
  Serial.begin(9600); 
}
 
void loop()                     
{
 
 {
  int chk = DHT.read11(DHT11_PIN7);
  delay(1000);
  
}

{ 
 int chk = DHT.read11(DHT11_PIN);
  Serial.print ("Temperature = ");
  Serial.println (DHT.temperature);
  Serial.print ("Humidity = ");
  Serial.println (DHT.humidity);
  delay(1000);
}
 delay(1000);
 
  if{ (DHT.temperature < desiredTempF);
  {

  
    Serial.println("Heater ON");
    
  }
  else{
    Serial.println("Heater OFF");

  }
}

this is my newest code

baconeer1:

{

int chk = DHT.read11(DHT11_PIN7);
  delay(1000);
}




this is my newest code
  1. from where did you get the read11() function? is that part of the Adafruit sensor library? It isn't part of the DHT library that comes with Arduino IDE.

  2. why are you creating an int, initializing it with some value (perhaps) and then doing nothing with it? It is destroyed after the closing brace(more on variable scope here).

I remade the code to be a lot simpler

#include <Adafruit_Sensor.h>;
#include <DHT.h>;
#define DHT11_PIN 7
float desiredTempF= 56;
void setup() {
Serial.begin(9600); 
}
void loop() {
 int chk = DHT.read11(DHT11_PIN7);
  delay(1000);
{ 
 int chk = DHT.read11(DHT11_PIN);
  Serial.print ("Temperature = ");
  Serial.println (DHT.temperature);
  Serial.print ("Humidity = ");
  Serial.println (DHT.humidity);
  delay(1000);
}
if{ (DHT.temperature < desiredTempF);
    Serial.println("Heater ON");
  }
else{
    Serial.println("Heater OFF");}
}

I keep getting expected primary token errors

#include <Adafruit_Sensor.h>;
#include <DHT.h>;
#define DHT11_PIN 7;

No, semicolons are wrong here - semicolons separate statements - #include and #define are
preprocessor directlves

 if{ (DHT.temperature < desiredTempF);

Braces definitely do not belong there, and the semicolon terminates the then-part of the if which
you certainly didn't intend. Just:

 if (DHT.temperature < desiredTempF)

When you get a bunch of syntax errors, fix the first one first, the others may all cascade from it.

Auto-indent your code to check the braces match as you meant...

thanks MarkT

if (DHT.temperature < desiredTempF)
    Serial.println("Heater ON");
  }
else{
    Serial.println("Heater OFF");}
}

It is still saying that else is unidentified

baconeer1:

if (DHT.temperature < desiredTempF)

Serial.println("Heater ON");
  }
else{
    Serial.println("Heater OFF");}
}




It is still saying that else is unidentified

missing opening curly brace...

if (DHT.temperature < desiredTempF)
{ // here <<<<<<<<<<<<<<<<<<<<<<<<<<
  Serial.println("Heater ON");
}
else
{
    Serial.println("Heater OFF");}
}

that is why properly formatting your code really helps you debug

baconeer1:

if (DHT.temperature < desiredTempF)

Serial.println("Heater ON");
  }
else{
    Serial.println("Heater OFF");}
}




It is still saying that else is unidentified

Why don't you simply cut and paste the actual error message you're getting?

AWOL:
Why don't you simply cut and paste the actual error message you're getting?

That error has been resolved but

int chk = DHT.read11(DHT11_PIN);

is saying the "." token is undefined

newest:11: error: expected primary-expression before '.' token
int chk = DHT.read11(DHT11_PIN);

Does the library have any examples?
Do the examples look like your code?

is saying the "." token is undefined

No, it isn't!

newest:11: error: expected primary-expression before '.' token
int chk = DHT.read11(DHT11_PIN);

That is saying that is has no idea what the DHT object is. It hardly seems likely that that is the first, or only, error message.