Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano-Based Temperature and Humidity Monitor with OLED Display and Automatic Fan Control

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Temperature and Humidity Monitor with OLED Display and Automatic Fan Control

Circuit Documentation

Summary

This circuit is designed to monitor temperature and humidity using a DHT11 sensor and display the readings on a 1.3" OLED display. Additionally, a fan is controlled based on the temperature readings. The entire system is managed by an Arduino Nano microcontroller.

Component List

  1. OLED 1.3" Display

    • Description: A small OLED display used to show temperature and fan status.
    • Pins: GND, VCC, SCL, SDA
  2. DHT11 Humidity and Temperature Sensor

    • Description: A sensor used to measure temperature and humidity.
    • Pins: VDD, DATA, NULL, GND
  3. Fan

    • Description: A fan that is turned on or off based on the temperature readings.
    • Pins: GND, 5V
  4. Arduino Nano

    • Description: A microcontroller used to read sensor data, control the fan, and update the OLED display.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK

Wiring Details

OLED 1.3" Display

DHT11 Humidity and Temperature Sensor

Fan

Code Documentation

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

// OLED display width and height
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// Initialize OLED display (I2C address 0x3C)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// DHT Sensor setup
#define DHTPIN 2
#define DHTTYPE DHT11 // Change to DHT22 if using a DHT22 sensor
DHT dht(DHTPIN, DHTTYPE);

// Fan pin
#define FAN_PIN 3

// Temperature threshold
#define TEMP_THRESHOLD 20

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize OLED display
  if (!display.begin(0x3C)) {
    Serial.println("SSD1306 allocation failed");
    for (;;);
  }
  display.display();
  delay(2000);
  display.clearDisplay();

  // Initialize DHT sensor
  dht.begin();

  // Initialize fan pin
  pinMode(FAN_PIN, OUTPUT);
  digitalWrite(FAN_PIN, LOW); // Ensure fan is OFF at start
}

void loop() {
  // Read temperature
  float temp = dht.readTemperature();

  // Check if reading is valid
  if (isnan(temp)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Determine fan status
  bool fanOn = temp > TEMP_THRESHOLD;

  // Control fan
  digitalWrite(FAN_PIN, fanOn ? HIGH : LOW);

  // Display temperature and fan status on OLED
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print("Temp: ");
  display.print(temp, 1); // Display temperature with 1 decimal
  display.print(" C");

  display.setTextSize(2);
  display.setCursor(0, 30);
  if (fanOn) {
    display.print("FAN: ON");
  } else {
    display.print("FAN: OFF");
  }

  display.display();
  delay(1000); // Update every 1 second
}

This code initializes the OLED display and DHT11 sensor, reads the temperature, and controls the fan based on the temperature threshold. The temperature and fan status are displayed on the OLED screen.