This program is about using a temperature sensor and displaying the temperature on the LCD screen. Not only that when the temperature drops below 25, but the heater is also turned on and the temperature rising above 25 leads to turning on the fan.

Dependencies:   mbed TextLCD TMP36

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 
00005 
00006 
00007 TextLCD lcd(PA_5, PA_6, PA_7, PB_6, PC_7, PA_9, TextLCD::LCD16x2);
00008 AnalogIn tmp36(PA_0);
00009 
00010 PwmOut motor(PA_8);
00011 
00012 
00013 
00014  
00015 int main()
00016 {
00017  
00018     while(1) {
00019         float voltage=3.3f*tmp36.read();
00020         float temperature=100.0f*voltage-50.0f;
00021         char buffer[14];
00022         
00023         sprintf(buffer,"Temp in C=%.2f ",temperature);
00024       
00025        
00026         lcd.locate(0,0);
00027         lcd.printf(buffer,0,0);
00028         float ain;
00029         ain =tmp36.read(); 
00030         printf("The temperature:",tmp36.read());
00031         if (temperature >=25){
00032         motor.write(.5f); // (ain);   
00033         }
00034         else if (temperature<25) {
00035             motor. write(.0f);  //period(0.0f);
00036             }
00037   
00038         
00039         
00040         
00041         wait(1.0);
00042         
00043         
00044     }
00045 }
00046 
00047