Project Finished Product Image:

Bilibili Video Link:
https://www.bilibili.com/video/BV1hZBBYwEHb/?share_source=copy_web&vd_source=097fdeaf6b6ecfed8a9ff7119c32faf2
(See end of article for resource sharing)
01
—
Project Introduction
1. Function Details
STM32 Smart Home Appliance Control System
Functions are as follows:
-
STM32F103C8T6 microcontroller board as the main control unit
-
Display function: Real-time display of temperature and humidity data on OLED screen
-
Automatic control: Determine if temperature and humidity are within threshold range, otherwise sound the buzzer alarm
-
Threshold adjustment: Threshold values can be adjusted using buttons
-
Remote control: Control lights, fans, and curtains remotely via the Gizwits Cloud APP
-
Remote monitoring: The Gizwits Cloud APP can remotely monitor environmental temperature and humidity data
2. Bill of Materials
-
STM32F103C8T6 Microcontroller
-
OLED Screen
-
DHT11 Temperature and Humidity Sensor
-
ESP8266-01S WiFi Module
-
Relay
-
High Power LED Module
-
Fan Module
-
Stepper Motor
02
—
Schematic Design

03
—
PCB Hardware Design
PCB Diagram


04
—
Program Design
#include "stm32f10x.h" // Device header#include "gizwits_product.h"#include "oled.h"#include "menu.h"#include "dht11.h"#include "motor.h"#include "key.h"#include "buzzer.h"#include "flash.h"#include "usart.h"#include "sys.h"#include "usb.h"#include "tim3.h"#include "tim2.h"#include "iwdg.h"
#define FLASH_START_ADDR 0x0801f000 // Starting address for writing
u8 Menu = 1; // Menu variable
u8 SetNum = 1;
u8 Temp_value; // Temperature threshold variable
u8 Humi_value; // Humidity threshold variable
int main(void) {
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
OLED_Init();
DHT11_UserConfig();
MOTOR_UserConfig();
Key_Init();
USB_Init();
Buzzer_Init();
Temp_value = FLASH_R(FLASH_START_ADDR); // Read from specified page address in FLASH
Humi_value = FLASH_R(FLASH_START_ADDR + 2); // Read from specified page address in FLASH
Timer2_Init(9, 14398);
uart2_init(9600);
uart1_init(115200);
GENERAL_TIM_Init();
userInit(); // Complete initial assignment
gizwitsInit();
IWDG_Init();
while (1) {
IWDG_ReloadCounter(); // Reload counter value to feed the watchdog
switch(Menu) {
case 1:
Menu1(); // Display menu 1
/* Check if motor start flag is 1 */
if(Curtain_ON_Flag == 1) {
MOTOR_Direction_Angle(1, 0, 180, 1); // Clockwise motor rotation 180 degrees
MOTOR_STOP(); // Motor stop
Curtain_ON_Flag = 0;
}
/* Check if motor stop flag is 1 */
if(Curtain_OFF_Flag == 1) {
MOTOR_Direction_Angle(0, 0, 180, 1); // Counterclockwise motor rotation 180 degrees
MOTOR_STOP(); // Motor stop
Curtain_OFF_Flag = 0;
}
break;
case 2:
OLED_Clear(); // Clear screen
Menu2(); // Display menu 2
Menu = 3;
case 3:
OLED_Option(SetNum); // Display current selection position
OLED_ShowNum(2, 10, Temp_value, 2); // Display temperature threshold data
OLED_ShowNum(3, 10, Humi_value, 2); // Display humidity threshold data
/* Count the number of times button 1 is pressed */
if(KeyNum == 1) {
KeyNum = 0;
SetNum++;
if(SetNum > 2) {
SetNum = 1;
}
}
/* When position points to temperature threshold, adjust value based on button 3 or 4 */
if(SetNum == 1) {
if(KeyNum == 3) {
KeyNum = 0;
Temp_value++;
if(Temp_value >= 100) {
Temp_value = 0;
}
}
if(KeyNum == 4) {
KeyNum = 0;
Temp_value--;
if(Temp_value >= 100) {
Temp_value = 99;
}
}
}
/* When position points to humidity threshold, adjust value based on button 3 or 4 */
if(SetNum == 2) {
if(KeyNum == 3) {
KeyNum = 0;
Humi_value++;
if(Humi_value >= 100) {
Humi_value = 0;
}
}
if(KeyNum == 4) {
KeyNum = 0;
Humi_value--;
if(Humi_value >= 100) {
Humi_value = 99;
}
}
}
/* When button 2 is pressed, return to main menu */
if(KeyNum == 2) {
KeyNum = 0;
/* Store the changed threshold values in Flash */
FLASH_W(FLASH_START_ADDR, Temp_value, Humi_value);
OLED_Clear(); // Clear screen
Menu = 1; // Display menu 1
}
break;
default: break;
}
userHandle();
gizwitsHandle((dataPoint_t *)¤tDataPoint);
}
}
05
—
Experimental Results


Resource Sharing (Baidu Cloud)
https://pan.baidu.com/s/1SyRMEeWhjiycDIb8y7RWoA?pwd=uep1 Extraction Code: uep1
(Or scan the QR code below to obtain)
For physical purchases, scan the QR code below