Product images of the project:

Bilibili video link:
https://www.bilibili.com/video/BV1xw4m1Y7sA/?share_source=copy_web&vd_source=097fdeaf6b6ecfed8a9ff7119c32faf2
(See the end of the article for resource sharing)
01
—
Project Introduction
1. Function Details
Smart fan system based on STM32
The functions are as follows:
-
OLED displays the current temperature, humidity, fan gear, and speed, with automatic and manual modes.
-
Buttons can switch between automatic and manual modes, and in automatic mode, a temperature threshold can be set.
3. In manual mode, the fan can be turned on freely, and the gear level can be adjusted.
4. In automatic mode, when the human infrared sensor detects a person and the current temperature exceeds the set upper limit, the fan turns on.
5. Each speed adjustment increases the fan gear by one, with a maximum of 5 gears.
6. There is a countdown function that allows setting a timer; when the time is up, the fan automatically turns off.
7. Bluetooth APP control, with manual, automatic, mode switching, and countdown functions.
Main Components:
-
STM32F103C8T6 microcontroller
-
DHT11 temperature and humidity sensor
-
OLED screen
-
HC-SR501 human infrared sensor
-
BT04A Bluetooth module
-
TB6612 motor driver module
-
Active buzzer
-
LED light
-
Fan module
02
—
Schematic Design

03
—
PCB Hardware Design
PCB Diagram


04
—
Program Design
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "Motor.h"
#include "MatrixKey.h"
#include "RED.h"
#include "DHT11.h"
#include <string.h>
#include "Timer.h"
#include "beep.h"
#include "Serial.h"
char RxData; // Receive Bluetooth data
uint8_t KeyNum, RED_Data, RH, TH; // Used to get key, infrared, temperature, humidity
int8_t Speed; // Fan speed
uint8_t Key_M = 1, Time_demo; // Used to switch modes
uint8_t Time_1, Time_10, Time; // Units and tens of time, total time
uint8_t temperature = 30; // Threshold setting
int8_t dang = 0; // Gear count
uint8_t Num = 1, Timedemo; // Flag
int main(void) {
/* Module initialization */
OLED_Init(); // OLED initialization
Motor_Init();
DHT11_Init();
MatrixKey_Init();
Red_Init();
Timer_Init();
Serial_Init();
BEEP_GPIO_Config();
OLED_ShowChinese(0, 0, "Temperature");
OLED_ShowChinese(16*4, 0, "Humidity");
OLED_ShowChinese(0, 16, "Mode");
OLED_ShowChinese(16*4, 16, "Gear Count");
OLED_ShowNum(16*2, 16, Key_M, 1, OLED_8X16);
OLED_ShowNum(16*6, 16, dang, 1, OLED_8X16);
OLED_ShowChinese(0, 16*2, "Speed:");
OLED_ShowSignedNum(16*3, 16*2, Speed, 3, OLED_8X16);
OLED_ShowChinese(0, 16*3, "Countdown:");
OLED_ShowNum(16*4, 16*3, Time, 2, OLED_8X16);
OLED_Update();
GPIO_SetBits(GPIOB, GPIO_Pin_0);
GPIO_SetBits(GPIOB, GPIO_Pin_1);
Delay_ms(100);
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
GPIO_ResetBits(GPIOB, GPIO_Pin_1);
while (1) {
DHT11_Read_Data(&TH, &RH); // Get current temperature and humidity
OLED_ShowNum(16*2, 0, TH, 2, OLED_8X16);
OLED_ShowNum(16*6, 0, RH, 2, OLED_8X16);
OLED_Update();
if (Timedemo == 1) {
if (RED_Data == 1) // If someone is present
{
OLED_ShowString(16*6, 16*2, "Hi! ", OLED_8X16);
if (temperature < TH) // Actual temperature exceeds set threshold
{
// Speed = (TH-temperature)*20; // Increase speed by 20 for each degree
// if (Speed > 100) {
// Speed = 100;
// }
Speed = 100;
} else Speed = 0;
} else {
OLED_ShowString(16*6, 16*2, "Bey!", OLED_8X16);
Speed = 0;
}
OLED_ShowSignedNum(16*3, 16*2, Speed, 3, OLED_8X16);
OLED_Update();
Motor_SetSpeed(Speed);
}
Delay_ms(500);
}
}
</string.h>
05
—
Experimental Results


Resource Sharing (Baidu Cloud)
https://pan.baidu.com/s/1CKQC8mNIbY3-En7349qZYw?pwd=gd9g Extraction code: gd9g
(Or scan the QR code below to obtain)
Scan the QR code below for physical purchase