I am new to SIM900 module and my below code is modified from a tutorial and this forum Q&A. I had set the jumper to software serial selected. Unfortunately, my code is not sending out a sms.
Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
SIM900.begin(19200);
// For serial monitor
Serial.begin(19200);
// Give time to your GSM shield log on to network
delay(20000);
Serial.begin(9600);
if (SIM900.available())
{
Serial.println("SIM 900 is ready");
}
else
{
Serial.println("SIM 900 is not ready");
}
Serial.println("Sending message");
// Send the SMS
sendSMS();
}
void loop() {
}
void sendSMS() {
SIM900.println("AT");
String status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Sim responds = ");
Serial.print(status_code);
// AT command to set SIM900 to SMS mode
SIM900.print("AT+CMGF=1\r");
delay(100);
status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Sim responds = ");
Serial.print(status_code);
SIM900.print("AT+CMEE=1\r");
delay(100);
status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Sim responds = ");
Serial.print(status_code);
SIM900.print("AT+CSCS=\"GSM\"\r");
delay(100);
status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Sim responds = ");
Serial.print(status_code);
SIM900.print("AT+CSTA?\r");
delay(100);
status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Sim responds = ");
Serial.print(status_code);
SIM900.print("AT+CSQ\r");
delay(100);
status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Sim responds = ");
Serial.print(status_code);
SIM900.print("AT+CMGS=\"0194802873\"");
SIM900.print("\r");
delay(100);
status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Sim responds = ");
Serial.print(status_code);
SIM900.println("Message example from Arduino Uno.");
delay(100);
// End AT command with a ^Z, ASCII code 26
SIM900.println((char)26);
SIM900.print("\r\n"); // Send CRLF
delay(100);
SIM900.println();
// Give module time to send SMS
delay(5000);
Serial.println("Message sent");
}
The output is as follow:
11:44:27.523 -> SIM 900 is not ready
11:44:27.523 -> Sending message
11:44:28.563 -> Sim responds = AT
11:44:28.563 ->
11:44:28.563 -> OK
11:44:29.683 -> Sim responds = AT+CMGF=1
11:44:29.683 -> OK
11:44:30.803 -> Sim responds = AT+CMEE=1
11:44:30.803 -> OK
11:44:31.923 -> Sim responds = AT+CSCS="GSM"
11:44:31.923 -> OK
11:44:33.003 -> Sim responds = AT+CSTA?
11:44:33.003 -> +CSTA: 129
11:44:33.043 ->
11:44:33.043 -> OK
11:44:34.123 -> Sim responds = AT+CSQ
11:44:34.123 -> +CSQ: 18,0
11:44:34.123 ->
11:44:34.123 -> OK
11:44:35.243 -> Sim responds = AT+CMGS="0194802873"
11:44:35.243 -> > Message sent
what did I make wrong in the above code? if you spot my errors, please point out my errors. Thank you in advance.
Most issues we have seen with GPRS boards that don’t work as expected when using codes from published examples is due to using an insufficient power source.
Can you describe how things are wired and powered?
I am using an external power supply with 5v and 1amp to the sim900 module power socket. For my arduino board, the power is from my laptop usb port. The pin 7 and 8 are for tx and rx respectively. That is my wiring and settings.
My sim has sufficient credit and tested on my phone. Sim 900 status and netlight led are lighted up or blinking once I power up and press power key button for short moment.
What is the "64" in this statement? It is supposed to be a terminating CHARACTER.
You will get compiler warnings about this if you turn them on
/var/folders/4z/3g9th3gs4cng3b803dg5bhw40000gn/T/arduino_modified_sketch_152933/HelloWorld.pde: In function 'void sendSMS()':
/var/folders/4z/3g9th3gs4cng3b803dg5bhw40000gn/T/arduino_modified_sketch_152933/HelloWorld.pde:31:51: warning: invalid conversion from 'const char*' to 'char' [-fpermissive]
String status_code = SIM900.readStringUntil("64"); // Read string until 64 is found (end of message
I got the compilation warning message but do not think it will impact sending sms though. Fyi, I copied readStringUntil statement from an article and my purpose is only dumping after at command results.
When I copied sending sms code, I only set initializing baud rate,sms mode, recipient mobile no, message and terminate message character. No reading statement was added. After i could not send a simple sms, i only added more at command in the beginning and tried to dump out the at command operation result to a console screen to rule out wiring and any other possible issues.
a few more AT commands worth trying
AT+CGMI returns the manufacturer's name
AT+CGMM returns the MODEM model number
AT+CGMR returns details of the software and model revision level
AT+CGSN returns the MODEM's serial number
AT+CIMI returns IMSI of the SIM card
AT+CCID returns the SIM ID number
AT+CNUM returns your telephone number
My power source is 5v and max output is 5amp and test again. The sending sms is still not working. I do not implement reading sms as it is not part of my project.
I have done following operation.
AT+CGMI, AT+CGMM, AT+CGMR, AT+CGSN, AT+CIMI, AT+CCIDnumber and
AT+CNUM
the above results are following:
10:39:23.058 -> Sim responds = AT+CGMI