Getting an error message when attempting to verify an Arduido sketch code. Don’t understand why I’m getting error.
the code is
#include <DHT.h>
#define dataPin 8 // Defines pin number to which the sensor is connected
DHT dht; // Creats a DHT object
void setup() {
Serial.begin(9600);
}
void loop() {
int readData = DHT.read22(dataPin); // Reads the data from the sensor
float t = DHT.temperature; // Gets the values of the temperature
float h = DHT.humidity; // Gets the values of the humidity
// Printing the results on the serial monitor
Serial.print("Temperature = ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(" Humidity = ");
Serial.print(h);
Serial.println(" % ");
delay(2000); // Delays 2 secods, as the DHT22 sampling rate is 0.5Hz
}
error message :
Arduino: 1.8.6 Hourly Build 2018/07/11 05:33 (Windows 10), Board: “Arduino/Genuino Uno”
dht11:3:5: error: no matching function for call to ‘DHT::DHT()’
DHT dht; // Creats a DHT object
^
In file included from D:\BAHAN PI\dht11\dht11\dht11.ino:1:0:
C:\Users\Hp\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:41:4: note: candidate: DHT::DHT(uint8_t, uint8_t, uint8_t)
DHT(uint8_t pin, uint8_t type, uint8_t count=6);
^
C:\Users\Hp\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:41:4: note: candidate expects 3 arguments, 0 provided
C:\Users\Hp\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:39:7: note: candidate: constexpr DHT::DHT(const DHT&)
class DHT {
^
C:\Users\Hp\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:39:7: note: candidate expects 1 argument, 0 provided
C:\Users\Hp\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:39:7: note: candidate: constexpr DHT::DHT(DHT&&)
C:\Users\Hp\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:39:7: note: candidate expects 1 argument, 0 provided
D:\BAHAN PI\dht11\dht11\dht11.ino: In function ‘void loop()’:
dht11:8:21: error: expected primary-expression before ‘.’ token
int readData = DHT.read22(dataPin); // Reads the data from the sensor
^
dht11:9:16: error: expected primary-expression before ‘.’ token
float t = DHT.temperature; // Gets the values of the temperature
^
dht11:10:16: error: expected primary-expression before ‘.’ token
float h = DHT.humidity; // Gets the values of the humidity
^
exit status 1
no matching function for call to ‘DHT::DHT()’
can anyone help?