P
P
Pavel2020-09-24 16:00:01
Arduino
Pavel, 2020-09-24 16:00:01

How to fix DHT access error?

#include "C:\Users\User\Documents\Arduino\DHT11.h"
DHT11 DHT(DHT11); // Указать датчик DHT11, DHT21 или DHT22. (несколько датчиков вписывать не нужно)
// Подключать можно только одинаковые датчики, то есть нельзя использовать одновременно DHT11 и DHT22

void setup() 
{
  Serial.begin(57600);
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);
}

void loop() 
{
  int t = DHT.readTemperature(2); // чтение датчика на пине 2
  int h = DHT.readHumidity(2);    // чтение датчика на пине 2
  delay(2000);
  
  Serial.print("Hum: ");
  Serial.print(h);
  Serial.print(" %");
  Serial.print("Temp: ");
  Serial.print(t);
  Serial.println(" C ");
  Serial.print("Hum2: ");
  Serial.print(h2);
  Serial.print(" %");
  Serial.print("Temp2: ");
  Serial.print(t2);
  Serial.println(" C "); 
}


This Error
C:\Users\User\Documents\Arduino\dhT\dhT.ino: In function 'void loop()':
dhT:16:15: error: request for member 'readTemperature' in 'DHT', which is of non-class type 'DHT11(DHT11)'
int t = DHT.readTemperature(2); // read sensor on pin 2
^~~~~~~~~~~~~~~
dhT:17:15: error: request for member 'readHumidity' in 'DHT', which is of non-class type 'DHT11 (DHT11)'
int h = DHT.readHumidity(2); // read sensor on pin 2
^~~~~~~~~~~~
dhT:27:16: error: 'h2' was not declared in this scope
Serial.print(h2);
^~
C:\Users\User\Documents\Arduino\dhT\dhT.ino:27:16: note: suggested alternative: '
^~
h
dhT:30:16: error: 't2' was not declared in this scope
Serial.print(t2);
^~
C:\Users\User\Documents\Arduino\dhT\dhT.ino:30:16: note: suggested alternative: 't'
Serial.print(t2);
^~
t
exit status 1
request for member 'readTemperature' in 'DHT', which is of non-class type 'DHT11(DHT11)'

Help me fix this error

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Pavlov, 2020-09-24
@Stalker31

Try adding your library first


Library Manager
and then include your library from the library manager

O
Ocelot, 2020-09-24
@Ocelot

Look carefully here:

DHT11 DHT(DHT11);

what you have is the name of the class, what is the name of the instance, and what is the constant that is defined in the library.

L
lonelymyp, 2020-09-25
@lonelymyp

Did you install the library?
So have you tried it?

#include "stDHT.h"
DHT sens(DHT11);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question