Hey all, finally got a chance to start learning about this GSM shield and immediately I ran into a problem. I use the example code below and made the changes needed to send an sms to my phone. So now its supposed to send me an sms telling me that the GSM shield has been initialized and can now receive sms.
So it does initialize and says it has sent me an sms but I don't get anything. And when I try to send an sms to the GSM shield from my phone it won't show anything.
You think it has something to do with the sim and its service? I live in Canada and bought a sim with a pre-paid service from BELL.
#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"
//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to send and receive SMS.
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
//debug begin
char sms_position;
char phone_number[20]; // array for the phone number string
char sms_text[100];
int i;
//debug end
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(4800))
{
Serial.println("\nstatus=READY");
started=true;
}
else
Serial.println("\nstatus=IDLE");
if(started)
{
//Enable this two lines if you want to send an SMS.
(sms.SendSMS("+1##########", "Arduino SMS ready")); //HERE IS WHERE I PUT MY PHONES NUMBER
Serial.println("\nSMS sent OK");
//if NO SPACE ,you need delte SMS from position 1 to position 20
//please enable this four lines
//for(i=1;i<=20;i++)
//{
//sms.DeleteSMS(i);
//}
}
};
void loop()
{
if(started)
{
//Read if there are messages on SIM card and print them.
sms_position=sms.IsSMSPresent(SMS_UNREAD);
if (sms_position)
{
// read new SMS
Serial.print("SMS postion:");
Serial.println(sms_position,DEC);
sms.GetSMS(sms_position, phone_number, sms_text, 100);
// now we have phone number string in phone_num
Serial.println(phone_number);
// and SMS text in sms_text
Serial.println(sms_text);
}
else
{
Serial.println("NO NEW SMS,WAITTING");
}
delay(1000);
}
};
What I was suggesting was following the steps I outline in the page linked to in my signature. Send a simple SMS to your phone manually to make sure the shield connects to the network correctly.
I'm assuming that that the net light starts to blink slower, indicating a network connection, before it reports that it has sent the SMS?
Unfortunately not. First the power led turns on then the net led starts to blink, then lastly an led that says 's' turn on. The blink of the net led is constant no matter what happens. I'll give your guide a go.
Nothing seems to be working. Perhaps its because of a weak antennae signal? My phone has only 2 bars out of 5. I also keep thinking its because the module isn't getting enough power, but the GSM module has no power input so I just plug a 9v battery along side the usb power on the arduino.
I wouldn't bother with the regular, rectangular 9v batteries. They are good for smoke alarms and radios but little else. If you have one connect up a decent power supply as the SIM900 (and most other modem chips) can draw 2 amps when transmitting, which includes connecting to the network. However lack of network connection is a difficult thing to diagnose.
Hi! I did use your code,((Seeedstudio SIM900 GPRS/GSM Shield)) but after Write a AT command and send, nothing happened.
Im trying to start a Led by sms, I can make calls, and send sms, but, the action doesnt happen.
Can you help me? under is the code them Im use:
SerialGSM cel(2,3); //Configura os pinos 2 e 3 para se trabalhar como Rx e Tx via Software
String SMS; //Variável para o armazenamento da SMS recebida
String numeroRemetente; //Variável para o armazenamento do número do remetente da SMS
String numeroPermitido = "998919094"; //Variável que define o número do celular que o sistema irá responder
boolean sendonce=true; //Variável boleana utilizada pela biblioteca SerialGSM.h
void setup()
{
int i; //Variável para contagem
for(i=9;i<=11;i++) //Laço que configura os pinos D9 a D11 como saída e em nível lógico 0(LOW)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
Serial.begin(9600); //Incializa a Serial(Hardware) com um Baud Rate de 9600
cel.begin(9600); //Incializa a Serial(Software) com um Baud Rate de 9600
cel.Verbose(true); //Função de configuração da biblioteca SerialGSM.h
cel.Boot(); //Função de inicialização do Módulo SM5100B
cel.DeleteAllSMS(); //Função para deletar todas as SMS do chip
cel.FwdSMS2Serial(); //Função utilizada para enviar as SMS para a Serial
Serial.println(">>>>> Celular Shield Inicializado <"); //Mensagem de início da aplicação
Serial.println(); //Pula linha
}
void loop()
{
if (cel.ReceiveSMS()) //Se o chip no Celular Shield receber uma SMS
{
Serial.println(); //Pula linha
Serial.println(); //Pula linha
Serial.println(); //Pula linha
Serial.println(); //Pula linha
Serial.println("NOVA MENSAGEM RECEBIDA"); //Imprime na serial "NOVA MENSAGEM RECEBIDA"
Serial.println(); //Pula linha
Serial.print("REMETENTE: "); //Imprime na serial a palavra "REMETENTE:"
Serial.println(cel.Sender()); //Imprime o número do remetente que a SMS foi enviada
numeroRemetente = cel.Sender(); //Armazena na variável numeroRemetente o número do remetente
if(numeroRemetente != numeroPermitido) //Se o número do remetente não for o mesmo que o número permitido
{
Serial.println("Não Permitido"); //Imprime a mensagem "Não Permitido" e não executa nada
}
else //Senão, o número é o permitido e executará os comandos
{
Serial.print("MENSAGEM: "); //Imprime na serial a palavra "MENSAGEM:"
Serial.println(cel.Message()); //Imprime a mensagem que foi recebida
SMS = cel.Message(); //Guarda na mensagem na variável SMS
//++++++++Tratamento do Primeiro Caractere++++++++
if(SMS[0] == '1') //Se o primeiro caractere da SMS for igual a 1
{
digitalWrite(9,HIGH); //Acende o LED verde
Serial.println();//Pula uma linha na serial
Serial.println("LED VERDE ACESO"); //Imprime a mensagem "LED VERDE ACESO"
}
else if(SMS[0] == '0') //Senão, se o primeiro caractere for igual a 0
{
digitalWrite(9,LOW); //Apaga o LED verde
Serial.println(); //Pula uma linha na serial
Serial.println("LED VERDE APAGADO"); //Imprime a mensagem "LED VERDE APAGADO"
Serial.println(); //Pula uma linha na serial
}
//=================================================
}
//++++++++Tratamento do Segundo Caractere++++++++
if(SMS[1] == '1') //Se o segundo caractere da SMS for igual a 1
{
digitalWrite(10,HIGH); //Acende o LED amarelo
Serial.println(); //Pula uma linha na serial
Serial.println("LED AMARELO ACESO"); //Imprime a mensagem "LED AMARELO ACESO"
}
else if(SMS[1] == '0') //Senão, se o segundo caractere for igual a 0
{
digitalWrite(10,LOW); //Apaga o LED amarelo
Serial.println(); //Pula uma linha na serial
Serial.println("LED AMARELO APAGADO"); //Imprime a mensagem "LED AMARELO APAGADO"
}
//=================================================
//++++++++Tratamento do Terceiro Caractere++++++++
if(SMS[2] == '1') //Se o terceiro caractere da SMS for igual a 1
{
digitalWrite(11,HIGH); //Acende o LED vermelho
Serial.println(); //Pula uma linha na serial
Serial.println("LED VERMELHO ACESO"); //Imprime a mensagem "LED VERMELHO ACESO"
}
else if(SMS[2] == '0') //Senão, se o terceiro caractere for igual a 0
{
digitalWrite(11,LOW); //Apaga o LED vermelho
Serial.println(); //Pula uma linha na serial
Serial.println("LED VERMELHO APAGADO"); //Imprime a mensagem "LED VERMELHO APAGADO"
}
//=================================================
cel.DeleteAllSMS(); //Deleta todas as SMS
}
}
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
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())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
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=\"+********\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
delay(1000);
}
may try these one hope it works
connect gsm tx and rx pins to 9,10
open serial monitor press s and press enter for sending sms and for getting sms press r and enter key
This code is worked. But how to control the LED by this function?
rupavelamuri:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
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())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
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="+********"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
delay(1000);
}
may try these one hope it works
connect gsm tx and rx pins to 9,10
open serial monitor press s and press enter for sending sms and for getting sms press r and enter key