[SCM Graduation Project] [jj-015] Smart Fan | Temperature Control Fan | Energy Saving Fan | Automatic Control Fan

1. Basic introduction

Item name:
Intelligent fan system design based on microcontroller
Design of temperature control fan system based on single chip microcomputer
Design of energy-saving fan system based on single-chip microcomputer
Design of automatic control fan system based on single-chip microcomputer

Project name: Smart fan | Temperature-controlled fan | Energy-saving fan | Automatic control fan
Microcontroller type: STM32F103C8T6
Specific functions:
1. Measure the current temperature value through DS18B20. When the temperature is greater than the set minimum value and less than the intermediate value between the maximum value and the minimum value, the fan will be started to rotate at a speed of one gear; when the temperature is greater than the intermediate value between the maximum value and the minimum value and less than the maximum value. value, the fan will be started to rotate at the second speed; when the temperature is greater than the set maximum value, the fan will be started to rotate at the third speed.
2. Adjust the fan speed through MX1508 combined with PWM
3. Use human body infrared to detect whether there is someone, and the fan will automatically turn off if no one is there
4. The fan is driven by a stepper motor to simulate automatic shaking of the head, and the buttons can control start and stop.
5. The fan rotation time can be set by pressing the button. When the time is reached, it will automatically stop (switch to manual mode to stop).
6. Set each threshold, manually control wind speed, and switch modes through buttons
7. Display the measured value through the display screen
Extended functions: Send measurement data to the mobile phone through the WIFI module, and can set thresholds, control wind speed, fan shaking and mode switching

2. Data Overview

Physical information

Please add a picture description

Simulation data

Please add an image description

3. Display of some information on 51 microcontroller

1. Physical picture display

Microcontroller model: STC89C52
Power supply interface: TYPE-C
Board type: PCB integrated board, thickness 1.2, two-layer board (upper and lower layers are copper-clad and grounded)
Device type: The components are basically pin type, and some buck chips will use SMD type.

2. Simulation diagram display

Simulation software version: proteus8.9
Circuit connection method: network label connection method
Note: Some physical components are not included in the simulation. They will be replaced by other components with similar working principles in the simulation. This may cause the physical program to be different from the simulation program.

3. Schematic display

Software version: AD2013
Circuit connection method: network label connection method
Note: The schematic diagram only shows the pin diagram of the module, not the internal structure diagram of the module.

4. PCB diagram display

Exported from the schematic diagram, there is a project number in the middle, which is hidden under the base of the microcontroller and will not be seen after inserting the microcontroller.
Two-layer board, top and bottom covered with copper and grounded.

IV. Display of some information on 32 microcontroller

1. Physical picture display

Microcontroller model: STM32F103C8T6
Power supply interface: TYPE-C
Board type: PCB integrated board, thickness 1.2, two-layer board (upper and lower layers are copper-clad and grounded)
Device type: The components are basically pin type, and some buck chips will use SMD type.

2. Schematic display

Software version: AD2013
Circuit connection method: network label connection method
Note: The schematic diagram only shows the pin diagram of the module, not the internal structure schematic diagram of the module.

3. PCB diagram display

Exported from the schematic diagram, there is a project number in the middle, which is hidden under the base of the microcontroller and will not be seen after inserting the microcontroller.
Two-layer board, top and bottom covered with copper and grounded.

5. System block diagram

Drawing software: VISIO

This design uses a single-chip microcomputer as the core controller, plus other modules to form the entire system of this design, including the central control part, the input part and the output part. The central control part adopts a single-chip microcomputer controller, whose main function is to obtain the data of the input part, and finally control the output part after internal processing and logical judgment. The input consists of four parts. The first part is the temperature detection module, which detects the temperature of the current environment; the second part is the human body pyroelectric detection module, which can detect whether there is anyone in the current environment; the third part is the button module. Through this module, you can switch interfaces, set thresholds, switch modes, etc.; the fourth part is the power supply module, through which the entire system can be powered. The output consists of three parts. The first part is the display module, through which the monitored data and the set threshold can be displayed; the second part is the stepper motor module, through which the fan is controlled to move its head; the third part is the DC motor module. Fans can be controlled through this module for selection. In addition, the Bluetooth module serves as both input and output. The Bluetooth module is connected to the mobile phone and can transmit the monitored data to the user’s mobile phone. The user can also send instructions through the mobile phone to control the work of the fan and its mode switching. The specific system block diagram is shown in Figure 3.1.

6. Partial program display

Software version: keil5
Note: The logic program and driver are separated and distributed in main.c and other .c files

