DHT11 Problems

Hi,
I recently bought this sensor of temperature/humidity for a project, but if never use one of those.
I tried codes from internet but I got errors or it don't display anything.
If someone has used this type of sensors, please help me.

We can't know what you are doing wrong until we know what you are doing. How is the sensor wired? Show the code you tried. Show the output of the code. Show errors reported.

#include <idDHT11.h>

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600); 
  Serial.println("DHT11 test!");
 
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
  }
}

That's the code I'm using

for the wiring:

i've used diferent the leg on the left goes to gnd and the one of the right goes to 5v, if it's the otherway it will fry. But the pin of the middle i don't where it goes i've seen some projects using analog pins and some digtal pins.

I want to measure tempearture and humidity and show it on the screen of the computer

I also have this error:

'DHT' does not a name type

The error usually means that the library is not installed properly. The DHT11 folder should be in the libraries folder in your sketchbook.
The DHT11 sensors that I have are all labeled as to the pinout. They are digital so connect to any digital input.

Thanks, I'm going to check that library

I'm sorry, but it still doesn't working

Where did you get the code? Is it an example from the installed library?

Same error?

I finally manage to run the code, but now all give me 0 in temperature and humidity.

Please give my DHTlib a try - Arduino Playground - DHTLib -

It is confirmed working well with different boards and DHT-sensors.
The syntax is slightly different but the examples should work.

best part: it includes some error handling helping to track faulty situations like you have.

+1 for the DHT11 library. I have used it for several projects and it has worked well. Thanks for the library, robtillaart.