This project gives you a simple temperature controlled fan. If the difference between real temperature and the user temperature is high then the fan will run at full speed and if the difference is low then the fan will rotate at slow speed. The speed of the fan varies with the temperature.
The user can enter the temperature limit through the keypad.
The speed of the fan is adjusted by using the PWM.
Circuit Diagram
Bascom Code:
ββββββββββββmainββββββββββββββ-
$regfile = βm16def.datβ
$crystal = 1000000
βββββββββββ-lcdβββββββββββββββ
βrs=pinb.6,e=pinb.0,db4=pinb.2,db5=pinb.3,db6=pinb.4,db7=pinb.5
Config Lcd = 16 * 2
Config Lcdpin = Pin , Rs = Pinb.0 , E = Pinb.1 , Db4 = Pinb.2 , Db5 = Pinb.3 , Db6 = Pinb.4 , Db7 = Pinb.5
βββββββββββ-key boardβββββββββββββ
Config Kbd = Portc
βUse the following code to disable JTAG
Mcusr = &H80
Mcusr = &H80
ββββββββββββpwmβββββββββββββββ
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Down , Prescale = 1
Start Timer1
ββββββββββββdimββββββββββββββ-
βa,bΒ for keyboard, c for chek , d for pwm
Dim A As Word , B As Word , C As Word , D As Word , Tanzim As Byte , E As Byte
Dim Lop As Byte
Dim Dama As Byte , Lm35 As Word , Motor As Word
ββββββββββββadcββββββββββββββ-
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
ββββββββββββmainββββββββββββββ
Config Pind.4 = Output
Config Pind.5 = Output
βββββββββββββββββββββββββββ
A = 0
B = 0
Cursor Off
Cls
Locate 1 , 5
Lcd βHelloβ
Wait 2
Cls
Main:
Locate 1 , 1
Lcd βIntern numberΒ Β Β β
Locate 2 , 1
Lcd βΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β β
Compare1a = 1
Compare1b = 1
Rool:
A = Getkbd()
If A = 16 Then Goto Rool
A = A + 1
Select Case A :
Case 1 To 3:
Case 4:
Cls
Lcd βf1β
Goto Rool
Case 5 To 7 :
A = A β 1
Case 8:
Cls
Lcd βf2β
Goto Rool
Case 9 To 11:
A = A β 2
Case 12:
Cls
Lcd βf3β
Goto Rool
Case 13:
Cls
Lcd βstartβ
Wait 1
Goto Lm35
Case 14:
A = 0
Case 15:
B = 0
A = 0
Cls
Goto Main
Case 16:
Cls
Lcd βf4β
Goto Rool
End Select
Tanzim3:
B = B * 10
A = A + B
B = A
Cls
Locate 1 , 1
Lcd B ; βΒ Β Β Β Β Β Β Β Β β
Locate 2 , 1
Lcd βpush start setβ
Lop:
Lop = Getkbd()
If Lop <> 16 Then Goto Lop
Goto Rool
βββββββββββββββββββββββββββ-
Lm35:
Lm35 = Getadc(0)
Waitms 10
Lm35 = Lm35 / 2
A = Getkbd()
A = A + 1
If A = 15 Then Goto Stops
Locate 1 , 1
Lcd βTEMPERATURE= β ; Lm35 ; βcΒ β
If Lm35 =< B Then
Compare1a = 1
Compare1b = 1
Motor = 0
Locate 2 , 1
Lcd βSet=β ; B ; βΒ pwm=β ; Motor ; βΒ Β Β Β Β Β Β Β Β Β Β Β β
Goto Lm35
End If
If Lm35 > B Then
D = Lm35 β B
Gosub Motor1
End If
Goto Lm35
Motor1:
Motor = D * 100
Motor = Motor + 50
If Motor > 1022 Then
Motor = 1023
Locate 2 , 1
Lcd βSet=β ; B ; βΒ pwm=fastΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β β
End If
If Motor =< 1022 Then
Locate 2 , 1
Lcd βSet=β ; B ; βΒ pwm=β ; Motor ; βΒ Β Β Β Β Β Β Β Β Β Β Β β
End If
Compare1a = Motor
Compare1b = Motor
For more Detail: Temperature controlled fan using PWM microcontroller