100% found this document useful (2 votes)
1K views8 pages

Temperature Controlled Fan Using PIC 16F877A - Gadgetronicx

This document describes a temperature controlled fan system using a PIC 16F877A microcontroller. The system uses an LM35 temperature sensor to measure the external temperature. The temperature reading is fed to the microcontroller's analog-to-digital converter to obtain a digital value. Based on the temperature range, the microcontroller controls the speed of a DC motor connected to a fan using pulse-width modulation. The motor speed increases with rising temperature to maintain temperature, and decreases with falling temperature. The code written for the microcontroller implements the temperature measurement and motor speed control via PWM.

Uploaded by

devchandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
1K views8 pages

Temperature Controlled Fan Using PIC 16F877A - Gadgetronicx

This document describes a temperature controlled fan system using a PIC 16F877A microcontroller. The system uses an LM35 temperature sensor to measure the external temperature. The temperature reading is fed to the microcontroller's analog-to-digital converter to obtain a digital value. Based on the temperature range, the microcontroller controls the speed of a DC motor connected to a fan using pulse-width modulation. The motor speed increases with rising temperature to maintain temperature, and decreases with falling temperature. The code written for the microcontroller implements the temperature measurement and motor speed control via PWM.

Uploaded by

devchandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

TemperaturecontrolledfanusingPIC16F877A
Gadgetronicx>Microcontroller>PIC>PICProjects>TemperaturecontrolledfanusingPIC16F877A

l FrankDonald } September18,2014 v 36Comments

m PICProjects dcmotor

TemperatureControlledDCmotor

Youmighthavecomeacrossseveralapplicationswhereweneedtocontrolaspecificdevicebasedonanalogparameter.This
Embedded system works in a similar concept where we are about to control the speed of a DC motor using based on the
external temperature. The rise in temperature will result in increase in speed of the motor and vice versa. These type of
Temperaturecontrolledfansystemscangenerallybeusedtomaintaintemperatureofaroomorobjectautomatically.

DESIGNOFTEMPERATURECONTROLLEDFANSYSTEM:
ThetemperatureismeasuredbymeansofatemperaturesensorLM35.
TheoutputvoltageofthesensorisfedtotheA/DchanneloftheMicrocontroller.
BasedonthesensedtemperaturethespeedofthemotoriscontrolledusingPWM.
Severaltemperaturerangeswassetinthecodetovarythemotorspeedbasedontheleveloftemperaturesensed.
ThespeedofthemotoriscontrolledbyusingPWM.

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 1/8
8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

ThemotorisdrivenusingadriverICl293D,Seeabriefexplanationonitsworkingandwiringhere.

LM35:

LM35PinDiagram

Lm35isusedtosensetheexternaltemperaturewhichiscapableofsensingtemperaturerangesfrom55to150C.Theoutput
voltageisproportionaltothetemperaturehencethereisnoneedoftrimmerstocalibratethereading.Theoutputvoltageofthis
sensorvariesby10mvperdegreechangeintemperature.

CALIBRATION:
Weareusinga10bitADCandVccasVreftotheADCmoduleoftheController.Soinordertodeterminethestepsizewehave
todividetheVrefbyourresolutionthatis2^10(1024).

StepSize=5/1024=4.83mV

Weobtainachangeof10mVwitheachriseorfallintemperaturefromthesensor.AndvalueintheADCregisterwillalterby
twostepswitheachdegreechangeinthesensorsincetwoincrementsofstepsizei.e4.833mV*2=9.96mVwhichis
approximatelyequalto10mV.SoinordertoobtaintheoriginalvaluewehavetodividethecontentsintheADCregisterby2

Realvalue=ADCvalue/2

CODE:
ThiscodewasbuiltusingCCScompilerforPICMicrocontrollers.

01. #include<16F877A.h>
02. #deviceADC=10//SettingADCbits
03. #FUSESNOWDT
04. #FUSESNOBROWNOUT
05. #FUSESNOLVP
06. #usedelay(crystal=20000000)

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 2/8
8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

07. #bytelcd=0x08
08. #byteTRIS_lcd=0x88
09. #bitrs=0x06.2
10. #biten=0x06.3
11. #bitTRIS_rs=0x86.2
12. #bitTRIS_en=0x86.3
13. longintadc_value,real_value
14. inti
15. charvalue[4]
16. unsignedchartext[]="Temperature:"
17. voiddisplay(unsignedchara,intb)
18. voidmotor()
19. voidmain()
20. {
21. TRIS_lcd=TRIS_rs=TRIS_en=0
22. display(0x38,0)
23. display(0x01,0)
24. display(0x0c,0)
25. for(i=0i<=12i++)
26. {
27. display(text[i],1)
28. }
29. setup_timer_2(T2_DIV_BY_16,255,1)//SettingtimersforPWM
30. SETUP_ADC_PORTS(AN0)//SettingADCPORTS
31. SET_ADC_CHANNEL(0)//SelectingChannel
32. SETUP_ADC(ADC_CLOCK_INTERNAL)
33. while(TRUE)
34. {
35. delay_us(20)
36. adc_value=READ_ADC()//ReadingADCvalue
37. delay_us(10)
38. real_value=adc_value/2//Obtainingrealvalue
39. motor()
40. sprintf(value,"%lu",real_value)//Changinginttochar
41. display(0x8c,0)
42. for(i=0i<=3i++)
43. {
44. display(value[i],1)
45. }
46. }
47. }
48. voiddisplay(unsignedchara,intb)//LCDsubroutine
49. {
50. lcd=a
51. rs=b
52. en=1
53. delay_ms(10)
54. en=0
55. delay_ms(10)
56. }
57.
58. voidmotor()
59. {
60. if(real_value<10)
61. {
62. setup_ccp1(CCP_OFF)
63. }

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 3/8
8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

64. if(real_value>10)
65. {
66. setup_ccp1(CCP_PWM)
67. if(real_value>=10&&real_value<=29)
68. {
69. set_pwm1_duty((int16)204)//20%dutycyclePWM
70. }
71. elseif(real_value>=30&&real_value<=69)
72. {
73. set_pwm1_duty((int16)510)//50%dutycyclePWM
74. }
75. elseif(real_value>=70&&real_value<=99)
76. {
77. set_pwm1_duty((int16)715)//70%dutycyclePWM
78. }
79. elseif(real_value>=100&&real_value<=150)
80. {
81. set_pwm1_duty((int16)919)//90%dutycyclePWM
82. }
83. }
84. }

The above code uses built in functions in the CCS compiler to use the A/D and PWM feature in the Microcontroller. The
receivedanalogvalueiscalibratedtodisplaythetemperatureintheLCD.Thereal_valueintvalueisconvertedtocharacter
usingsprintfinordertodisplaythetemperaturevalues.

ThetemperaturerangesanddutycycleofthePWMisgivenusingthesubroutine.motor.Sothemicrocontrollerrunsacheck
onthetemperatureeverytimeandaltersthespeedofthemotorbasedonit.

EasyEDA:FreeCircuitDesignTool&LowCostPCBPrototype
10pcs2layersonly$10,registertoget$5CashCoupon

SelectLanguageonEasyEDA
English()FrenchPortugueseSpanishThaiArabicDutch

HebrewVietnameseRussianItalianPolishAfrikaansPersianGerman

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 4/8
8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

RelatedDesignsandSchematics

Remotecontrolled Howtobuilda Weathermeterusing ElectronicCode


LEDlightingeffects Remotecontrol(RC) PIC16F877 lockingsystemusing
carathome Microcontroller PIC16F877Mi...

Bio LatestPosts

FrankDonald
JuniorNetworkEngineeratTataCommunications

FrankDonaldisanElectronicsandCommunicationEngineerwhoisverypassionate
abouthissubject.Reading,SurfingandBloggingarethethingsheloves.

Previouspost Nextpost

Askyourquery

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 5/8
8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

36Commentson"TemperaturecontrolledfanusingPIC16F877A"

Notifyof Notifyofallnewfollowupcomments Email

Jointhediscussion

Sortby:newest|oldest|mostvoted

Aytu 3months11daysago

Helloguys..
Guest
Ishouldconvertthiscodetohexfile.Anyonehavethisone?
Myemailaytugdemiregen@gmail.com

0 | ReplyShare

firdaus 3months20daysago

SIR..PLSHELP..INEEDTHEHEXFILE..IHAVINGPROBLEMWITHTHECODE..PLSSENDTOMY
Guest
EMAIL..mohdfirdaus007.mf@gmail.com

0 | ReplyShare

sean 4months14daysago

plsIneedthehexfile.amhavingproblemscompilingthecode.myemailistoscliff_2011@yahoo.com
Guest

0 | ReplyShare

sylvesterwalter 4months27daysago

whrecanigettheccscompiler..canugivemealink..cozicantfindthesametypeasyour
Guest

0 | ReplyShare

khalid 4months28daysago

howtoconfigtwovalueforvoltage5,12thatusedinL293Dthanks
Guest

0 | ReplyShare

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 6/8
8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

khalid 4months28daysago

whatisthe10KsymbolthatconnecttoVDDinLCDandhowtogetitfromproteus
Guest

0 | ReplyShare HideReplies

Hammad 2months26daysago

DearKhaliddidyou.Getyouranswer.
Guest

0 | ReplyShare

swami 5months5daysago

pleasesendmecompressedfileofthatproject
Guest

0 | ReplyShare

pat 5months16daysago

needtoaddlightingcontrolltocodeanyhelp
Guest

0 | ReplyShare

pat 5months16daysago

needtoaddlightinfcontrolltotheprojectsoitcancontrolthelntheroom
Guest

0 | ReplyShare HideReplies

FrankDonald 5months6daysago

Pat,
Author UseanLDRsensorandconnectittoanADCpinmeasureitsvoltageandwriteyourcontrolcondition
loopsbasedonthosevalues.

0 | ReplyShare

dave 6months26daysago

thanksalotthesimulationisworkingfine.plsiwouldliketochangethereferrencetemperaturefrom10to30
Guest degrees(whenceitwouldincreaseinitiallyby30%)andalsowantthespeedofthefantoincreaseby10%per
degreeafter40degrees.iknowthiseditionshouldbemadeontheprogrambutidontknowwhere.alsoplsif

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 7/8
8/21/2016 TemperaturecontrolledfanusingPIC16F877AGadgetronicx

itsnottoomuchtroublecanyouhelpmewithastepbystepexplanationofeachlineofthecodestartingfrom
theheaderfiles.

0 | ReplyShare

LoadMoreComments

http://www.gadgetronicx.com/temperaturecontrolledfanpic/ 8/8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy