Interfacing DHT11 sensor
In this project, I'll walk you through how to interface a DHT11 humidity and temperature sensor with an OLED display using an Arduino. This is perfect for anyone looking to monitor real-time environmental data with a simple setup.
• Components Required
1. Arduino Uno
2. DHT11 Sensor
3. HW-239A OLED Display (128x64)
4. Jumper wires
5. Breadboard
6. USB cable(data transfer cable)
7. OTG (optional)
Step 1: Wiring the Components
OLED Display (HW-239A)
•VCC → 5V
•GND → GND
•SDA → A4
•SCL → A5
DHT11 Sensor
•VCC → 5V
•GND → GND
•DATA → D2
Ensure all connections are tight and double-check to avoid any errors.
Step 2: Installing the Libraries
Before diving into the code, make sure you have the following libraries installed:
•Adafruit GFX Library
•Adafruit SSD1306 Library
•DHT Sensor Library
To install the libraries:
In laptop or PC;
Go to Sketch → Include Library → Manage Libraries in the Arduino IDE.Search and install the above libraries.
In mobile;
Download Arduinodroid → click on three dots → click on libraries → mannage libraries → Available → search for required libraries → install
Step 3: Arduino Code
Now that everything is connected, here’s the complete code to read data from the DHT11 sensor and display it on the OLED screen.
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <DHT.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C
if(!display.begin(SSD1306_I2C_ADDRESS, OLED_RESET)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
dht.begin();
}
void loop() {
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
float h = dht.readHumidity();
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if
Step 4: upload code and enjoy
• Conclusion
This project demonstrates how to display environmental data on an OLED screen using a DHT11 sensor and an Arduino. It’s simple yet effective for beginners looking to explore electronics and sensor interfacing.
If you want to dive deeper, consider adding more sensors or modifying the display style. Stay tuned for more projects on my YouTube channel, and don't forget to check out the full video tutorial here(link will available soon).
