I am using a Mega 2560 and the official GSM shield. I also attached an external 9V power supply to my mega.
I can run the sample SMS code, and then based on that, I just wrote a function that send an a default SMS.
However, I noticed that it won't initialise neither will it send SMS if I unplug the USB cable / don't use Serial Monitor. Why is that so? I have browsed through the forum and have seen a couple of setup problem but I just can't make it work with my GSM shield. Below are my codes for your reference. Please assist. It is driving me crazy!
/*
* Send SMS to somewhere
* Author: Syahmul Aziz
* Written on 23/5/2014
* Reference: SendSMS by Arduino GSM
*/
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
//GSM gsmAccess;
GSM gsmAccess(true); //for debugging purposes
GSM_SMS sms;
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(115200);
Serial.println("SMS SENDER MEGA");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected) {
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("Initialized");
//send message. I did not put it in a loop because I only want it to send once
sendSMS();
}
void loop() {
}
void sendSMS() {
// send the message
char remoteNum[20] = "9899xxxx"; // telephone number to send sms
// sms text
char txtMsg[200] = "Sending from BLUNO sendSMS."; //sms content
// send the message
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("SMS sent");
}
On the nth time of trying, I noticed that my GSM shield "ON" LED is not lighted up at all when I use the external battery (Last time I check with multimeter, the value is 8v and 1.6A). But when I use a USB cable, the GSM shield lighted up.
So, I straight away unplug my battery and plugged in my 9V adapater and works! I kinda feel stupid for posting this post. haha. But I hope it would be useful for others.