IOT & EMBEDDED SYSTEMS

SMART WINDOW CONTROL

An ESP32-based automated window system to maintain room temperature and reduce basement humidity during winter.

1. The "Why": Balancing Temperature and Humidity

Basements are notorious for humidity problems, especially during winter months. Cold outside air meets warm, moist indoor air, creating condensation and potential mold issues. The challenge is finding the right balance: opening windows to reduce humidity can drop the room temperature too low, while keeping windows closed maintains warmth but traps moisture.

This system was built to solve a specific problem: maintaining a comfortable temperature range (16.5°C to 23°C) while actively reducing humidity when conditions are favorable. The key insight is using absolute humidity rather than relative humidity to make decisions—absolute humidity tells you the actual amount of water vapor in the air, making it possible to determine whether opening a window will actually reduce moisture levels.

By automating this process, the system can make decisions 24/7, taking advantage of favorable conditions (like cold, dry winter air) to continuously reduce basement humidity without constant manual intervention or risking the room getting too cold.

2. The "How": System Architecture

Tech Stack

  • Microcontroller: ESP32 (main controller and web server)
  • Wireless Communication: ESP-NOW for low-power sensor data transmission
  • Sensors: DHT22 (temperature and humidity) - one outside, one or more inside
  • Actuators: Relay board controlling window motor (left, right, breaker relays)
  • Web Server: ESPAsyncWebServer for real-time monitoring and control
  • Frontend: HTML5, CSS3, JavaScript with Server-Sent Events (SSE) for live updates

System Components

Outside Sensor ESP-NOW Main Controller Relay Control Window Motor

The system consists of multiple ESP32 nodes:

Outside Sensor Node

A battery-powered ESP32 with a DHT22 sensor placed outside. It reads temperature and humidity every 2 seconds and transmits the data via ESP-NOW to the main controller. The node uses channel scanning to match the WiFi network channel for reliable communication.

Main Controller

The central ESP32 that receives sensor data, hosts a web server, and controls the window motor via relays. It performs all calculations, makes control decisions, and serves a real-time dashboard to monitor the system status.

Window Motor Control

Three relays control the window motor: left and right for direction, and a breaker for power. The system can open/close fully or incrementally (1-second steps) for precise control. A 20-minute timer prevents constant cycling.

Absolute Humidity Calculation

The system uses the Antoine equation to calculate absolute humidity from temperature and relative humidity:

1. Calculate saturated vapor pressure: P_sat = 10^(A - B/(C + T))
2. Calculate actual vapor pressure: P_actual = (P_sat × RH) / 100
3. Convert to absolute humidity: AH = P_actual / (R × T_K) × 1000 g/m³

Where A=8.07131, B=1730.63, C=233.426 (Antoine constants for water), R=461.5 J/(kg·K), and T_K is temperature in Kelvin. This gives the actual mass of water vapor per cubic meter, allowing direct comparison between inside and outside conditions.

3. Control Logic

The system operates in three modes, selectable via web interface or touch sensor:

Auto Mode (Default)

The system continuously evaluates conditions and makes decisions:

  • Temperature in range (16.5-23°C): If inside absolute humidity is higher than outside, incrementally opens the window. If outside is wetter, closes the window.
  • Too warm (>23°C): Opens window fully to cool the room.
  • Too cold (<16.5°C): Closes window to maintain warmth.

A 20-minute timer prevents rapid cycling, and incremental control allows fine-tuning without full open/close cycles.

Window Open Mode

Forces the window to open fully, overriding automatic control. Useful for manual intervention or when you want to ensure maximum ventilation.

Window Closed Mode

Forces the window to close and stay closed, useful for maintaining temperature during very cold periods or when you want to prevent any automatic operation.

4. Web Interface & Monitoring

The ESP32 hosts a web server accessible on the local network, providing:

  • Real-Time Data: Live updates of inside/outside temperature and humidity via Server-Sent Events (SSE), updating every 15 seconds without page refresh.
  • Absolute Humidity Display: Shows calculated absolute humidity values for both inside and outside, with clear indication of which is higher.
  • Window Status: Current window position (0-100%), time since last operation, and current mode.
  • Mode Control: Toggle between Auto, Open, and Closed modes directly from the web interface.

The interface uses Server-Sent Events for efficient one-way communication from the ESP32 to the browser, providing real-time updates without the overhead of WebSockets or constant polling.

5. Key Design Decisions

Several design choices were made to ensure reliable operation:

  • ESP-NOW for Sensors: Lower power consumption than WiFi for battery-powered sensor nodes, with reliable point-to-point communication.
  • Incremental Control: Instead of always fully opening/closing, the system can move in 1-second increments, allowing precise positioning and reducing wear on the motor.
  • Timer-Based Throttling: The 20-minute minimum between operations prevents rapid cycling that could damage the motor or waste energy, while still allowing responsive control.
  • Absolute Humidity Focus: By comparing absolute rather than relative humidity, the system makes correct decisions even when temperatures differ significantly between inside and outside.