Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO with OLED Display and DHT11 Sensor for Temperature and Humidity Monitoring

Image of Arduino UNO with OLED Display and DHT11 Sensor for Temperature and Humidity Monitoring

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with a 0.96" OLED display and a DHT11 temperature and humidity sensor. The Arduino UNO serves as the central processing unit, controlling the OLED display via I2C communication and reading environmental data from the DHT11 sensor. The OLED display shows the temperature and humidity readings obtained from the DHT11 sensor. The circuit is powered through the Arduino UNO, which provides the necessary voltage levels to the connected components.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the central controller for the circuit, interfacing with the OLED display and the DHT11 sensor.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D13-D0.

0.96" OLED

  • Description: A small display that uses OLED technology for high contrast and visibility.
  • Purpose: Displays the temperature and humidity readings from the DHT11 sensor.
  • Pins: GND, VDD, SCK, SDA.

DHT11

  • Description: A basic, ultra-low-cost digital temperature and humidity sensor.
  • Purpose: Measures the ambient temperature and humidity.
  • Pins: DATA, GND, VCC.

Wiring Details

Arduino UNO

  • 3.3V to OLED VDD
  • 5V to DHT11 VCC
  • GND to OLED GND and DHT11 GND
  • A4 (SDA) to OLED SDA
  • A5 (SCL) to OLED SCK
  • D5 to DHT11 DATA

0.96" OLED

  • VDD connected to Arduino UNO 3.3V
  • GND connected to Arduino UNO GND
  • SCK connected to Arduino UNO A5
  • SDA connected to Arduino UNO A4

DHT11

  • VCC connected to Arduino UNO 5V
  • GND connected to Arduino UNO GND
  • DATA connected to Arduino UNO D5

Documented Code

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

// OLED display width and height, in pixels
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // No reset pin, so -1

// Initialize SSD1306 display with the I2C address 0x3C (common for these displays)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// DHT sensor configuration
#define DHTPIN 5 // Pin connected to the DHT11 sensor
#define DHTTYPE DHT11 // DHT 11 sensor type
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // Initialize the display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Check for the OLED display at address 0x3C
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  // Clear the display buffer
  display.clearDisplay();
  display.setTextSize(1); // Set text size to 1
  display.setTextColor(SSD1306_WHITE); // Set text color to white
  display.setCursor(0, 0);
  display.print("Initializing...");
  display.display();

  // Initialize the DHT sensor
  dht.begin();

  delay(2000); // Wait for the DHT sensor to stabilize
}

void loop() {
  // Read humidity and temperature values
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  // Check if any readings failed and exit early (to try again later)
  if (isnan(humidity) || isnan(temperature)) {
    display.clearDisplay();
    display.setCursor(0, 0);
    display.print("Failed to read from DHT sensor!");
    display.display();
    delay(2000); // Wait 2 seconds before retrying
    return;
  }

  // Display temperature and humidity values on the OLED
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Temp: ");
  display.print(temperature);
  display.print(" C");
  display.setCursor(0, 10);
  display.print("Humidity: ");
  display.print(humidity);
  display.print(" %");
  display.display();

  // Wait before updating again
  delay(2000);
}

This code initializes the OLED display and the DHT11 sensor, reads temperature and humidity data from the DHT11, and displays the readings on the OLED screen. If the sensor fails to provide valid readings, an error message is displayed. The display is updated every 2 seconds with the latest readings.