Design of an Intelligent Tea Brewing Machine Based on STM32 Microcontroller

System Overview

This design is based on the STM32F103 series microcontroller to develop an intelligent tea brewing machine control system. By integrating components such as temperature sensors, liquid level sensors, weighing modules, and relay control, it achieves precise water temperature control, automatic brewing, and status display functions. The system adopts a modular design, including a central control part, input part, and output part, supporting parameter presets for various types of tea and remote control functionality.

Design of an Intelligent Tea Brewing Machine Based on STM32 Microcontroller

Figure 1: Overall System Block Diagram

Hardware Design

Core Control Module

The system uses the STM32F103C8T6 as the main control chip, which has the following advantages:

  • 72MHz main frequency, performance meets real-time control requirements
  • Rich peripheral interfaces (ADC, PWM, USART, etc.)
  • Low power design, suitable for household appliances
  • Cost-effective, with abundant development resources

Sensor Selection

  1. Temperature Sensor: The DS18B20 digital temperature sensor is selected

    • Measurement range: -55℃ to 125℃
    • Accuracy: ±0.5℃
    • Single bus communication, saving IO resources
    • Waterproof packaging, can directly contact liquids
  2. Liquid Level Sensor: An optoelectronic liquid level sensor is used

    • Integrated installation, stable structure
    • Detects water level through infrared optical principles
    • No mechanical parts, long lifespan
    • Automatic alarm function for low water levels.
  1. Weighing Module: HX711 module
    • 24-bit high-precision ADC
    • Supports strain gauge weighing sensors
    • Can detect tea weight and water volume

Actuator Drive Circuit

  1. Heating Control:

    • Uses a solid-state relay to drive the heating tube
    • PWM controls heating power
    • Overcurrent protection and temperature fuse design
  2. Water Pump Control:

    • Relay controls the direct current water pump
    • Flow rate approximately 100ml/min
    • Dual verification of liquid level to prevent dry burning

Power Supply Design

  • Input: 220V AC
  • Main control power supply: 5V DC (via LM7805 voltage regulator)
  • Sensor power supply: 3.3V DC
  • Relay drive: 12V DC

The circuit schematic can be followed on my public account

Contact me via private message for more information.

Software Design

Main Program Framework

c

#include “stm32f10x.h”#include “ds18b20.h”#include “hx711.h”#include “oled.h”#include “relay.h”#include “key.h”// Global variable definitionfloat current_temp = 0;float target_temp = 90; // Default brewing temperatureuint16_t water_level = 0;uint16_t tea_weight = 0;uint8_t tea_type = 0; // 0-Green tea, 1-Black tea, 2-Oolong teaint main(void){ // Hardware initialization SystemInit(); DS18B20_Init(); HX711_Init(); OLED_Init(); Relay_Init(); Key_Init(); // Main loop while(1) { // 1. Data collection current_temp = DS18B20_GetTemp(); water_level = Get_WaterLevel(); tea_weight = HX711_GetWeight(); // 2. User interaction processing Key_Process(); // 3. Control logic execution Tea_Control_Logic(); // 4. Status display update OLED_Display(); // Delay 10ms Delay_ms(10); }}

Temperature PID Control Algorithm

// PID parameterstypedef struct { float Kp; // Proportional coefficient float Ki; // Integral coefficient float Kd; // Derivative coefficient float integral; // Integral term float prev_error; // Previous error} PID_Controller;// PID initializationvoid PID_Init(PID_Controller* pid, float Kp, float Ki, float Kd){ pid->Kp = Kp; pid->Ki = Ki; pid->Kd = Kd; pid->integral = 0; pid->prev_error = 0;}// PID calculate outputfloat PID_Calculate(PID_Controller* pid, float setpoint, float measured_value){ float error = setpoint – measured_value; // Proportional term float Pout = pid->Kp * error; // Integral term (anti-integral saturation) pid->integral += error; if(pid->integral > 100) pid->integral = 100; if(pid->integral < -100) pid->integral = -100; float Iout = pid->Ki * pid->integral; // Derivative term float derivative = error – pid->prev_error; float Dout = pid->Kd * derivative; // Calculate total output float output = Pout + Iout + Dout; // Limit output range 0-100% if(output > 100) output = 100; if(output < 0) output = 0; // Save current error pid->prev_error = error; return output;}// Temperature control taskvoid Temperature_Control_Task(void){ static PID_Controller temp_pid; static uint8_t first_run = 1; if(first_run) { // Initialize PID parameters (need to be tuned according to the actual system) PID_Init(&temp_pid, 5.0, 0.1, 1.0); first_run = 0; } // Calculate PID output float pid_output = PID_Calculate(&temp_pid, target_temp, current_temp); // Convert to PWM duty cycle to control heater Set_Heater_PWM(pid_output);}

