Temperature control fan design based on single-chip microcomputer

Collect and like, your attention is the motivation for my creation

Article directory

    • summary
  • 1. Overall system design
  • 2. Hardware design of each unit module
  • 3. Software design
    • 3.1 Program settings
    • Appendix 1: General circuit diagram
    • code
  • 4. Conclusion
  • 5. Article Table of Contents

Summary

This study analyzes and designs the temperature-controlled fan system. The microcontroller is its core component. Temperature information is obtained through the temperature sensor DS18B20 and input into the microcontroller. The microcontroller compares the temperature set by the system and sends out corresponding control signals through ULN2803. The fan system is controlled to dissipate heat to the components. At the same time, the speed of the fan system can be determined by judging the temperature difference between the set temperature and the collected temperature. An LED eight-segment digital tube is used to realize the temperature display function. Dynamically displays the current ambient temperature and set temperature, and the current temperature can be set through the keyboard buttons. The keyboard part can adjust the set temperature independently and the DS18B20 can measure the external ambient temperature, then record the ambient temperature and set temperature and display them continuously and in real time.

Keywords: microcontroller, DS18B20, temperature control, LED

1. Overall system design

The division of labor of the main components of this system is as follows: First, the temperature sensor is used to detect the ambient temperature and obtain digital information, and then input it into the microcontroller, thereby displaying two temperatures on the eight-segment digital tube, one is the ambient temperature, The second is the temperature preset by the system. Accurate to tenths and integer digits respectively. And by using the PWM pulse width modulation method, the motor speed changes as the ambient temperature changes. In addition, in order to adjust the preset temperature, two buttons are set to increase or decrease the preset temperature. The system operation flow chart is as follows:

Figure 1.1 System structure block diagram

2. Hardware design of each unit module

The main hardware of this design includes: ① Digital temperature sensor with discrete output model DS18B20; ② CMOS 8-bit microcontroller model AT89C52; ③ 5-bit LED packaged digital tube display ④ Fan DC motor; ⑤ Model ULN2803 driver. Other electronic components include: ① a variety of resistors with different resistance values; ② a variety of capacitors with different capacitances; ③ multiple crystal oscillators; ④ various voltage sources and current sources; ⑤ multiple buttons; ⑥ multiple DIPs switch.

3. Software design

3.1 Program Settings

The main program, DS18B20 initialization function, DS18B20 temperature conversion function, temperature reading function, keyboard scanning function, digital tube indication function, temperature function and fan engine control function can all be used and applied, aiming to control the relevant indicators of the electric fan. Under normal circumstances, the recovery of the DS18B20 program to the initial state can be controlled by the DS18B20 initialization function; the external environment temperature can be monitored and recorded in real time through the DS18B20 temperature conversion function; the temperature reading function is to read the data collected and recorded by the temperature conversion function. Obtain and convert these data and transmit them to the host; the function of the keyboard scanning function needs to be completed by completing the addition and subtraction of the original value of the set temperature; the processing of the relevant temperature data that is detected, collected, and recorded is separate. If the temperature processing function is not turned on, in addition, the change of the electric fan engine speed is also inseparable from the operation of the temperature processing function; whether the electric fan engine rotates and the level of the reading are based on the external temperature and the set temperature, plus the fan motor control function Take control.
The specific usage of this program is shown in Figure 3.1.1:

Figure 3.1.1 Main program flow chart

Appendix 1: General circuit diagram

Attached Figure 1 General circuit diagram

Program code

