Forums MikroC Pro for PIC Project Discussions temperature controlled fan Reply To: temperature controlled fan

#3053

co6alt
Participant

hello sir/mam. thank you so much for replying. so i did update the code a little bit and i managed to fix some errors but now im stuck with two problems. firstly the lm35 sensor is just displaying the same value of the potentiometer with .10 extra i still havent figured out why. the second problem is that the fan is still not working with me even though the desired temperature is .10 less than the sensor as the lcd displays.

here is the updated code:

sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;

sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections

//variables
char Txt[7],Txt2[7];
float Temp_Ref ;
unsigned int temp,temp2;
float mV, ActualTemp;
unsigned char inTemp;
//end variables
void main() {
//configuration
TRISA=0xff;
TRISD=0;
ansel=0x03;
anselh=0x00;
//end configuration
// lcd part 1
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 4, “Automatic”);
Lcd_Out(2, 2, “Temp Control”);
delay_ms(1000);
//end lcd part 1

// fan off
portd.f0=0;
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
// ADC
temp = ADC_Read(0);
temp2 = ADC_Read(1);
mV = temp * 5000.0/1024.0;
temp2 = temp2 * 5000.0/1024.0;
ActualTemp = mV/10.0 ;
Temp_Ref=temp2/10.0 ;
//end ADC
Lcd_Out(1, 1, “Enter Temp:”);
FloatToStr( Temp_Ref,Txt);
Lcd_Out(1,12,Txt);
Lcd_Chr(1,15,223);
Lcd_Chr(1,16,’C’);
Delay_ms(1000);
Lcd_Out(2, 1, “Temp= “);
FloatToStr(ActualTemp,Txt2);
//Txt[4] = 0;
Lcd_Out(2,7,Txt2);
Lcd_Out(2,12,” “);

if (Temp_Ref > ActualTemp){portd.f0=0;}
if (Temp_Ref < ActualTemp){portd.f0=1;}
if (Temp_Ref == ActualTemp){portd.f0=0;}

Delay_ms(2000);
}

}

 

i hope the code answers your questions. And no i didnt see the videos yet however i will do so and try to fix it. thank you again.