Brewing Time Control Logic

// Tea parameters structuretypedef struct { char name[16]; // Tea name float temperature; // Recommended water temperature uint16_t time; // Brewing time (seconds) uint16_t water; // Recommended water volume (ml)} Tea_Parameter;// Brewing parameters for different teasTea_Parameter tea_params[] = { {“Green Tea”, 80, 120, 150}, {“Black Tea”, 95, 180, 200}, {“Oolong Tea”, 90, 240, 180}};// Brewing state machinetypedef enum { STATE_IDLE, // Idle state STATE_HEATING, // Heating STATE_POUR_WATER, // Pouring water STATE_STEEPING, // Steeping STATE_DRAINING, // Draining STATE_COMPLETE // Complete} Tea_Making_State;// Tea control main logicvoid Tea_Control_Logic(void){ static Tea_Making_State state = STATE_IDLE; static uint32_t timer = 0; switch(state) { case STATE_IDLE: if(Start_Button_Pressed()) { // Set parameters based on selected tea type target_temp = tea_params[tea_type].temperature; state = STATE_HEATING; } break; case STATE_HEATING: if(current_temp >= target_temp – 2) { // Near target temperature state = STATE_POUR_WATER; timer = 0; } break; case STATE_POUR_WATER: // Start water pump to pour water Pump_On(); // Water pouring time calculation (simplified to fixed time, should be calibrated based on flow rate) if(++timer > tea_params[tea_type].water / 2) { // Assuming flow rate 100ml/min Pump_Off(); state = STATE_STEEPING; timer = 0; } break; case STATE_STEEPING: if(++timer >= tea_params[tea_type].time) { state = STATE_DRAINING; timer = 0; } break; case STATE_DRAINING: // Open drain valve Drain_Valve_On(); if(++timer > 10) { // Drain for 10 seconds Drain_Valve_Off(); state = STATE_COMPLETE; } break; case STATE_COMPLETE: // Emit completion beep Buzzer_Beep(3); // Return to idle state state = STATE_IDLE; break; }}

Circuit Schematic Design

The system mainly includes the following circuit modules:

  1. Main Control Circuit:

    • STM32F103C8T6 minimum system
    • Reset circuit
    • 8MHz crystal oscillator circuit
    • SWD debugging interface
  2. Power Supply Circuit:

    • 220V to 12V switching power supply
    • 12V to 5V linear regulator
    • 5V to 3.3V LDO
  3. Sensor Interface Circuit:

    • DS18B20 interface circuit (4.7K pull-up resistor)
    • HX711 weighing module interface
    • Liquid level sensor interface
  4. Actuator Drive Circuit:

    • Relay drive circuit (optocoupler isolation)
    • Water pump drive MOSFET circuit
    • Heater solid-state relay drive
  5. Human-Machine Interaction Circuit:

    • OLED display interface (I2C)
    • Button input circuit
    • Buzzer drive circuit

System Debugging and Optimization

Temperature Control Debugging

  1. Output real-time temperature curve via serial port
  2. Adjust PID parameters to achieve steady-state error <±1℃
  3. Test heating performance under different ambient temperatures

Brewing Process Testing

  1. Verify state machine transition logic
  2. Calibrate the relationship between water volume and actual flow rate
  3. Test brewing effects for different types of tea

Safety Protection Testing

  1. Heater protection under low water conditions
  2. Temperature anomaly alarm function
  3. Overcurrent protection function verification

Suggestions for Extended Features

  1. IoT Functionality:

    • Connect to cloud platform via ESP8266 WiFi module
    • Develop mobile app for remote control and monitoring
    • Brewing record and data statistics functionality
  2. Voice Interaction:

    • Integrate voice recognition module
    • Support voice command control
    • Voice status feedback
  3. Intelligent Learning:

    • Record user preference parameters
    • Automatically optimize brewing parameters
    • Recommend brewing schemes based on tea type

Conclusion

This design implements an intelligent tea brewing machine control system based on the STM32 microcontroller. Through reasonable hardware selection and software design, it meets the core functional requirements of precise temperature control, automatic brewing, and status display. The system adopts a modular design, facilitating function expansion and maintenance, and has high practical value and market prospects.

Leave a Comment