i am working on a embedded project using GSM SIM300.i am using Atmel at89s52, GSM module ,temperature sensor LM35.
Working of project- Temp sensor will sense the temperature and sent a message to my cell phone only if the temperature is above 30^c,,and if i sent a SMS to the cell phone(for eg-OK),the relay connected to the microcontroller should turn ON.My code is as follows-
#include<reg51.h> #include<stdio.h> #define MYDATA P1; sbit ALE=P2^4; sbit OE=P2^5; sbit SC=P2^6; sbit EOC=P2^7; sbit ADDR_A=P2^0; sbit ADDR_B=P2^1; sbit MOTOR=P2^2; unsigned char rx[20],msg[6]; unsigned char sensor1,adc1,r; void clear(void) { unsigned char r; for(r=0;r<100;r++) rx[r]=0x00; } void clear1(void) //user msg { unsigned char n; for(n=0;n<=5;n++) msg[n]=0x00; } void serialcomm() { TMOD=0x20; // Mode=2 TH1=0xfd; // 9600 baud SCON=0x50; // Serial mode=1 ,8-Bit data,1 Stop bit ,1 Start bit , Receiving on TR1=1; // Start timer } void delay(unsigned int value) { unsigned int i,j; for(i=0;i<value;i++) for(j=0;j<1275;j++); } void serial(unsigned char x) { SBUF=x; while(TI==0); TI=0; } void Send2Gsm(char *aaa) { while(*aaa!='\0') { serial(*aaa); aaa++; } } unsigned char convert(void) { unsigned char value; delay(1); ALE=1; delay(1); SC=1; delay(1); ALE=0; SC=0; while(EOC==1); while(EOC==0); OE=1; delay(1); value=MYDATA; OE=0; return(value); } void receive_data() interrupt 4 // Function to recieve data serialy from RS232 into uc { unsigned char r; rx[r]=SBUF; // Read sbuf RI=0; } void main() { char string1[10}; int temp; serialcomm(); Send2Gsm("AT\r\n"); delay(2); Send2Gsm("AT+CMGF=1\r\n"); delay(2); Send2Gsm("AT+CMGS= +918762357075\r\n"); delay(2); Send2Gsm("hello"); serial(0x1a); while(1) { ADDR_B=0; ADDR_A=0; sensor1=convert(); if(sensor1>60 ) { temp=(adc1*0.489); sprintf(string1,"%d",temp); delay(500); Send2Gsm("Temperature="); Send2Gsm(string1); Send2Gsm("*c"); delay(500); serial(0x1A); delay(500); IE=0x90; while(rx[r]=='?') { IE=0x00; //disable interrupt if(rx[0]=='*' && rx[1]=='O' && rx[2]=='N' ) { MOTOR=1; clear(); clear1(); } else if(rx[0]=='*' && rx[1]=='O' && rx[2]=='F') { MOTOR=0; clear(); clear1(); } } } } }
i am not getting output with this code.i am having doubt with the recieving sms to the gsm modem.can anyone point out the mistakes in my code ??
Modem communication is a dialogue. So yes, you should care about the responses even if this is just a school project. Caring about responses and return codes from function calls is the way you catch problems and can fix them, instead of wasting hours or days or weeks just wondering why some things doesn't work at all, or only works sometimes.
It's the responses from the modem that is the indication that you should go ahead with more communication with the modem. Or do you put plugs in your ears and just talk out in the air at home, and expect someone to listen and care what you are saying? If you do - does it really work?