Expected primary expression error

Hello trying to setup data logging of the humidity sensor and getting these errors. Very new to this so very little understanding. I have researched the libraries and understand i need to have the correct DS3231 and DHT libraries which i think i do.

Here is the code followed by the errors

/*

  • Program to demonstrate Data Logging/Visualisation using Arduino
  • ###Connection with SD card module###
  • Vcc->5V
  • Gnd->Gnd
  • MISO->pin 12
  • MOSI->pin 11
  • SCK-> pin 13
  • CS-> pin 4
  • ###Connection with DS3231###
  • Vcc->5V
  • Gns->Gnd
  • SCL->pin A5
  • SDA-> pin A4
  • ###Connection with DT11###
  • Vcc->5V
  • Gnd->Gnd
  • Out-> pin 7

*/

#include <DS3231.h> //Library for RTC module (Download from Link in article)
#include <SPI.h> //Library for SPI communication (Pre-Loaded into Arduino)
#include <SD.h> //Library for SD card (Pre-Loaded into Arduino)
#include <DHT.h> //Library for dht11 Temperature and Humidity sensor (Download from Link in article)

#define DHT11_PIN 7 //Sensor output pin is connected to pin 7
DHT; //Sensor object named as DHT

const int chipSelect = 4; //SD card CS pin connected to pin 4 of Arduino

// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);

void setup()
{
// Setup Serial connection
Serial.begin(9600);
Initialize_SDcard();
Initialize_RTC();
Initialize_PlxDaq();
}

void loop()
{
Read_DHT11();
Write_SDcard();
Write_PlxDaq();
delay(5000); //Wait for 5 seconds before writing the next data
}

void Write_PlxDaq()
{
Serial.print("DATA"); //always write "DATA" to Indicate the following as Data
Serial.print(","); //Move to next column using a ","

Serial.print("DATE"); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.print("TIME"); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.print(DHT.temperature); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.print(DHT.humidity); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.println(); //End of Row move to next row
}

void Initialize_PlxDaq()
{
Serial.println("CLEARDATA"); //clears up any data left from previous projects
Serial.println("LABEL,Date,Time,Temperature,Humidity"); //always write LABEL, to indicate it as first line
}

