Design of a Smart Clothesline Control System Based on STM32 and FreeRTOS

#Smart Hardware#STM32#FreeRTOS

Smart clothesline hardware

👉 Hardware kit purchase link (Taobao)

Video walkthrough:

Abstract

To address the slow response to sudden rainfall and the single-purpose nature of traditional clotheslines, this paper designs and implements a smart clothesline control system based on an STM32F103C8T6 and FreeRTOS. The system integrates a temperature/humidity sensor (DHT11), an ambient-light sensor (BH1750) and a rain sensor. An event-bus architecture decouples sensor acquisition, business logic and motor actuation, while an ESP12F module connects the system to the OneNET cloud platform, enabling remote control and dual-chip OTA firmware upgrades. Tests show that the system reliably retracts the clothesline on rainfall and automatically dries clothes out again after a configurable delay once the rain stops.

Keywords: STM32; FreeRTOS; smart clothesline; OTA; event-driven

1 Introduction

Motorized clotheslines are now common in households, yet most products on the market only provide electric raising and lowering, lacking environmental awareness and autonomous decision-making. Targeting a cost-constrained embedded platform (Cortex-M3, 64KB Flash, 20KB RAM), this design introduces a real-time operating system and a layered software architecture so the clothesline can act autonomously — retracting when it rains and drying out again after a delay — while still supporting manual control and remote upgrades, balancing practicality with maintainability.

2 System Overview

The hardware consists of an STM32F103C8T6 main controller, three sensor inputs (DHT11 / BH1750 / rain), a motor driver, an OLED display, a W25Q64 external Flash, and an ESP12F Wi-Fi module. The software adopts a two-layer architecture: the Hardware layer reads and drives peripherals and emits events; the Services layer handles business decisions and state orchestration. The two layers communicate through a central event bus (AppEvent):

sensor task ──event──▶ EventBus ──dispatch──▶ ClotheslineService (decision) ──▶ Motor (actuation)

This decouples sensor drivers from business logic, so adding a sensor or swapping the actuator never touches the decision-layer code.

3 Key Implementation

3.1 Rain detection and retract state machine

Rain sensor signals suffer from mechanical bouncing and cannot be used directly. After hardware-level debouncing, the service layer processes three phases — retract, delay, dry out — as a state machine: rain triggers an immediate retract; after the rain stops, only when in auto mode with the clothes retracted does the system wait for rainStopDelayMs (default 15 s) to confirm there is no further intermittent rain before drying the clothes out again. The core logic:

static void ProcessRainLogic(void)
{
    if (isRaining) {
        rainStopActive = 0;
        TryStartRetract();  /* retract has the highest priority */
        return;
    }
    rainRetracting = 0;  /* rain stopped, clear the retract flag */

    if (IsAutoMode() && clothesState == CLOTHES_IN) {
        if (!rainStopActive) {
            rainStopActive = 1;
            rainStopStartTicks = xTaskGetTickCount();
        } else if ((xTaskGetTickCount() - rainStopStartTicks)
                   >= pdMS_TO_TICKS(rainStopDelayMs)) {
            rainStopActive = 0;
            if (!Motor_IsRunning() && !isRaining) {
                Motor_DryOutForAuto();
            }
        }
    }
}

Here rainStopActive and rainStopStartTicks form a software timing window that prevents the line from oscillating between "retract and dry out" under intermittent drips.

3.2 Dual-chip OTA upgrade

The system supports over-the-air firmware upgrades for both the STM32 and the ESP12F. On the ESP12F side, an rBoot dual-partition layout with an immutable recovery partition provides automatic rollback after a failed upgrade. On the STM32 side, an IAP + YMODEM serial protocol is used: the ESP12F pulls the firmware from a server and forwards it as a stream while the OLED shows live progress as a percentage, avoiding the risk of bricking the device remotely.

4 Testing and Results

The rain-response chain was stress-tested for 48 consecutive hours: after simulated rainfall the system always started retracting within one decision cycle with no missed triggers; after the rain stopped, the clothesline stayed retracted while intermittent drips (shorter than the delay threshold) continued, and only dried out after more than 15 s without rain, matching the design expectation. Temperature/humidity and light data were reported to OneNET over MQTT and were viewable in real time from the app. Each chip completed 10 OTA upgrades successfully, and devices always fell back to a working firmware after deliberately injected power failures.

5 Conclusion

This paper completes the design of a smart clothesline system based on STM32 + FreeRTOS. With the event-bus architecture and state-machine decision logic it delivers reliable automatic rain retraction, together with a complete OTA upgrade scheme and a Chinese font library stored on external Flash. The system demonstrates a viable path for building maintainable, remotely evolvable IoT products on resource-constrained MCUs. Future work may extend it with a light-linked drying strategy and voice control.