Go Down

Topic: GSM keeps sending SMS (problem in Arduino code) (Read 506 times) previous topic - next topic

dogo1500

I have an Arduino Uno that is interfaced with GSM. I wrote a code which makes the GSM send SMS if it receives an SMS with letter ('s'). The problem is when the GSM received letter 's' it keeps sending multiple SMSs rather than one.
Anyone can solve this problem ??
Here is the code that I wrote it.


KASSIMSAMJI

use the code tags and post your code, not the image
Expert To Be: Machine Learning And Computer/Machine Vision (ML/CV/MV)

dogo1500

this is  the code

 #include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // Rx,Tx
String textMessage;
String message;

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(20000); // it should be 20000 to connect gsm to network
 
   Serial.print("SIM900 ready...");
delay(1000);
  // AT command to set SIM900 to SMS mode
  mySerial.print("AT+CMGF=1\r");
  delay(1000);
  // Set module to send SMS data to serial out upon receipt
  mySerial.print("AT+CNMI=2,2,0,0,0\r");
  delay(1000);

}

void loop()
{
if(mySerial.available()>0){
    textMessage = mySerial.readString();
    Serial.print(textMessage);   
    delay(1000);
     if(textMessage.indexOf("s")>=0){
      message= "led is on";
    SendMessage(message);
    delay(1000);
    textMessage = "";
}}}
 void SendMessage(String message)
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+966554942736\"\r"); // Replace x with mobile number
  delay(2000);
  mySerial.println(message);// The SMS text you want to send
  delay(2000);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(5000);
}

 

Go Up