Temperature controlled fan using PWM microcontroller

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

Temperature controlled fan

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


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top