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

Arduino Nano-Based Smart Climate Control System with OLED Display and Rotary Encoder

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Smart Climate Control System with OLED Display and Rotary Encoder

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a heater, fan, and bulb based on temperature and humidity readings. The circuit uses an Arduino Nano microcontroller to interface with various sensors and actuators, including a DHT22 temperature and humidity sensor, a DS3231 RTC module, a 0.96" OLED display, a rotary encoder, and a 4-channel relay module. The system can operate in both automatic and manual modes, with settings adjustable via the rotary encoder.

Component List

  1. Arduino Nano

    • Description: Microcontroller board based on the ATmega328P.
    • 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
  2. Heater Element

    • Description: Heating element controlled via relay.
    • Pins: VCC, GND
  3. BULB

    • Description: Light bulb controlled via relay.
    • Pins: +, -
  4. Fan

    • Description: Cooling fan controlled via relay.
    • Pins: GND, 5V
  5. DS3231 RTC

    • Description: Real-time clock module.
    • Pins: 32K, SQW, SCL, SDA, VCC, GND
  6. TEMP (DHT22)

    • Description: Temperature and humidity sensor.
    • Pins: 5V, D3, GND
  7. Relay 4 Channel 5v

    • Description: 4-channel relay module for controlling high-power devices.
    • Pins: GND, IN1, IN2, IN3, IN4, VCC, COM1, COM2, COM3, COM4, NO1, NO2, NO3, NO4, NC1, NC2, NC3, NC4
  8. 0.96" OLED

    • Description: OLED display for visual output.
    • Pins: GND, VDD, SCK, SDA
  9. Rotary Encoder

    • Description: Rotary encoder for user input.
    • Pins: clk, dt, sw, gnd, +
  10. AC-DC PSU board 220V-5V&12V

    • Description: Power supply unit converting 220V AC to 5V and 12V DC.
    • Pins: AC-N, AC-L, +5V, GND, +12V
  11. Power 220v

    • Description: 220V AC power source.
    • Pins: hot wire, neutral wire

Wiring Details

Arduino Nano

Heater Element

BULB

Fan

DS3231 RTC

TEMP (DHT22)

Relay 4 Channel 5v

0.96" OLED

Rotary Encoder

AC-DC PSU board 220V-5V&12V

Power 220v

Code Documentation

#include <Wire.h>
#include <RTClib.h>
#include <DHT.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Encoder.h>
#include <EEPROM.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 10 // Pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define HEATER_PIN 9 // Pin connected to the heater relay
#define FAN_PIN 8 // Pin connected to the fan relay
#define BULB_PIN 7 // Pin connected to the bulb relay

DHT dht(DHTPIN, DHTTYPE);
RTC_DS3231 rtc;
Encoder myEnc(2, 3); // Rotary encoder connected to D2 and D3

int buttonPin = 4; // Rotary encoder button connected to D4
int buttonState = 0;
int lastButtonState = 0;
int dayTemperature = 25; // Default day temperature
int nightTemperature = 15; // Default night temperature
int setHumidity = 40; // Default set humidity threshold
bool manualControl = false; // Flag for manual control
bool heaterState = false;
bool fanState = false;
bool bulbState = false;
enum Mode { SET_DAY_TEMP, SET_NIGHT_TEMP, SET_HUMIDITY, MANUAL_CONTROL };
Mode currentMode = SET_DAY_TEMP;

const int EEPROM_ADDR_DAY_TEMP = 0;
const int EEPROM_ADDR_NIGHT_TEMP =