Appendix 2: Program code
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DQ=P1^7;
sbit key1=P1^3;
sbit key2=P1^4;
sbit dianji=P3^1;
float ff;
uint y3;
uchar shi,ge,xiaoshu,sheding=20,gaonum,dinum;
uchar code dispcode[]={<!-- --> //segment code
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tablel[]={<!-- --> //Segment code with decimal point
0xbf,0x86,0xdb,0xcf,
0xe6,0xed,0xfd,
0x87,0xff,0xef};
uchar dispbitcode[]={<!-- --> //bit selection
0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
uchar dispbuf[8]={<!-- -->0,0,0,0,0,0,0,0};
void Delay(uint num)//delay function
{<!-- -->
while( --num );
}
void digitalshow(uchar a4,uchar a3,uchar a2,uchar a1,uchar a0)
{<!-- -->
dispbuf[0]=a0;
dispbuf[1]=a1;
dispbuf[2]=a2;
dispbuf[3]=a3;
dispbuf[4]=a4;
\t
P2=0xff;
P0=dispcode[dispbuf[0]];
P2=dispbitcode[5];
Delay(1);

P2=0xff;
P0=dispcode[dispbuf[1]];
P2=dispbitcode[4];
Delay(1);

P2=0xff;
P0=dispcode[dispbuf[2]];
P2=dispbitcode[2];
Delay(1);

P2=0xff;
P0=tablel[dispbuf[3]];
P2=dispbitcode[1];
Delay(1);

P2=0xff;
P0=dispcode[dispbuf[4]];
P2=dispbitcode[0];
Delay(1);
}
void dmsec(uint count)
{<!-- -->
uint i; // 1ms delay
while(count--)
{<!-- -->
for(i=0;i<125;i + + ){<!-- -->}
}
}

void tmreset(void)
{<!-- -->
DQ=0;
Delay(90); // Accurate delay is greater than 480us
DQ=1;
Delay(4); // 90, 4 can change in a small range
}

void tmpre(void)
{<!-- -->
while(DQ);
while(~DQ);
Delay(4);
}

bit tmrbit(void)
{<!-- -->
uint i;
bit dat;
DQ=0;
i + + ; // i + + ;about 1us
DQ=1;
i + + ;
i + + ;
dat=DQ;
Delay(8);
return(dat);
}

uchar tmrbyte(void) //Read a bit
{<!-- -->
uchar i,j,dat;
dat=0;
for(i=1;i<=8;i + + )
{<!-- -->
j=tmrbit();
dat=(j<<7)|(dat>>1);
}
return(dat);
}

void tmwbyte(uchar dat) //Write a bit
{<!-- -->
uint i;
uchar j;
bit testb;
for(j=1;j<=8;j + + )
{<!-- -->
testb=dat &0x01;
dat=dat>>1; //Start from low bit
if(testb) // Write 1
{<!-- -->
DQ=0; // Pull low first
i + + ;
i + + ; // >1us
DQ=1;
Delay(4);
}
else // Write 0
{<!-- -->
DQ=0;
Delay(4);
DQ=1;
i + + ;
i + + ; // pull it higher again
}
}
}
void tmstart(void) //ds1820 starts conversion
{<!-- -->
dmsec(1);
    tmreset();
    tmpre();
    dmsec(1);
    tmwbyte(0xcc); // skip rom
    tmwbyte(0x44); // Conversion
}
uchar tmrtemp(void) //Read temperature
{<!-- -->
uchar a,b;
tmreset();
tmpre();
dmsec(1);
tmwbyte(0xcc); // skip rom
tmwbyte(0xbe); // Conversion
a=tmrbyte(); // LSB lower 8 bits
b=tmrbyte(); // MSB high 8 bits
y3=b;
y3<<=8;
y3=y3|a;
ff=y3*0.0625;
y3=ff*10 + 0.5;
return(y3);
}
void keyscan(void)
{<!-- -->
if(key1==0)
{<!-- -->
dmsec(5);
if(key1==0)
{<!-- -->
shedding + + ;
if(shedding==100)
shedding=20;
}
while(!key1);
}
else if(key2==0)
{<!-- -->
dmsec(5);
if(key2==0)
{<!-- -->
shedding--;
if(shedding==0)
shedding=20;
}
while(!key2);
}
}
void deal(uint tmp) //Temperature processing
{<!-- -->
if(tmp<=sheding)
{<!-- -->
gaonum=0;
dinum=4;
}
else if((tmp>sheding) & amp; & amp;(tmp<=(shedding + 5)))
{<!-- -->
gaonum=1;
dinum=3;
}
else if((tmp>(shedding + 5)) & amp; & amp;(tmp<=(shedding + 10)))
{<!-- -->
gaonum=2;
dinum=2;
}
else if((tmp>(shedding + 10)) & amp; & amp;(tmp<=(shedding + 15)))
{<!-- -->
gaonum=3;
dinum=1;
}
else
{<!-- -->
gaonum=4;
dinum=0;
}
}
void dianjik() //Motor control
{<!-- -->
 uchar q,i;
 for(q=0;q<dinum;q + + )
 {<!-- -->
  dianji=0;
  digitalshow(shi,ge,xiaoshu,sheding/10,sheding);
  for(i=255;i>0;i--)
  {<!-- -->
   digitalshow(shi,ge,xiaoshu,sheding/10,sheding);
  }
 }
 for(q=0;q<gaonum;q + + )
 {<!-- -->
  dianji=1;
  digitalshow(shi,ge,xiaoshu,sheding/10,sheding);
  for(i=255;i>0;i--)
  {<!-- -->
   digitalshow(shi,ge,xiaoshu,sheding/10,sheding);
  }
 }
}
void main(void)
 {<!-- -->
uint last;
dianji=0;
tmstart();
dmsec(450); //Initialize ds18b20
while(1)
{<!-- -->
tmstart(); // ds1820 starts conversion
dmsec(2);
last=tmrtemp() + 256; // read temperature
shi=last/100;
ge=(last 0)/10;
xiaoshu=(last 0);
keyscan();
dmsec(2);
deal(last/10);
dianjik();
}
}








4. Conclusion

This system uses a single-chip microcomputer as the core part, and uses the DS18B20 temperature sensor to measure the ambient temperature as the basis. The fan engine with different speeds can be combined as a whole, and the engine speed can be accelerated or slowed down by measuring changes in the external ambient temperature, and can be achieved within a certain range. Continuous regulation of rotational speed within temperature range. The LED digital tube can display the ambient temperature, and can maintain and stabilize the adjustment of different set temperatures of the digital tube through two independent buttons on the keyboard, which means that the temperature of the digital tube is fixed at different temperature difference levels. Changing the difference between the ambient temperature and the set temperature can further change the engine speed.
Understanding the engine speed design of this system can be applied to many engine control systems. It can be used in daily life, so that the intelligent fan can be used by consumers to provide convenience for life. In industrial production, in order to control the engine speed, different types of input signals can be changed to reduce the degree of production automation, production pressure and usage costs. The design and research of this system plays an important role in industrial production and daily life.

5. Article directory

Table of contents
Abstract I
Abstract II
Chapter 1 Overall Plan Design 1
1.1 Preface 1
1.2 Overall system design 1
1.3 Plan demonstration 2
1.3.1 Selection of temperature sensor 2
1.3.2 Control core selection 3
1.3.3 Selection of temperature display device 3
1.3.4 Selection of speed regulation method 3
Chapter 2 Hardware design of each unit module 5
2.1 Introduction to system components 5
2.1.1 Introduction to DS18B20 single-wire digital temperature sensor 5
2.1.2 Introduction to Darlington reverse driver ULN2803 5
2.1.3 Introduction to AT89C52 microcontroller 6
2.1.4 Introduction to LED digital tube 7
2.2 Circuit design of each part 8
2.2.1 Switch reset and crystal oscillator circuit 9
2.2.2 Independent keyboard connection circuit 9
2.2.3 Digital tube display circuit 10
2.2.4 Temperature acquisition circuit 11
2.2.5 Fan motor drive and speed regulation circuit 12
Chapter 3 Software Design 14
3.1 Program settings 14
3.2 Programming with Keil C51 14
3.3 Simulation with Proteus 15
3.3.1 Introduction to Proteus 15
3.3.2 This design is based on Proteus simulation 16
Chapter 4 System Debugging 21
4.1 Software Debugging 21
4.1.1 Debugging the button display part 21
4.1.2 Debugging of temperature acquisition part of sensor DS18B20 21
4.1.3 Debugging the motor speed control circuit part 21
4.2 Hardware debugging 22
4.2.1 Debugging of button display part 22
4.2.2 Debugging of temperature acquisition part of sensor DS18B20 22
4.2.3 Debugging of the motor speed regulating circuit 22
4.3 System functions 23
4.3.1 Functions implemented by the system 23
4.3.2 System function analysis 23
Conclusion 24
Reference 25
Acknowledgments 26
Appendix 1: General circuit diagram 27
Appendix 2: Program code 28