Error: expected primary-expression before '.'

i need some help with my code. The error show
sketch.ino: In function 'void loop()':
sketch.ino:32:16: error: expected primary-expression before '.' token
int chk = DHT.read11(DHT11PIN);
^
sketch.ino:33:18: error: expected primary-expression before ',' token
lcd.setCursor( , 0);
^
sketch.ino:35:16: error: expected primary-expression before '.' token
lcd.print(DHT.temperature);
^
sketch.ino:40:16: error: expected primary-expression before '.' token
lcd.print(DHT.humidity);
^

Error during build: exit status 1

This is my full code

#include <DHT.h>
#include <DHT_U.h>
#define DHT11PIN 4

int dht11 = DHT11;
#include <LiquidCrystal.h>
LiquidCrystal lcd (12, 13, 4, 5, 6, 7);

void setup() {
// masukkan code setup di sini, VoidSetup berjalan sekali sahaja
pinMode (2, INPUT_PULLUP);
pinMode (3, INPUT_PULLUP);
lcd.setCursor (0, 0);
lcd.print ("COUNTER MACHINE ");

Serial.begin(9600);//serial monitor

pinMode(4, OUTPUT); //pin ENA, untuk PWM
pinMode(5, OUTPUT); //pin IN1, digital
pinMode(6, OUTPUT); //pin IN2, digital

//offkan semua pin pada peringkat awal
//dengan meletakkan LOW
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);

}//END VOID SETUP

void loop(){
int chk = DHT.read11(DHT11PIN);
lcd.setCursor( , 0);
lcd.print("Temp: ");
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
delay(2000); //Delay 2 sec between temperature/humidity check.
//Forward-kan Motor selamat 3 saat
forward();
delay(3000);

//Brake-kan Motor selamat 1 saat
brake();
delay(1000);

//Reverse-kan Motor selamat 5 saat
brake();
delay(5000);

//Brake-kan Motor selamat 1 saat
brake();
delay(1000);

}//END VOID LOOP

void forward() {
digitalWrite(4, LOW); //IN2
digitalWrite(5, HIGH); //IN1
analogWrite(6, 255); //ENA - PWM (255 Speed Max, 0 Speed Min)
}//END FORWARD

void reverse() {
digitalWrite(4, HIGH); //IN2
digitalWrite(5, LOW); //IN1
analogWrite(6, 255); //ENA - PWM (255 Speed Max, 0 Speed Min)
}//END REVERSE

void brake() {
digitalWrite(4, HIGH); //IN2
digitalWrite(5, HIGH); //IN1
digitalWrite(6, HIGH); //ENA - PWM (255 Speed Max, 0 Speed Min)
}//END BRAKE

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.


lcd.setCursor( , 0); :thinking:

1 Like

Oops

Hi,
correct your topic by enclosing your code in </> tags.

Your code has several errors that it is even difficult to help you.

I will list a few:

1 (already quoted by @LarryD ) , lcd.setCursor( , 0);

  1. Dual pin definition:

    #define DHT11PIN 4
    LiquidCrystal LCD (12, 13, 4, 5, 6, 7);
    pinMode(4, OUTPUT); //pin ENA, untuk PWM
    pinMode(5, OUTPUT); //pin IN1, digital
    pinMode(6, OUTPUT); //pin IN2, digital

  2. LCD initialization is missing. (lcd.begin(xx,y);

  3. This line doesn't define the instance correctly:
    int dht11 = DHT11;
    Correct for this library:
    DHT_Unified dht(DHTPIN, DHTTYPE);

  4. I stopped here, there must be more errors.

I suggest researching more examples of using this sensor on the web.
There must be several tutorials.

alright thank

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.