Weather monitoring code

Dependencies:   TextLCD mbed

main.cpp

Committer:
nannanitinkumar
Date:
2013-10-26
Revision:
0:edc11adb58de

File content as of revision 0:edc11adb58de:

#include "mbed.h"
#include "TextLCD.h"
Serial GSM(p9, p10);  // tx, rx
char  z=0x1A,e=0x22;
char num1[] = "9742920934";
char num[] = "7406660316";
char c1[20]="Temp";
char c2[20]="Humidity";
char c3[20]="light";
char c4[20]="Moisture";
char c5[20]="Soil_Temp";
DigitalOut led1(p28);
DigitalOut led2(p27);

//char nun[] = "9739933223";
Serial pc(USBTX, USBRX); // tx, rx
TextLCD     lcd(p21, p22, p23, p24, p25,p26);
AnalogIn ain2(p19);//SM100
AnalogIn ain3(p20); //HS220
AnalogIn ain4(p18); //LM35
AnalogIn ain5(p16); //PT100
AnalogIn ain6(p17); //LDR
char time_stamp[16];//as our lcd is of 16 character it is so

int main() 
{
led2 = 0;
led1 = 1;
lcd.printf("  BMSCE_WSM  ");
    //GSM.printf("AT\r\n");
//wait(3);
    //GSM.printf("AT+CMGF=1\r\n");
wait(3);
//set_time(1361194897);

     while (1) 
    { 
    float a,b,a1,a2,a3,a4,a5,t1,t2,t3,t4,t5,vcc;
    vcc = 3.25;
     //   time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
       // strftime(time_stamp, 16, "%d%m%y%H%M%S", localtime(&seconds)); 
        //this converts the value in seconds obtained above to human readable format and assigns it to the timestamp 
       // lcd.locate(0,0);//start displaying from zeroth column,zeroth row
        //lcd.printf("%s",time_stamp);//diplays the human readable time
        a = vcc-(ain6 * vcc);
       t1 = 46000*a/(vcc-a);
        b = vcc-(ain5*3.2);
       t2 = 219*b/(3.257-b);
       t3 = ain4*vcc;
       t4 = ain3*vcc;
       t5 = ain2*4096;
       a1 = 6000000*(powf(t1,-1.287));//LDR
       a2 = (t2 - 102)/0.3707;//PT100
       a3 = (t3 * 100)+1;//LM35
       a4 = (30.274*t4)+0.0402;//HS220 
       a5 = 0.057 * t5 - 54.702;//SM100
       lcd.cls();
       lcd.locate(0,0);
       lcd.printf( "Light=%0.2fLUX", a1);
       lcd.locate(0,1 );
       lcd.printf( "Soil_T=%0.2fC", a2);
       wait(3);
       lcd.cls();
       lcd.locate(0,0);
       lcd.printf( "Temp= %0.2f C ", a3);
       lcd.locate( 0, 1 );
       lcd.printf( "SMois=%0.2f wc", a5);
       wait(3);
       lcd.cls();
       lcd.locate( 0, 0 );
       lcd.printf( "Humi=%0.2f %RH", a4);
      // pc.printf("%s",time_stamp);
       pc.printf("%f\r\n",a1);
       pc.printf("%f\r\n",a2);
       pc.printf("%f\r\n",a3);
       pc.printf("%f\r\n",a4);
       pc.printf("%f\r\n",a5);
       //GSM.printf("AT+CMGS=%c%s%c\r\n",e,num,e);
      //  wait(3);
        GSM.printf("AT\r\n");
        wait(3);
        GSM.printf("AT+CMGF=1\r\n");
        wait(3);
        GSM.printf("AT+CMGS=%c%s%c\r\n",e,num1,e);
        wait(3);
          
        GSM.printf("T%0.2f,H%0.2f,L%0.2f,P%0.2f@",a3,a4,a1,a5);
       

        /*GSM.printf("Degree=%0.2f\r\n",a3);
        GSM.printf("lumence=%0.2f\r\n",a1);
        GSM.printf("Humi=%0.2f\r\n",a4);
        GSM.printf("Soil_mois=%0.2f\r\n",a5);
        GSM.printf("Soil_temp=%0.2f",a2);*/
        
        GSM.printf("%c",z);
           wait(1);
        GSM.printf("AT+CMGS=%c%s%c\r\n",e,num,e);
         GSM.printf("Temp=%0.2f,Humi=%0.2f,Light=%0.2f,SMois=%0.2f,Soil_T=%0.2fC@",a3,a4,a1,a5,a2);
           GSM.printf("%c",z);
        wait(3);
        
     }
}