I am having a problem with my arduino, I’m using a Mega and a DHT11 sensor, the problem comes when the sensor is just giving me a Temperature of 0.00 C and also a humidity of 0.00% always, I am not sure if there is problem with my code but i also tried some online code and they gave me the same problem. My code is as follows:
#include <dht.h>
#define dataPin 7 // 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.read11(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
}