EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Working code

Working code

|

Microcontroller › Arduino › GSM900A-Having problem with programming › Working code

March 1, 2016 at 11:50 am #13739
Aryan
Participant

Well 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 Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Serial3.println("AT+CMGS="+918557803648"r"); // Replace x with mobile number
  delay(1000);
  Serial3.println("I am SMS from GSM Module");// The SMS text you want to send
  delay(100);
   Serial3.println((char)26);// ASCII code of CTRL+Z
  delay(100);
}
 

RSS Recent Posts

  • using a RTC in SF basic May 20, 2025
  • Trail camera May 20, 2025
  • how to work on pcbs that are thick May 20, 2025
  • can a AT89C51 be used as a rom? May 20, 2025
  • Telegram Based Alarm - Sensor cable protection May 20, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise