Uno+GSM shield+PIR sensor not sending text

Hello. I am new to GSM as well as writing code. I created a similar project using two Uno boards+RF modules+PIR sensor to activate an LED & buzzer when the PIR sensor detected motion. Now I'm trying to create a similar project using a Uno+GSM shield+PIR sensor to send a text message to my phone when motion is detected by the sensor. I successfully sent and received texts between the board and phone via serial monitor, so I know the shield is working properly. But the code that I am using is not working:

#include <GSM.h>
#include <SIM900.h>
#include <sms.h>
#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8); // RX, TX pins

void setup() {


  pinMode(5, INPUT); // Our PIR sensor
  Serial.begin(9600); // Open serial connection at baud rate of 9600

}

void loop(){

  if (digitalRead(5) == HIGH){ // PIR sensor detects motion
    digitalWrite(13, HIGH); // Turn LED on.
    Serial.println("AT"); // Sends AT command to wake up gsm shield
    delay(500);
    Serial.println("AT+CMGF=1"); // Puts gsm shield into SMS mode
    delay(1000); // Wait a second
    Serial.println("AT+CMGS=\"+1xxxxxxxxxx\""); // YOUR NUMBER HERE; Creates new message to number
    delay(1000);
    Serial.print("Motion Detected."); // Message contents
    delay(1000);
    Serial.write(byte(26)); // (signals end of message)
    delay(1000);
    Serial.println("AT+CMSS=1"); // Sends message at index of 1
    digitalWrite(13, LOW); // Turn LED off
    delay(250);
    digitalWrite(13, HIGH); // Turn LED on.
    delay(10000); // Give the gsm shield time to send the SMS
    Serial.println("AT+CMGD=1"); // Deletes message at index of 1
    digitalWrite(13, LOW); // Turn LED off.
    delay(250);
  }

}

When the sensor detects motion, the green transmit light on the shield does not flash indicating that it is transmitting the text. The board is powered by the A/C adaptor. Am I using/missing the correct libraries? Wrong pins? Wrong AT commands? Or is my code completely wrong? I have tried for four days trying to figure this out but GSM is new to me, and any help would be appreciated. Thanks in advance.

Every AT command is supposed to return a response. Reading them is generally a good idea. Now, how you are going to display them when you are using the Serial instance to talk to the phone is a mystery. I'd recommend not doing that.

So I'm going about this all wrong then, huh? :blush: I don't need a return response. Basically, I just need a one-way transmission/text from the Uno/GSM shield to the phone when the sensor detects motion. I have been searching for a similar project to help point me in the right direction but everything I've found uses serial communication. That's why I wrote my failed code with serial instance. Which library(s) should I work with? Thanks.

I don't need a return response.

OK. Since you are CERTAIN that every AT command is being accepted, is formatted correctly, etc., what is the problem?

At least during development, I'd read the response, to make sure each command worked before sending another one. YMMV.

Try putting carriage returns where you would normally hit the enter key. For example, making a call through the serial monitor would be
ATD+1xxxxxxxxxx;
You would want to put
"ATD+1xxxxxxxxxx;\r"

Also, you should be using the Software serial you created (GPRS). Like this:

GPRS.write ("AT+CMGS="+1xxxxxxxxxx"\r");
delay (100);
GPRS.write ("Your text goes here\r");

and so on. This is posted from mobile. If you still need help, I can be of better assistance at home.

You would want to put
"ATD+1xxxxxxxxxx;/r"

Of course,
"ATD+1xxxxxxxxxx;\r"
would work better.

PaulS:

You would want to put
"ATD+1xxxxxxxxxx;/r"

Of course,
"ATD+1xxxxxxxxxx;\r"
would work better.

Right you are, sir! :sweat_smile: