
Bu projeyi gerçekten kurmak istersen parçaları hobidevre.com'dan temin edebilirsin →
Build it for real
To build this project for real, get the parts from hobidevre.com → hobidevre.com →
More build guides: hobidevre.com/blog
What the DHT11 reports
The DHT11 is a combined temperature and relative-humidity sensor with a digital output. It returns both measurements in one response, so you do not need to read an analogue voltage and convert it yourself. The published range is modest — it is intended for ordinary indoor conditions rather than extreme environments.
Because the output is digital, the value arriving at the pin is already a number. This removes analogue noise from the reading, but it also means a failed transfer shows up as an obviously wrong value rather than a slightly noisy one.
Pinout and wiring
A bare DHT11 has four pins in a row: VCC, data, a pin with no function and GND. The order is specified in the datasheet, but cheap modules and breakout boards sometimes place them differently, so check the markings on the part in front of you before connecting anything.
Connect VCC to the 5 V header, GND to ground and the data pin to a digital input-output pin. If you are using a breakout with only three labelled pins, the unused pin has already been omitted. Reversing power and ground is the most common wiring error and should be corrected before the board is powered again.
The pull-up resistor
The data line is open-drain: the sensor pulls it low to signal, and a resistor is needed to bring it back high between those moments. A resistor around 4.7 kilo-ohms from the data line to VCC is a common choice. Many breakout modules already include it, in which case adding another is unnecessary.
If your readings are erratic, check whether the pull-up is present before changing the code. A missing pull-up produces a data line that never settles correctly, which looks very much like a software timing fault.
Install a library
The DHT11 uses its own single-wire timing, so a library is the practical way to talk to it. Install a DHT sensor library through the library manager and include it in your sketch. The library handles the start signal, the response pulse and the decoding of the bits into two floating-point values.
Pass the data pin and the sensor type when you create the object. Selecting the wrong sensor type can produce values that look plausible but are scaled incorrectly.
Read values in a sketch
Initialise the serial monitor, then call the library’s read function at intervals. Store the temperature and humidity in separate variables and check the return value before using them. A failed read should be reported as such, not printed as a temperature of zero.
The example below prints both values and a short status message. It deliberately does nothing else, so that a bad reading can be recognised without other output getting in the way.
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float nem = dht.readHumidity();
float sicaklik = dht.readTemperature();
if (isnan(nem) || isnan(sicaklik)) {
Serial.println("Okuma basarisiz");
} else {
Serial.print("Nem: ");
Serial.print(nem);
Serial.print(" % Sicaklik: ");
Serial.print(sicaklik);
Serial.println(" C");
}
delay(2000);
}
Sampling rate and bad reads
The sensor cannot provide a new measurement instantly. Reading it far more often than its update rate returns the same value repeatedly and can interfere with the transfer itself. A couple of seconds between reads is a reasonable habit for a serial-monitor demo.
A failed transfer is normal occasionally. Handle it by skipping that sample rather than by replacing it with zero. If failures become frequent, look at wiring, the pull-up and the length of the cable before rewriting the code.
If you log readings to a file, include a timestamp and a status flag for every sample. A gap in the log is then obvious, and you can tell at a glance whether a strange value came from the sensor or from a failed transfer that was printed by mistake.
DHT11 versus other sensors
Other sensors in the same family offer wider ranges and finer resolution, usually at a higher cost. If your project only needs a rough indoor indication, the DHT11 is adequate. If you need to measure near freezing, in a hot enclosure or with tighter accuracy, choose a part whose datasheet covers those conditions.
Changing sensor type is mostly a wiring and library change; the structure of the sketch — read, validate, use — stays the same.
Get the parts
DHT11 modules and pull-up resistors are available from hobidevre.com.
Frequently asked questions
Why do I see NaN in the serial monitor?
That means the transfer failed. Check the data connection and pull-up, then read less often and skip failed samples instead of displaying them.
How often can I read the sensor?
Not continuously. Leave a couple of seconds between reads so the sensor has time to produce a new measurement.
Can it be used outdoors?
The part is intended for ordinary indoor conditions. For outdoor or extreme temperatures, choose a sensor rated for that range and protect it from moisture.