We will learn how to interface the DHT11 temperature and humidity sensor with the Arduino UNO in this tutorial. The acronym for Digital Humidity and Temperature sensor is DHT. The resistive humidity sensor, NTC temperature sensor, and 8-bit microcontroller that make up the DHT11 provide great quality, fast response times, anti-interference capabilities, and affordability.
Components Required:-
- DHT11 Sensor
- Arduino Uno
- 0.96 inch OLED
- Bread Board
- Jumper Wires
DHT11 Temperature and Humidity Sensor
- Operating Voltage : 3V ~ 5.5V
- Temperature range : 0 ~ 50°C
- Temperature Accuracy : 2°C
- Humidity range : 20 – 90 %RH
- Humidity Accuracy : 5 %RH
- Maximum Sampling Rate : 1 Hz
- Pin Out : VCC – Power In, Data – Data Out, NC – No Connection, GND – Ground
VCC pin provides power to the sensor. Despite the fact that the supply voltage ranges from 3.3V to 5.5V, a 5V supply is recommended. With a 5V power supply, the sensor can be placed up to 20 meters away. With 3.3V supply voltage, the sensor can be placed up to 1 meter away; otherwise, the line voltage drop will cause measurement errors.
Data pin is used for communication between the sensor and the microcontroller.
NC Not connected
Data pin is used for communication between the sensor and the microcontroller.
NC Not connected
GND is the ground pin.
Working:-
- Both an NTC temperature sensor and a humidity measuring component are included with the DHT11 sensor.
- The component used to measure humidity is made up of two electrodes with a substrate positioned in between.
- The resistance between the electrodes varies when there is a change in the conductivity of the substrate due to variations in humidity or moisture.
- As the temperature rises, the NTC thermistor's resistance falls.
- The inbuilt microcontroller measures, interprets, and transmits the resistance change via the data line.
Circuit Diagram:-
Description:-
- DHT11 VCC pin – 5V output of Arduino Uno
- OLED VCC pin – 5V output of Arduino Uno
- DHT11 GND pin – GND of Arduino Uno
- OLED GND pin – GND of Arduino Uno
- DHT11 Data pin – Digital pin 2 of Arduino Uno
- OLED SCL pin – Pin A4 of Arduino Uno
- OLED SDA pin – Pin A5 of Arduino Uno
Program:-
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#define DHTPIN 2
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C
display.display(); // show splash screen
delay(2000);
display.clearDisplay(); // clears the screen and buffer
dht.begin();
delay(2000);
}
void loop() {
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed.
if (isnan(h) || isnan(t) || isnan(f)) {
delay(2000);
}
else {
// routine for converting temp/hum floats to char arrays
char temp_buff[5]; char hum_buff[5];
char temp_disp_buff[11] = "Tmp:";
char hum_disp_buff[11] = "Hum:";
// appending temp/hum to buffers
dtostrf(t,2,1,temp_buff);
strcat(temp_disp_buff,temp_buff);
dtostrf(h,2,1,hum_buff);
strcat(hum_disp_buff,hum_buff);
// routine for displaying text for temp/hum readout
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(temp_disp_buff);
display.println(hum_disp_buff);
display.display();
delay(2000);
}
}
Functioning:-
- The pin that is attached to the OLED reset pin is defined by the Adafruit_SSD1306 display (OLED_RESET).
- The DHT sensor type and the pin that the data line is attached to are specified by DHT dht(DHTPIN, DHTTYPE).
- The DHT sensor and the OLED display are initialized with their I2C addresses (0x3C) in the setup() function.
- We continuously read the temperature and humidity values from the sensor and print them on the OLED display in the loop().
Conclusion
- I hope you now have a better understanding of how the Arduino Uno and DHT11 temperature and humidity sensor function together. Moreover, regarding the Arduino Uno and SSD1306 OLED display integration. If you have any questions, don't hesitate to leave a remark below.
Tags:
asmita
astitva
b2acypher
Interfacing DHT11 Temperature and Humidity Sensor with Arduino Uno
IOT Practicals
mskuthar