How to use DHT11 sensor - Simple Tutorial
Friday, April 21, 2017This is a simple, brief guide to use or test your DHT11 temperature and humidity sensor with arduino for first time.
By using below sketch you can see the real time reading of DHT11 sensor in your aruino IDE serial monitor.
Parts required
- Arduino UNO/Nano (any arduino board)
- DHT11 sensor module
- Jumper cables
- LED bulb
Steps
- Connect VCC of DHT11 sensor to Arduino pin 5V
- Connect OUT of DHT11 sensor to Arduino pin 9
- Connect GND of DHT11 sensor to Arduino pin GND
Circuit diagram of DHT11 with arduino.
//
// FILE: dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 9
void setup(){
Serial.begin(9600);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}
void loop(){
int chk;
Serial.print("DHT11, \t");
chk = DHT.read(DHT11_PIN); // READ DATA
switch (chk){
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAT DATA
Serial.print(DHT.humidity);
Serial.print(",\t");
Serial.println(DHT.temperature);
delay(1000);
}
Click here to download the code
1 comments
This comment has been removed by the author.
ReplyDeleteClick on 'Notify me' to get replies of your comment.