DHT11 SENSOR ARDUINO CODE

In this tutorial we will see how to interface DHT11 sensor with Arduino and then we write DHT11 sensor arduino code.

DHT sensor comes in two models DHT11 and DHT22 here we will use DHT11. For measuring temperature and humidity in digital form we use DHT sensors.

These values measured in analog form, because all signals in nature present in only analog form but then it converted into digital form.

COMPONENTS REQUIRED

S.N. COMPONENT QUANTITY
1. Arduino UNO 1
2. DHT11 Sensor module 1
3. Connecting wires 3

CIRCUIT DIAGRAM INTERFACING DHT11 SENSOR WITH ARDUINO

DHT11 SENSOR ARDUINO CODE

DHT11 TECHNICAL SPECIFICATION

Operating Voltage 3.3 V to  5V
Humidity Range 20 – 90 % RH
Accuracy ± 5 % RH
Temperature Range 0 – 50 °C
Accuracy ± 2 °C

DHT11 SENSOR ARDUINO CODE

Click to Download DHT Library file at S.N. 21)

/* Tutorial link:  https://pijaeducation.com/arduino/sensor/dht11-sensor-arduino-code/
   To Library download click this link: https://pijaeducation.com/download/ at S.N. 21) DHT-sensor-library-master
*/
#include <DHT.h>;

#define DHTPIN 2     // data pin we're connected to
#define DHTTYPE DHT11   // or DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor

//Variable to Store humidity and temperature value
float hum, temp;  

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {

  //Read data and store it to variables hum and temp
  hum = dht.readHumidity();
  temp = dht.readTemperature();

  //Print temp and humidity values to serial monitor
  Serial.print("Humidity: ");
  Serial.print(hum);
  Serial.print(" %, Temp: ");
  Serial.print(temp);
  Serial.println(" Celsius");
  delay(2000); 
  //Delay 2 sec, this is important to maintain that much delay in each reading
}

OUTPUT

Once you upload arduino sketch to your board then you will see these types of values in the Serial Monitor.

DHT11 Interfacing with Arduino

Arduino Tutorials with Basic Electronics: CONTENT

Translate »