void Write_SDcard()
{
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.print(rtc.getDateStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.print(rtc.getTimeStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.print(DHT.temperature); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.print(DHT.humidity); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.println(); //End of Row move to next row
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}

void Initialize_SDcard()
{
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println("Date,Time,Temperature,Humidity"); //Write the first row of the excel file
dataFile.close();
}
}

void Initialize_RTC()
{
// Initialize the rtc object
rtc.begin();

//#### The following lines can be uncommented to set the date and time for the first time###
/*
rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(18, 46, 45); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 30, 2017); // Set the date to January 1st, 2014
*/
}

void Read_DHT11()
{
int chk = DHT.read11(DHT11_PIN);
}

/*void Read_DateTime()
{
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");

// Send time
Serial.println(rtc.getTimeStr());
}*/

/void Read_TempHum()
{
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
// delay(1000);
}
/

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino:32:1: warning: declaration does not declare anything [-fpermissive]

DHT; //Sensor object named as DHT

^

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino: In function 'void Write_PlxDaq()':

sketch_jul25d:67:21: error: expected primary-expression before '.' token

Serial.print(DHT.temperature); //Store date on Excel

^

sketch_jul25d:70:21: error: expected primary-expression before '.' token

Serial.print(DHT.humidity); //Store date on Excel

^

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino: In function 'void Write_SDcard()':

sketch_jul25d:96:23: error: expected primary-expression before '.' token

dataFile.print(DHT.temperature); //Store date on SD card

^

sketch_jul25d:99:23: error: expected primary-expression before '.' token

dataFile.print(DHT.humidity); //Store date on SD card

^

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino: In function 'void Read_DHT11()':

sketch_jul25d:142:14: error: expected primary-expression before '.' token

int chk = DHT.read11(DHT11_PIN);

^

exit status 1
expected primary-expression before '.' token

STEMMERS:
C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino:32:1: warning: declaration does not declare anything [-fpermissive]

DHT; //Sensor object named as DHT

^

Spend some time studying the examples that came with the DHT library and then correct line 32 of your code accordingly.

STEMMERS:
Hello trying to setup data logging of the humidity sensor and getting these errors. Very new to this so very little understanding. I have researched the libraries and understand i need to have the correct DS3231 and DHT libraries which i think i do.

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino:32:1: warning: declaration does not declare anything [-fpermissive]

DHT; //Sensor object named as DHT
^

You specified a type ('DHT') but did not specify a name for the variable to be declared. You didn't create a variable so the compiler complains when you try to use 'DHT' as the name of an object.

Thanks,

so how do i declare a name for a variable?

Study the library examples. They will show you how to do it.

Thanks i have tried defining DHT type and others. I really have no idea what im doing so i maybe i will wait and see if anyone else can help.

Thanks you

DHT dht;

Tried that. Doesnt work

Define "doesn't work"

Did you then try

int chk = dht.read11(DHT11_PIN);

Note: dht not DHT. Case matters

I made the changes you suggested to DHT and lower case and this is the list of errors and the code

/*

  • Program to demonstrate Data Logging/Visualisation using Arduino
  • ###Connection with SD card module###
  • Vcc->5V
  • Gnd->Gnd
  • MISO->pin 12
  • MOSI->pin 11
  • SCK-> pin 13
  • CS-> pin 4
  • ###Connection with DS3231###
  • Vcc->5V
  • Gns->Gnd
  • SCL->pin A5
  • SDA-> pin A4
  • ###Connection with DT11###
  • Vcc->5V
  • Gnd->Gnd
  • Out-> pin 7

*/

#include <DS3231.h> //Library for RTC module (Download from Link in article)
#include <SPI.h> //Library for SPI communication (Pre-Loaded into Arduino)
#include <SD.h> //Library for SD card (Pre-Loaded into Arduino)
#include <DHT.h> //Library for dht11 Temperature and Humidity sensor (Download from Link in article)

#define DHT11_PIN 7 //Sensor output pin is connected to pin 7
DHT dht; //Sensor object named as DHT

const int chipSelect = 4; //SD card CS pin connected to pin 4 of Arduino

// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);

void setup()
{
// Setup Serial connection
Serial.begin(9600);
Initialize_SDcard();
Initialize_RTC();
Initialize_PlxDaq();
}

void loop()
{
Read_DHT11();
Write_SDcard();
Write_PlxDaq();
delay(5000); //Wait for 5 seconds before writing the next data
}

void Write_PlxDaq()
{
Serial.print("DATA"); //always write "DATA" to Indicate the following as Data
Serial.print(","); //Move to next column using a ","

Serial.print("DATE"); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.print("TIME"); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.print(DHT.temperature); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.print(DHT.humidity); //Store date on Excel
Serial.print(","); //Move to next column using a ","

Serial.println(); //End of Row move to next row
}

void Initialize_PlxDaq()
{
Serial.println("CLEARDATA"); //clears up any data left from previous projects
Serial.println("LABEL,Date,Time,Temperature,Humidity"); //always write LABEL, to indicate it as first line
}

void Write_SDcard()
{
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.print(rtc.getDateStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.print(rtc.getTimeStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.print(DHT.temperature); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.print(DHT.humidity); //Store date on SD card
dataFile.print(","); //Move to next column using a ","

dataFile.println(); //End of Row move to next row
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}

void Initialize_SDcard()
{
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println("Date,Time,Temperature,Humidity"); //Write the first row of the excel file
dataFile.close();
}
}

void Initialize_RTC()
{
// Initialize the rtc object
rtc.begin();

//#### The following lines can be uncommented to set the date and time for the first time###
/*
rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(18, 46, 45); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 30, 2017); // Set the date to January 1st, 2014
*/
}

void Read_DHT11()
{
int chk = dht.read11(DHT11_PIN);
}

/*void Read_DateTime()
{
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");

// Send time
Serial.println(rtc.getTimeStr());
}*/

/void Read_TempHum()
{
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
// delay(1000);
}
/

sketch_jul25d:32:5: error: no matching function for call to 'DHT::DHT()'

DHT dht; //Sensor object named as DHT

^

In file included from C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino:29:0:

C:\Users\nicks\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:49:4: note: candidate: DHT::DHT(uint8_t, uint8_t, uint8_t)

DHT(uint8_t pin, uint8_t type, uint8_t count=6);

^

C:\Users\nicks\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:49:4: note: candidate expects 3 arguments, 0 provided

C:\Users\nicks\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate: constexpr DHT::DHT(const DHT&)

class DHT {

^

C:\Users\nicks\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate expects 1 argument, 0 provided

C:\Users\nicks\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate: constexpr DHT::DHT(DHT&&)

C:\Users\nicks\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate expects 1 argument, 0 provided

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino: In function 'void Write_PlxDaq()':

sketch_jul25d:67:21: error: expected primary-expression before '.' token

Serial.print(DHT.temperature); //Store date on Excel

^

sketch_jul25d:70:21: error: expected primary-expression before '.' token

Serial.print(DHT.humidity); //Store date on Excel

^

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino: In function 'void Write_SDcard()':

sketch_jul25d:96:23: error: expected primary-expression before '.' token

dataFile.print(DHT.temperature); //Store date on SD card

^

sketch_jul25d:99:23: error: expected primary-expression before '.' token

dataFile.print(DHT.humidity); //Store date on SD card

^

C:\Users\nicks\Documents\Arduino\sketch_jul25d\sketch_jul25d.ino: In function 'void Read_DHT11()':

sketch_jul25d:142:15: error: 'class DHT' has no member named 'read11'

int chk = dht.read11(DHT11_PIN);

^

exit status 1
no matching function for call to 'DHT::DHT()'

Take a look at the examples that come with the library. Better yet, try getting one of them working first. You have way too much code for something that doesn't even declare the dht sensor correctly.

From the example:

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}
dataFile.print(DHT.temperature); //Store date on SD card
    dataFile.print(","); //Move to next column using a ","

    dataFile.print(DHT.humidity); //Store date on SD card
    dataFile.print(","); //Move to next column using a ","

Still have a bunch of DHT instead of dht.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Forget you code for the moment.
Just use the example code in the IDE and get it working for the DHT.

Start to write your code in stages.
Trying write all your code at once will only cause conflicting errors.

So just start by getting your DHT code working and giving data.

What model Arduino are you using?

Thanks.. Tom... :slight_smile: