Heat controlled fan

A fan that will be mounted in a ventilation hole. If the temperature rises over a limit the fan will start and run until the temperature is under a certain point. Although the fan is extremely quiet a LDR is used to keep the fan quiet at night.

Status: Has been running without problems for two years. The fan is so quit and nights can be hot so the LDR is not used.


Code (for mikroC):

#define fan GPIO.GP5

int potTemp, potTime, light, temp;

long int delayTime;

void main() {


OPTION_REG = 0b11010000; //GPIO pullup and TMR0 setup


TRISIO = 0b00010111;

//A/D. Fosc/2, AN<3:0> activated.

ANSEL = 0b00001111;

//ADCON0. 0 (ADFM), 0 (Vref=VDD),00 (dont care),10 (channel select, chan 02),0 (Go/Done), 1 (AD is on)

ADCON0 = 0b00001101;

fan = 1;

do{ // Loop

potTime = Adc_Read(0); //Left pot AN0, pin7

potTemp = Adc_Read(1); //Right pot AN1, pin6

//light = Adc_Read(2); //LDR

temp = Adc_Read(3); //TC1047


The temp potentiometer can have values from 0-5V, ie 0-1023 (10-bit A/D).


temp = temp - 140;

temp = temp * 50;

if (temp > potTemp) {

fan = 1;


if (temp < potTemp) {

fan = 0;


//Wait a second

delayTime = potTime * 3000;

Vdelay_ms (delayTime);

} while(1);