dht11 temperature and humidity sensor arduino code




DHT11 Temperature and Humidity Sensor Arduino Code

DHT11 Temperature and Humidity Sensor Arduino Code

Article Summary

  1. Introduction
  2. Understanding the DHT11 sensor
  3. Arduino Integration
  4. Writing the Arduino code
  5. Summary

Introduction

The DHT11 temperature and humidity sensor is a popular choice among Arduino enthusiasts. It allows you to measure both temperature and humidity with a single component, making it ideal for various projects. In this article, we will guide you through the process of integrating the DHT11 sensor with an Arduino board and provide you with a sample code to get started.

Understanding the DHT11 sensor

The DHT11 sensor is a digital sensor that uses a capacitive humidity sensor and a thermistor to accurately measure temperature and humidity. It provides temperature readings from 0 to 50 degrees Celsius with an accuracy of ±2 degrees Celsius, and humidity readings from 20% to 90% with an accuracy of ±5%.

Before diving into the Arduino integration, it’s important to understand the pinout of the DHT11 sensor. The sensor has three pins: VCC, data, and ground. VCC is connected to the 5V pin of the Arduino, ground is connected to the ground pin, and the data pin is connected to any digital pin of the Arduino.

Arduino Integration

To integrate the DHT11 sensor with an Arduino board, you will need the following components:

  • Arduino board (e.g., Arduino Uno)
  • DHT11 sensor
  • Jumper wires

Connect the DHT11 sensor to the Arduino board as described previously. Make sure to connect the data pin to the desired digital pin of the Arduino.

Writing the Arduino code

Now, let’s write the Arduino code to read temperature and humidity values from the DHT11 sensor. First, you need to install the DHT sensor library if you haven’t already. Open the Arduino IDE, go to Sketch -> Include Library -> Manage Libraries, search for “DHT sensor library,” and click install.

Here’s a sample code that reads temperature and humidity values from the DHT11 sensor and displays them on the serial monitor:

#include 
#define DHTPIN 2       // Replace with your data pin
#define DHTTYPE DHT11   // DHT 11 sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(9600);
  dht.begin();
}
void loop() {
  delay(2000);
  
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.print(" °C | Humidity: ");
  Serial.print(humidity);
  Serial.println("%");
}

Summary

In this article, we introduced the DHT11 temperature and humidity sensor and explained its pinout. We then discussed how to integrate the sensor with an Arduino board and provided a sample code to read temperature and humidity values. With this information, you can now start building projects that require temperature and humidity monitoring. Have fun exploring the possibilities!


Related Post

What is a Thermocouple Transmitter?

A thermocouple transmitter is a device designed to convert the temperature readings obtained from a thermocouple sensor into a standardized electrical signal. This electrical signal can then be transmitted over

Shopping Cart
Scroll to Top
Scroll to Top