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

ESP32-Based Room AC Control System with HTU21D-F Sensors and OLED Display

View and Edit Project In Cirkit DesignerImage of ESP32-Based Room AC Control System with HTU21D-F Sensors and OLED Display

Circuit Documentation

Summary

The circuit is designed to control a room air conditioner using an ESP32 microcontroller. It features three tactile switch buttons for user input to set and adjust the temperature. The circuit also includes three Adafruit HTU21D-F temperature and humidity sensors for environmental monitoring. An OLED display is used to show the current temperature, humidity, and set temperature. The circuit controls four LEDs, which are presumably used to send signals to the air conditioner. The ESP32 microcontroller is programmed to read sensor data, manage user inputs, and control the LEDs based on the temperature settings.

Component List

Tactile Switch Buttons - 12mm Square

Resistor (10k Ohms)

Resistor (22 Ohms)

Resistor (10 Ohms)

Resistor (1 Ohm)

GND

nMOS Transistor (MOSFET)

ESP32 (30 pin)

Adafruit HTU21D-F Temperature & Humidity Sensor

Vcc

LED: Two Pin (white)

128x64 OLED Display (I2C IIC SPI Serial)

Wiring Details

Tactile Switch Buttons - 12mm Square

Resistor (10k Ohms)

Resistor (22 Ohms)

Resistor (10 Ohms)

Resistor (1 Ohm)

nMOS Transistor (MOSFET)

ESP32 (30 pin)

Adafruit HTU21D-F Temperature & Humidity Sensor

LED: Two Pin (white)

128x64 OLED Display (I2C IIC SPI Serial)

Documented Code

/*
 * Room AC Control Project
 * 
 * This project is designed to control a room air conditioner using an ESP32 microcontroller.
 * The system includes three pushbuttons for setting the temperature, increasing, and decreasing the set temperature.
 * It also includes three HTU21D-F temperature and humidity sensors to monitor the room environment.
 * An OLED display is used to show the current temperature, humidity, and set temperature.
 * Four infrared LEDs are used to send control signals to the air conditioner.
 */

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HTU21DF.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Pin definitions
#define SET_BUTTON_PIN 32
#define UP_BUTTON_PIN 35
#define DOWN_BUTTON_PIN 34
#define LED_PIN 4

// OLED display dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// Create instances for the sensors and display
Adafruit_HTU21DF htu1 = Adafruit_HTU21DF();
Adafruit_HTU21DF htu2 = Adafruit_HTU21DF();
Adafruit_HTU21DF htu3 = Adafruit_HTU21DF();
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Variables to store temperature settings
float setTemperature = 24.0; // Default set temperature
float currentTemperature = 0.0;
float currentHumidity = 0.0;

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

  // Initialize the pushbutton pins
  pinMode(SET_BUTTON_PIN, INPUT_PULLUP);
  pinMode(UP_BUTTON_PIN, INPUT_PULLUP);
  pinMode(DOWN_BUTTON_PIN, INPUT_PULLUP);

  // Initialize the LED pin
  pinMode(LED_PIN, OUTPUT);

  // Initialize the sensors
  if (!htu1.begin() || !htu2.begin() || !htu3.begin()) {
    Serial.println("Couldn't find HTU21D-F sensor!");
    while (1);
  }

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

void loop() {
  // Read the pushbutton states
  bool setButtonPressed = !digitalRead(SET_BUTTON_PIN);
  bool upButtonPressed = !digitalRead(UP_BUTTON_PIN);
  bool downButtonPressed = !digitalRead(DOWN_BUTTON_PIN);

  // Adjust the set temperature based on button presses
  if (upButtonPressed) {
    setTemperature += 0.5;
  }
  if (downButtonPressed) {
    setTemperature -= 0.5;
  }

  // Read the sensor data
  currentTemperature = (htu1.readTemperature() + htu2.readTemperature() + htu3.readTemperature()) / 3.0;
  currentHumidity = (htu1.readHumidity() + htu2.readHumidity() + htu3.readHumidity()) / 3.0;

  // Update the OLED display
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print("Set Temp: ");
  display.print(setTemperature);
  display.print(" C");
  display.setCursor(0, 10);
  display.print("Current Temp: ");
  display.print(currentTemperature);
  display.print(" C");
  display.setCursor(0, 20);
  display.print("Humidity: ");
  display.print(currentHumidity);
  display.print(" %");
  display.display();

  // Control the LED based on the set temperature
  if (currentTemperature > setTemperature) {
    digitalWrite(LED_PIN, HIGH); // Turn on the LED
  } else {
    digitalWrite(LED_PIN, LOW); // Turn off the LED
  }

  // Small delay to debounce buttons
  delay(200);
}

This code is responsible for the operation of the ESP32 microcontroller within the circuit. It initializes the hardware components, reads sensor data