A system to control fan speed according to temperature values.

Dependencies:   mbed-rtos mbed

Fork of Home_Monitoring_System by Saad Habach

main.cpp

Committer:
habusaq
Date:
2018-03-20
Revision:
4:bfc60dcb627a
Parent:
3:399fd9e24cea

File content as of revision 4:bfc60dcb627a:

#include "mbed.h"

AnalogIn temp(A0);
PwmOut control(D3);
Serial pc(USBTX, USBRX); 
Serial bt(PTC17, PTC16);



int main(void)
{
    float tempC;
    float tempF;
    int TempC;
    char c;

    
    
    pc.printf("\n\nProgram Started \r\n");
      
    //6.785503686
    
    while(1)
    {
        control.period(0.000000000000001);   //10 kHz
        tempC = (temp*6.786*10);
        tempF = (9.0*tempC)/5.0 + 32.0;
        TempC = tempC;
         if(bt.readable() > 0)
            c = bt.getc();
            
        if(pc.readable())
            bt.putc(pc.getc());


        pc.printf("Temperature is %.2f C %.2f F\n\r", tempC, tempF);
        
        wait(1);
        
       
        if(tempC > 28 || c == 's')
        {
            control.write(0.79);
            DigitalOut test2(D2, 1);
            DigitalOut test1(D4, 0);
           
            //LED red 
               
        }
            
         else if(tempC > 34 || c == 'f')
        {
            control.write(1);
            DigitalOut test1(D4, 1);
            DigitalOut test2(D2, 0);
           
            //LED green       
        }  
        
         else //(tempC < 28 || c == 'p')
        {
            DigitalOut test1(D4, 0);
            DigitalOut test2(D2, 0);
            control.write(0);
        }
        
        
    }
}