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