Showing DS18B20 temperature sensor data in Nextion screen

Hello
I have been trying to show DS18B20 sensors temperature variables in my nextion display but when ever I try to upload this code I ve got the error:

#include <DS18B20.h>
#define DS18B20PIN 2
#define DS18B20TYPE DS18B20


float temperature = 0.0f;

DS18B20 heat(DS18B20PIN, DS18B20TYPE);

void setup(){
  Serial.begin(9600);
  heat.begin();
}

void loop(){
  readSensor();
  sendTemperatureToNextion();
  delay(2000);
}

void readSensor()
{
 temperature = dht.readTemperature();
}

void sendTemperatureToNextion()
{
  String command = "temperature.txt=\""+String(temperature,1)+"\"";
  Serial.print(command);
  endNextionCommand();
}

void endNextionCommand()
{
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

and the erorr:

Arduino:1.8.19 (Windows 10), Kart:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

sketch_jun15a:8:37: error: expected primary-expression before ')' token

DS18B20 heat(DS18B20PIN, DS18B20TYPE);

                                 ^

C:\Users\ahmet\OneDrive\Belgeler\Arduino\sketch_jun15a\sketch_jun15a.ino: In function 'void setup()':

sketch_jun15a:12:8: error: 'class DS18B20' has no member named 'begin'

heat.begin();

    ^~~~~

C:\Users\ahmet\OneDrive\Belgeler\Arduino\sketch_jun15a\sketch_jun15a.ino: In function 'void readSensor()':

sketch_jun15a:23:16: error: 'dht' was not declared in this scope

temperature = dht.readTemperature();

            ^~~

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.

Members do not like to have to download code. Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Isn't the type wrong?

Are there any examples that come with the DS18B20 library? Do the examples us a begin() statement?

You failed to include a dht library or create a dht object. How do you expect to read a
non-existent dht sensor?

why do I need a dht libary ?

isnt it another sensor libary

#include <DS18B20.h>
#define DS18B20PIN 2
#define DS18B20TYPE DS18B20


float temperature = 0.0f;

DS18B20 heat(DS18B20PIN, DS18B20TYPE);

void setup(){
  Serial.begin(9600);
  heat.begin();
}

void loop(){
  readSensor();
  sendTemperatureToNextion();
  delay(2000);
}

void readSensor()
{
 temperature = dht.readTemperature();
}

void sendTemperatureToNextion()
{
  String command = "temperature.txt=\""+String(temperature,1)+"\"";
  Serial.print(command);
  endNextionCommand();
}

void endNextionCommand()
{
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

You need a separate library to read the dht sensor as it is not the same as a DS18B20. Or write the code to read the dht yourself (which I wager is outside your current ability). The IDE library manager has libraries to help to read those sensors.

but I am useing DS18B20 sensor .. ohhh I ve wrote wrong one

I am useing only DS18H20 sensor and my main problem is expected primary expression before ')' token

the error

Look at the constructor in the example.

DS18B20 ds(2);

It only takes the pin number, not a pin and type.

Here is the documentation for the library.

hmmm so I think I confused with dht sensor in dht do we need type and pin ?

Similarly, the DS18B20 library doesn't have a begin method.

Post a schematic, please.

I have no idea what you have. You include a library for a DS18B20 one wire temperature sensor.
The DHT11 or DHT22 are completely different sensors for temperature and humidity. A DS18B20 library is totally wrong for reading a DHT. If you have a DHT sensor you will need a library for that and not a library for DS18B20. If you have both, you will need a library for each.

The DHT sensors are very popular with Arduino. A search for "dht sensor arduino" gets almost a half million hits. Check some out to see what others have done. There are several DHT libraries available via the IDE library manager. They all should have example code to get you started.

actually I was just confuesde about sensors because the code I ve got form is actually base of dht sensor

Which one, DHT11 or DHT22?

How about that schematic?

I ve designed it again an the sensor was dht22

actually I didnt understand probally what are the problems abou my code exactly.

note: I am gona use DS18B20 sensor for my project

Hi me from another account can u write every mistak or the main ones and how to solve them beacuse it gets a little confuseing I need to know exact problems to solve the error

" expected primary expression before ')' token" isnt this my main problem how can I solve this

Get rid of the type as you were advised in post #10.