*******Monitoring function
*****/
void Monitor_function(void)
{<!-- -->
if(flag_display == 0) //Measurement interface
{<!-- -->
if(time_num % 10 == 0) //Detect once every 2 seconds
{<!-- -->
      temp_value = DS18B20_Get_Temp(); //Get the temperature value

if(time_num % 30 == 0) //Send data
{<!-- -->
UsartPrintf(USART1,"\r\\
Temperature: %d.?",temp_value/10,temp_value );
if(HUMAN == 0)
UsartPrintf(USART1,"Human body: Someone");
else
UsartPrintf(USART1,"Human body: None");
if(motor_pwm == 0)
UsartPrintf(USART1,"\r\\
Close");
else if(motor_pwm == 300)
UsartPrintf(USART1,"\r\\
First file");
else if(motor_pwm == 600)
UsartPrintf(USART1,"\r\\
Second gear");
else if(motor_pwm == 900)
UsartPrintf(USART1,"\r\\
Third gear");
if(flag_direction == 1)
UsartPrintf(USART1,"Shake your head on");
else
UsartPrintf(USART1,"Shaking head off");
if(flag_mode == 0)
UsartPrintf(USART1,"\r\\
Automatic");
else
UsartPrintf(USART1,"\r\\
Manual");
}
}
if(USART1_WaitRecive() == 0) //Receive data
{<!-- -->
if(usart1_buf[0] == 'A') //A: switch mode
{<!-- -->
if(flag_mode == 0)
flag_mode = 1;
else
flag_mode = 0;
}
else if(usart1_buf[0] == 'B') //B: increase wind speed
{<!-- -->
flag_mode = 1;
motor_pwm + =300;
if(motor_pwm <= 900)
{<!-- -->
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
else
{<!-- -->
motor_pwm = 900;
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
}
else if(usart1_buf[0] == 'C') //C: Reduce wind speed
{<!-- -->
flag_mode = 1;
motor_pwm-=300;
if(motor_pwm >= 0)
{<!-- -->
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
else
{<!-- -->
motor_pwm = 0;
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
}
else if(usart1_buf[0] == 'D') //D: turn on shaking head
{<!-- -->
flag_direction = 1;
}
else if(usart1_buf[0] == 'E') //E: turn off shaking head
{<!-- -->
flag_direction = 0;
}
USART1_Clear();
}
}
}

/****
*******Display function
*****/
void Display_function(void)
{<!-- -->
switch(flag_display) //Display different interfaces according to different display mode flags
{<!-- -->
case 0: //Interface 0: measurement interface, displaying temperature, human body, gear, shaking head, and countdown time
Oled_ShowCHinese(1, 0, "Temperature:");
sprintf(display_buf,"%d.? ",temp_value/10,temp_value );
Oled_ShowString(1, 6, display_buf);

Oled_ShowCHinese(2, 0, "Human body:");
if(HUMAN == 0)
Oled_ShowCHinese(2, 3, "Someone");
else
Oled_ShowCHinese(2, 3, "No");

if(motor_pwm == 0)
Oled_ShowCHinese(3, 0, "Close");
else if(motor_pwm == 300)
Oled_ShowCHinese(3, 0, "First gear");
else if(motor_pwm == 600)
Oled_ShowCHinese(3, 0, "Second gear");
else if(motor_pwm == 900)
Oled_ShowCHinese(3, 0, "third gear");

if(flag_direction == 1)
Oled_ShowCHinese(3, 5, "Shake your head");
else
Oled_ShowCHinese(3, 5, "Shaking head off");

sprintf(display_buf,"%d%d:%d%d:%d%d",countdown_hour/10,countdown_hour ,countdown_minute/10,countdown_minute ,countdown_second/10,countdown_second );
Oled_ShowString(4,0,display_buf);

if(flag_mode == 0)
Oled_ShowCHinese(4, 5, "automatic");
else
Oled_ShowCHinese(4, 5, "Manual");
break;

case 1: //Interface 1: Display the maximum value of the set temperature
Oled_ShowCHinese(1,0,"Set the maximum temperature value");
if(time_num % 5 == 0)
{<!-- -->
sprintf(display_buf,"%d ",temp_max);
Oled_ShowString(2, 6, display_buf);
}
if(time_num % 10 == 0)
{<!-- -->
Oled_ShowString(2, 6, " ");
}
break;

case 2: //Interface 2: Display the minimum value of the set temperature
Oled_ShowCHinese(1,0,"Set the minimum temperature value");
if(time_num % 5 == 0)
{<!-- -->
sprintf(display_buf,"%d ",temp_min);
Oled_ShowString(2, 6, display_buf);
}
if(time_num % 10 == 0)
{<!-- -->
Oled_ShowString(2, 6, " ");
}
break;

case 3: //Interface 3: display setting countdown
Oled_ShowCHinese(1,1,"Set countdown");
if(time_num % 5 == 0)
{<!-- -->
sprintf(display_buf,"%d%d:%d%d:%d%d",countdown_hour/10,countdown_hour ,countdown_minute/10,countdown_minute ,countdown_second/10,countdown_second );
Oled_ShowString(2,4,display_buf);
}
if(time_num % 10 == 0)
{<!-- -->
Oled_ShowString(2,4," ");
}
break;

case 4: //Interface 4: Display setting countdown minutes
Oled_ShowCHinese(1,1,"Set countdown minutes");
if(time_num % 5 == 0)
{<!-- -->
sprintf(display_buf,"%d%d:%d%d:%d%d",countdown_hour/10,countdown_hour ,countdown_minute/10,countdown_minute ,countdown_second/10,countdown_second );
Oled_ShowString(2,4,display_buf);
}
if(time_num % 10 == 0)
{<!-- -->
Oled_ShowString(2,7," ");
}
break;

case 5: //Interface 5: Display setting countdown seconds
Oled_ShowCHinese(1,1,"Set countdown seconds");
if(time_num % 5 == 0)
{<!-- -->
sprintf(display_buf,"%d%d:%d%d:%d%d",countdown_hour/10,countdown_hour ,countdown_minute/10,countdown_minute ,countdown_second/10,countdown_second );
Oled_ShowString(2,4,display_buf);
}
if(time_num % 10 == 0)
{<!-- -->
Oled_ShowString(2,10," ");
}
break;

default:
break;
}
}

/****
*******Handling function
*****/
void Manage_function(void)
{<!-- -->
if(flag_display == 0) //Measurement interface
{<!-- -->
if(flag_mode == 0) //In automatic mode, (when there is someone, the temperature is three gears higher than the maximum value, two gears higher than the median value, and one gear higher than the minimum value, otherwise it is closed)
{<!-- -->
if((temp_value > temp_max*10) & amp; & HUMAN == 0)
{<!-- -->
motor_pwm = 900;
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
else if((temp_value > ((temp_max + temp_min)/2)*10) & amp; & HUMAN == 0)
{<!-- -->
motor_pwm = 600;
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
else if((temp_value > temp_min*10) & amp; & HUMAN == 0)
{<!-- -->
motor_pwm = 300;
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
else
{<!-- -->
motor_pwm = 0;
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
}
    if(countdown_hour != 0 || countdown_minute != 0 || countdown_second != 0) //Ventilation countdown is not 0
      flag_countdown_begin = 1; //Start countdown and enter timer interrupt
    
    if(flag_1s == 1) //1s arrives
    {<!-- -->
      flag_1s = 0;
      if(countdown_second > 0) //Countdown seconds > 0
        countdown_second--; //Countdown seconds-1
      else //Countdown seconds=0
      {<!-- -->
        if(countdown_minute > 0) //If countdown minute > 0
        {<!-- -->
          countdown_minute--; //Countdown minute-1
          countdown_second = 59; //Countdown seconds = 59
        }
        else //if countdown minutes=0
        {<!-- -->
          if(countdown_hour > 0) //If the countdown is >0
          {<!-- -->
            countdown_hour--; //Countdown time -1
            countdown_minute = 59; //Countdown minutes = 59
            countdown_second = 59; //Countdown seconds = 59
          }
          else //If countdown=0, countdown ends
          {<!-- -->
            flag_countdown_begin = 0;
            flag_countdown_end = 1;
          }
        }
      }
    }
    if(flag_countdown_end == 1) //The countdown is over, turn off the fan and enter manual mode
    {<!-- -->
      flag_countdown_end = 0;
      motor_pwm = 0;
      TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
      flag_mode = 1;
    }
if(motor_pwm == 0)
flag_direction = 0;
if(flag_direction == 1) //If in the shaking mode, the stepper motor shakes the head
{<!-- -->
if(flag_Step2 == 0)
{<!-- -->
flag_step2_o = 1;
flag_step2_c = 0;
}
else
{<!-- -->
flag_step2_o = 0;
flag_step2_c = 1;
}
}
else
{<!-- -->
flag_step2_o = 0;
flag_step2_c = 0;
}
}
else //Set the interface and turn off the fan
{<!-- -->
flag_countdown_begin = 0;
flag_direction = 0;
flag_step2_o = 0;
flag_step2_c = 0;
motor_pwm = 0;
TIM_SetCompare1(MOTOR_DIANJI_TIM,motor_pwm);
}
}