Arduino deneyi 12
Temperature and Humidity
Intermediate · 55 min · Digital sensor
Read temperature and relative humidity from a DHT11 sensor.
Malzemeler
- Arduino Uno
- DHT11 module
- Jumper wires
- Arduino DHT sensor library
Bağlantı
- Connect module VCC to 5V, GND to GND and DATA to pin 4.
- For a bare DHT11, add a 10 kΩ pull-up resistor between DATA and 5V.
Kod
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); dht.begin();
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Sensor read failed");
} else {
Serial.print(temperature); Serial.print(" C, ");
Serial.print(humidity); Serial.println(" %");
}
delay(2000);
}
Ne olmalı?
The Serial Monitor updates temperature and humidity about every two seconds.
Meydan okuma
Add an LED warning when temperature exceeds a chosen value.
Güvenlik ve sorun giderme
- Bağlantıyı değiştirmeden önce gücü kes.
- Her LED ile direnç kullan.
- Kart ve port seçimini Arduino IDE'de kontrol et.
- Her kablonun koddaki pin numarasıyla eşleştiğini doğrula.
Not: Ders metinleri İngilizcedir. Orijinal Türkçe çalışma kâğıdı PDF olarak indirilebilir.
