I am working on a module to send messages. I write the message on the serial monitor + phone number and I have to send the message to the line.

Question:

How to send messages through the SIM900A shield?

Problem: What am I doing wrong in my code? Because I do not get an error but it does not send the SMS using the shield.

Try:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7);
char msg;

void setup() {
  mySerial.begin(9600); // Setting the baud rate of GSM Module  
  Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}

void loop() {
  if (Serial.available()>0)
    switch(Serial.read()) {
      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=\"+XXXXXXXXX\"\r"); // mobile number
      delay(1000);
      mySerial.println("sim900a sms");// The SMS text you want to send
      delay(100);
      mySerial.println((char)26);// ASCII code of CTRL+Z
      delay(1000);
    }
  if (mySerial.available()>0) Serial.write(mySerial.read());
}

This is my shield This is my shield

Other try:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7);
char msg;

void setup() {
  mySerial.begin(9600);  // Setting the baud rate of GSM Module  
  Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}

void loop() {
  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=\"+XXXXXXXXX\"\r"); // mobile number
  delay(1000);
  mySerial.println("sim900a sms");// The SMS text you want to send
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}
  • 1
    And the question/problem is? – gre_gor Feb 14 at 16:14
  • There is still no question. – gre_gor Feb 14 at 21:21
  • now? help me please – R. Fernandez Feb 15 at 11:59

There was not really a question, but I do notice there is no case's in your switch statement..

example from here

// do something different depending on the range value:
  switch (range) {
    case 0:    // your hand is on the sensor
      Serial.println("dark");
      break;
    case 1:    // your hand is close to the sensor
      Serial.println("dim");
      break;
    case 2:    // your hand is a few inches from the sensor
      Serial.println("medium");
      break;
    case 3:    // your hand is nowhere near the sensor
      Serial.println("bright");
      break;
  }
  delay(1);        // delay in between reads for stability
  • a need send message to shield – R. Fernandez Feb 14 at 18:05
  • Are you wanted to send all those commands when ANY byte is received from Serial.read()? – Chad G Feb 14 at 19:03
  • the switch is to see if there is data or not in the serial, the question is. How to send an SMS with the shield? – R. Fernandez Feb 15 at 12:02
  • @R.Fernandez That's not how switch statement works. – gre_gor Feb 15 at 17:26
  • println() also adds a newline ( \n ) to the end of what you are sending, not sure if your module expects that or not, but you also have a return ( \r ) in one of your messages, need to check to see exactly what the module expects – Chad G Feb 15 at 17:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.