0% found this document useful (0 votes)
39 views

GSM Code

The document describes code for an Arduino project that monitors temperature using a GSM module. It initializes the LCD and GSM module, checks for over temperature, and sends an SMS alert with the reading if triggered.

Uploaded by

Edward Lloyd
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

GSM Code

The document describes code for an Arduino project that monitors temperature using a GSM module. It initializes the LCD and GSM module, checks for over temperature, and sends an SMS alert with the reading if triggered.

Uploaded by

Edward Lloyd
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

# include<reg52.

h> #define lcd_data P2 #define lcd_cont() ((lcd_en=1),(delay(3)),(lcd_en=0)) void UART_init(); void send_to_modem(char*); void enter(); void send(char); void ch_send_to_modem(char*); void lcd_init(void); void lcdcmd(unsigned char value); void lcddata(unsigned char value); void msgdisplay(unsigned char b[]); void delay(unsigned int value); void send_to_modem(char*); void enter(); void send(char); void ch_send_to_modem(char*); unsigned char str[10],mobilenum[11]={"09887081656"}; unsigned char mobilenum1[10]; code unsigned char str1[]={"OK"}; unsigned char l,s,n,a,b,i,count,j,jjj,hb=68; sbit temp=P1^3; sbit lcd_rs = P1^0; sbit lcd_en = P1^2; void main() { temp=1; lcd_init(); UART_init(); lcdcmd(0x84); msgdisplay(" welcome " ); delay(1000); lcdcmd(0x01); msgdisplay("searching for"); lcdcmd(0xc0); msgdisplay("GSM modem"); delay(100); send_to_modem("ate0"); //to avoid echo signals, enter(); send_to_modem("at"); enter(); // TO CHECKING GSM MODEM... send_to_modem("at"); enter(); send_to_modem("at"); enter(); send_to_modem("at"); enter(); send_to_modem("at\r"); enter(); for(mobilenum[i]=0;mobilenum[i]<11;i++); for(s=0;s<5;s++) { // to checking wether the GSM modem connected to system or while(RI==0); // not. str[s]=SBUF; RI=0;

} /* str[s]='\0'; lcdcmd(0x01); msgdisplay1(str); long_delay(); n=strcmp(str3,str1); if(n) goto again; // GSM modem if those are matching then following messages else {*/ // are displaying on LCD. lcdcmd(0x01); msgdisplay("SYSTEM"); lcdcmd(0xc3); msgdisplay("CONNECTED"); // } send_to_modem("at+cmgf=1"); enter(); send_to_modem("at+cmgd=1"); enter(); send_to_modem("at+cmgd=2"); enter(); send_to_modem("at+cmgd=3"); enter(); send_to_modem("at+cfcs="); enter(); send_to_modem("gsm"); enter(); RI=0; lcdcmd(0x01); msgdisplay(mobilenum);

st:delay(2500); while(RI==1) { RI=0; delay(100); } lcdcmd(0x01); msgdisplay("massage "); lcdcmd(0xc0); msgdisplay("start......"); while(RI==1);

while(1) { if(temp==0) {

resend: lcdcmd(0x01); msgdisplay("over temp"); lcdcmd(0xc3); msgdisplay("sending msg"); send_to_modem("at+cmgs=+918233598587"); lcdcmd(0x01); msgdisplay("No. sended"); lcdcmd(0xc0); msgdisplay("sending msg...."); delay(10); enter(); send_to_modem("abnormal temerature from room1 "); ch_send_to_modem(0x1a); enter(); while(RI==0); a=SBUF; RI=0; while(RI==0); b=SBUF; RI=0; if(a==13) { lcdcmd(0x01); msgdisplay("message sent "); goto st; } else { delay(2000); goto resend; } } } } void lcd_init(void) { lcdcmd(0x02); lcdcmd(0x02); lcdcmd(0x02); lcdcmd(0x28); lcdcmd(0x28); lcdcmd(0x28); lcdcmd(0x0c); lcdcmd(0x06); lcdcmd(0x01); } void lcdcmd(unsigned char value) // LCD COMMAND { lcd_data=value&(0xf0); lcd_rs=0; lcd_cont(); lcd_data=((value<<4)&(0xf0)); lcd_rs=0; lcd_cont(); }

void lcddata(unsigned char value) { lcd_data=value&(0xf0); lcd_rs=1; lcd_cont(); delay(3); lcd_data=((value<<4)&(0xf0)); lcd_rs=1; lcd_cont(); delay(3); } void msgdisplay(unsigned char b[]) { unsigned char s,count=0; for(s=0;b[s]!='\0';s++) { lcddata(b[s]); } } void delay(unsigned int value) { unsigned int x,y; for(x=0;x<100;x++) for(y=0;y<value;y++); } void UART_init() { SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TR1 = 1; } void send_to_modem(char*s) { while(*s != '\0') { send(*s); s++; } } void ch_send_to_modem(char*s) { while(*s != '\0') { send(*s); s++; } send('\r'); send('\n'); } void send(char x) { while(!TI);

TI = 0; SBUF=x; } void enter() { send('\r'); send('\n'); }

You might also like