Microcontroller › Arduino › GSM900A-Having problem with programming
- This topic has 1 reply, 1 voice, and was last updated 7 years ago by
Aryan.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
February 28, 2016 at 6:24 pm #4329
Aryan
ParticipantI am doing a project in which i need that when i send a particuar msg from my phone to gsm module should return a specific message.
My variable nam shows that it is equal to "status" in serial monitor, but fail to send me a msg . You can see the code below,pls help if you can . Thanks in advance.
int temp4=0;int lenth,lenth1,i=0,temp=0;String str="";String nam="";String number="";String m="Status";void setup() {Serial3.begin(9600);Serial.begin(9600);Serial3.println("AT+CNMI=2,2,0,0,0");Serial3.println("AT+CMGF=1");delay(1000);}void loop(){while(temp!=0){i=0;while(i<lenth){if(str=='"'){temp4++;}if(temp4==1){for(int j=0;j<15;j++){number+=str;i++;}temp4=2;}if(str=='*'){i++;while(str!='#'){nam+=str;i++;}}i++;}Serial.print(nam);if (nam==m){delay(1000);Serial3.println("AT+CMGF=1");Serial3.println("AT+CMGS="+919463617625"r");Serial3.println("I am SMS from GSM Module");Serial3.println((char)26);}delay(2000);temp=0;temp4=0;nam="";lenth=0;str="";number="";delay(1000);}}void serialEvent3(){while (Serial3.available()){char inChar = (char)Serial3.read();str+=inChar;lenth++;if (inChar == 'n'){ temp=1;inChar=0;}}}March 1, 2016 at 11:50 am #13739Aryan
ParticipantWell after a long time troubleshooting i found that problem was that i was not using delay function after AT commands.
Working code enjoy
#include<String.h>int temp4=0;int lenth,lenth1,i=0,temp=0;String str="";String nam="";String number="";String m="Status";void setup() {pinMode (9,OUTPUT);Serial3.begin(9600);Serial.begin(9600);Serial3.println("AT+CNMI=2,2,0,0,0");Serial3.println("AT+CMGF=1");delay(100);if (Serial3.available()>0)Serial.write(Serial3.read());}void loop(){while(temp!=0){i=0;while(i<lenth){if(str=='"'){temp4++;}if(temp4==1){for(int j=0;j<15;j++){number+=str;i++;}temp4=2;}if(str=='*'){i++;while(str!='#'){nam+=str;i++;}}i++;}Serial.print(nam);if (nam.compareTo(m)==0){SendMessage();}delay(2000);temp=0;temp4=0;nam="";lenth=0;str="";number="";delay(1000);}}void serialEvent3(){while (Serial3.available()){char inChar = (char)Serial3.read();str+=inChar;lenth++;if (inChar == 'n'){ temp=1;inChar=0;}}}void SendMessage(){digitalWrite(9,HIGH);Serial3.println("AT+CMGF=1"); //Sets the GSM Module in Text Modedelay(1000); // Delay of 1000 milli seconds or 1 secondSerial3.println("AT+CMGS="+918557803648"r"); // Replace x with mobile numberdelay(1000);Serial3.println("I am SMS from GSM Module");// The SMS text you want to senddelay(100);Serial3.println((char)26);// ASCII code of CTRL+Zdelay(100);} -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.