Interfacing DHT11 Sensor with OLED Display using Arduino Nano


Title: Interfacing DHT11 Sensor with OLED Display using Arduino Nano

 

In this project, we will demonstrate how to interface the DHT11 temperature and humidity sensor with an OLED display using an Arduino Nano. This setup will allow real-time monitoring of temperature (in Celsius) and humidity percentages, as shown in the image above.

Components Required:

  • Arduino Nano
  • DHT11 Temperature and Humidity Sensor
  • 0.96″ I2C OLED Display (128×64)
  • Breadboard and jumper wires
  • 10kΩ resistor (optional for pull-up in DHT11)

 

 

Circuit Diagram:

 

The following pin connections will guide you in setting up the hardware:

  1. DHT11 Sensor:
    • VCC: Connect to 5V on Arduino Nano
    • GND: Connect to GND on Arduino Nano
    • Data Pin: Connect to Digital Pin D3 on Arduino Nano
  2. OLED Display (I2C):
    • VCC: Connect to 5V on Arduino Nano
    • GND: Connect to GND on Arduino Nano
    • SCL: Connect to A5 (I2C Clock) on Arduino Nano
    • SDA: Connect to A4 (I2C Data) on Arduino Nano

Code Implementation:

The Arduino code will display temperature and humidity data on the OLED in real-time. We will use the DHT library for the DHT11 sensor and the Adafruit_SSD1306 library to control the OLED display.

//////////////////////////////////////////

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F(“SSD1306 allocation failed”));
for(;;);
}
dht.begin();

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
}

void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {
Serial.println(F(“Failed to read from DHT sensor!”));
return;
}

display.clearDisplay();

display.setCursor(0, 0);
display.print(“Temp: “);
display.print(t);
display.print(” C”);

display.setCursor(0, 20);
display.print(“Humidity: “);
display.print(h);
display.print(” %”);

display.display();
}

////////////////////////////////////////////

Explanation:

  • Libraries Used:
    • The Adafruit_SSD1306 library controls the OLED display, enabling us to display text and shapes.
    • The DHT library facilitates the DHT11 sensor’s interaction with the Arduino to read temperature and humidity.
  • Initialization:
    • The OLED display is initialized in the setup() function. The DHT11 sensor is also initialized using dht.begin().
    • The loop runs every 2 seconds to fetch and display the latest temperature and humidity values.
  • Display Data:
    • The temperature (in °C) and humidity values (in %) are displayed on the OLED, which you can customize for larger or different font sizes and positions.

Final Result:

Once the hardware is set up and the code uploaded to the Arduino Nano, you will see the OLED display showing real-time temperature and humidity, as shown in the image. The system is perfect for small monitoring systems that require compactness and portability.

Applications:

  • Home automation projects
  • Weather monitoring systems
  • Temperature and humidity monitoring in greenhouses or indoor spaces

By following the steps and code provided, you can easily set up this Arduino project and enjoy real-time environmental data displayed on an OLED screen!