Problem with gsm remote control sketch

Hello ! I have uploaded to my uno board this code :
#include <SoftwareSerial.h>

// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
//control pins of relay.
int relay_a=4;

//int relay_b=5;
//int relay_c=6;
//int relay_d=7;

// EN: Code PIN of the SIM card (if applied)
String SIM_PIN_CODE = String( “XXXX” ); // at XXXX i m writing the pin number of gsm’s sim

void setup()
{
Serial.begin(19200); // the GPRS baud rate
// Initialize PINs
pinMode( 4, OUTPUT );
// pinMode( 5, OUTPUT );
// pinMode( 6, OUTPUT );
// pinMode( 7, OUTPUT );
digitalWrite( 4, LOW );
// digitalWrite( 5, LOW );
// digitalWrite( 6, LOW );
// digitalWrite( 7, LOW );
Serial.println( “AT+CMGF=1” );
delay(200);
}

void loop()
{
char SerialInByte;
if(Serial.available())
{
SerialInByte = (unsigned char)Serial.read();
delay(5);

// -------------------------------------------------------------------
// EN: Program also listen to the GPRS shield message.
// -------------------------------------------------------------------
// EN: If the message ends with then process the message
if( SerialInByte == 13 ){
// EN: Store the char into the message buffer
ProcessGprsMsg();
}
if( SerialInByte == 10 ){
// EN: Skip Line feed
}
else {
// EN: store the current character in the message string buffer
msg += String(SerialInByte);
}
}
}
// EN: Make action based on the content of the SMS.
// Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){

if( sms.indexOf(“ona”) >= 0 ){
digitalWrite( relay_a, HIGH );
}

if( sms.indexOf(“offa”) >= 0 ){
digitalWrite( relay_a, LOW );
}

}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
Serial.println( “AT+CMGF=1” );
}

void GprsReadSmsStore( String SmsStorePos ){
Serial.print( “AT+CMGR=” );
Serial.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
msg = “”;
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
if( msg.indexOf( “Call Ready” ) >= 0 ){
// Serial.println( “*** GPRS Shield registered on Mobile Network ***” );
GprsTextModeSMS();
}

// EN: unsolicited message received when getting a SMS message
if( msg.indexOf( “+CMTI” ) >= 0 ){
// Serial.println( “*** SMS Received ***” );
// EN: Look for the coma in the full message (+CMTI: “SM”,6)
// In the sample, the SMS is stored at position 6
int iPos = msg.indexOf( “,” );
String SmsStorePos = msg.substring( iPos+1 );
// Serial.print( "SMS stored at " );
// Serial.println( SmsStorePos );
// EN: Ask to read the SMS store
GprsReadSmsStore( SmsStorePos );
}

// EN: SMS store readed through UART (result of GprsReadSmsStore request)
if( msg.indexOf( “+CMGR:” ) >= 0 ){
// EN: Next message will contains the BODY of SMS
SmsContentFlag = 1;
// EN: Following lines are essentiel to not clear the flag!
ClearGprsMsg();
return;
}

// EN: +CMGR message just before indicate that the following GRPS Shield message
// (this message) will contains the SMS body
if( SmsContentFlag == 1 ){
// Serial.println( “*** SMS MESSAGE CONTENT " );
// Serial.println( msg );
// Serial.println( "
END OF SMS MESSAGE ***” );
ProcessSms( msg );
}

ClearGprsMsg();
// EN: Always clear the flag
SmsContentFlag = 0;
}

I 'm using one relay to pin4 and i connect uno+gsm +tinkerkit relay to an external power suplly as you can see at this photo
http://postimg.org/image/9dpteita9/
I’m sending the sms ona to the sim card of the gsm but the relay doesn’t change situation !
is something wrong with the code ?

someone help me with the code ??????

  1. Can you modify your original post to use code tags please? And use Ctrl+T to auto format it. It makes it a lot easier to read.

Having just taken a look at the photo… You are using a suitable power supply for the modem aren’t you, and not the one in the foreground? And won’t the shield and the Arduino go any closer?

what's wrong with the power supply ? I have 10,6 V to the output of the power suplly ! It s max cuccent is 300 mA !
How am i going to modify the code being easier to read ?

The modem will draw about 2amps momentarily when in use. That is more than six times the maximum capacity of the power supply in your photo. Even with the capacitor on the shield acting as a reservoir you are trying to draw way more than it will supply.

Load your code into the IDE. Press Ctrl+T (or find auto format in the menu). Then copy the code and paste it to the forum in code tags. There is a sticky about how to use the forum at the top of the page.

#include <SoftwareSerial.h>

// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
//control pins of relay.
int relay_a=4;

//int relay_b=5;
//int relay_c=6;
//int relay_d=7;

// EN: Code PIN of the SIM card (if applied)
String SIM_PIN_CODE = String( “XXXX” ); // at XXXX i m writing the pin number of gsm’s sim

void setup()
{
Serial.begin(19200); // the GPRS baud rate
// Initialize PINs
pinMode( 4, OUTPUT );
// pinMode( 5, OUTPUT );
// pinMode( 6, OUTPUT );
// pinMode( 7, OUTPUT );
digitalWrite( 4, LOW );
// digitalWrite( 5, LOW );
// digitalWrite( 6, LOW );
// digitalWrite( 7, LOW );
Serial.println( “AT+CMGF=1” );
delay(200);
}

void loop()
{
char SerialInByte;
if(Serial.available())
{
SerialInByte = (unsigned char)Serial.read();
delay(5);

// -------------------------------------------------------------------
// EN: Program also listen to the GPRS shield message.
// -------------------------------------------------------------------
// EN: If the message ends with then process the message
if( SerialInByte == 13 ){
// EN: Store the char into the message buffer
ProcessGprsMsg();
}
if( SerialInByte == 10 ){
// EN: Skip Line feed
}
else {
// EN: store the current character in the message string buffer
msg += String(SerialInByte);
}
}
}
// EN: Make action based on the content of the SMS.
// Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){

if( sms.indexOf(“ona”) >= 0 ){
digitalWrite( relay_a, HIGH );
}

if( sms.indexOf(“offa”) >= 0 ){
digitalWrite( relay_a, LOW );
}

}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
Serial.println( “AT+CMGF=1” );
}

void GprsReadSmsStore( String SmsStorePos ){
Serial.print( “AT+CMGR=” );
Serial.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
msg = “”;
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
if( msg.indexOf( “Call Ready” ) >= 0 ){
// Serial.println( “*** GPRS Shield registered on Mobile Network ***” );
GprsTextModeSMS();
}

// EN: unsolicited message received when getting a SMS message
if( msg.indexOf( “+CMTI” ) >= 0 ){
// Serial.println( “*** SMS Received ***” );
// EN: Look for the coma in the full message (+CMTI: “SM”,6)
// In the sample, the SMS is stored at position 6
int iPos = msg.indexOf( “,” );
String SmsStorePos = msg.substring( iPos+1 );
// Serial.print( "SMS stored at " );
// Serial.println( SmsStorePos );
// EN: Ask to read the SMS store
GprsReadSmsStore( SmsStorePos );
}

// EN: SMS store readed through UART (result of GprsReadSmsStore request)
if( msg.indexOf( “+CMGR:” ) >= 0 ){
// EN: Next message will contains the BODY of SMS
SmsContentFlag = 1;
// EN: Following lines are essentiel to not clear the flag!
ClearGprsMsg();
return;
}

// EN: +CMGR message just before indicate that the following GRPS Shield message
// (this message) will contains the SMS body
if( SmsContentFlag == 1 ){
// Serial.println( “*** SMS MESSAGE CONTENT " );
// Serial.println( msg );
// Serial.println( "
END OF SMS MESSAGE ***” );
ProcessSms( msg );
}

ClearGprsMsg();
// EN: Always clear the flag
SmsContentFlag = 0;
}

is this good ?
is it sure that i need a 2 A power supply ?? I did this example http://arduino.cc/en/Tutorial/GSMExamplesSendSMS
only with the usb cable and i could read my messages to the serial monitor !!

Products > Shields > GSM Shield

Power requirements

It is recommended that the board be powered with an external power supply that can provide between 700mA and 1000mA. Powering an Arduino and the GSM shield from a USB connection is not recommended, as USB cannot provide the required current for when the modem is in heavy use.

The modem can pull up to 2A of current at peak usage, which can occur during data transmission. This current is provided through the large orange capacitor on the board’s surface.

Which Arduino board are you using?

UNO the original :slight_smile:

is there big difference at the current between the project of gsm remote control and the other project just sending a sms and read it to the serial monitor that worked to me ???

You need to bear in mind that when it refers to ‘data transmission’, this could mean basic communication with the mobile / cell phone network. It’s up to you but all the modem cards for Arduino recommend 2 amp power supplies. I use a three amp and run the Arduino and peripherals from the one supply.

Anyway, it would appear that you are trying to communicate with the shield using pins 0 & 1, whereas the shield is expecting you to communicate via pins 2 & 3!

Try adding the line

SoftwareSerial GSM(2, 3);

after

#include <SoftwareSerial.h>

and then change every instance of ‘Serial.’ to ‘GSM.’ and then try it.

Unless I'm mistaken, you appear to be missing an aerial too.

change every instance of 'Serial.' to 'GSM.' what do you mean ? every word ( serial ) at the code change it with the word (GSM) ?

Every place that the word Serial appears (starts with a capital S, and ends with a full stop / period) replace with GSM. (Note the full stop / period again.)

Obviously you don't need to change it in the comments but it might help to make the code readable...
Serial uses pins 0 & 1, you want to try to use pins 2 & 3, hence the use of SoftwareSerial.

i think it’s a better idea to modify the code from this project http://scuola.arduino.cc/lesson/LVEVK1a/Using_SMS_messages_to_control_LED_color that uses tha same gsm shield with mine
This code needed many changes so i did this :

/*

***** The circuit *****
For this project you need;
*Arduino Uno
*Arduino GSM shield

*WS2801 LED pixels connected to PIN 6

*5V Power source for the LED string
*12V Power source for the UNO and GSM shield

*/

// **** 1 Libraries, definitions and global variables ****

#include <GSM.h> // This includes the GSM library, included in your Arduino IDE

#define PINNUMBER “” // declaration of the constant PINNUMBER used to push the pin number of the SIM card
#define PIN 6 // declaration of the constant PIN, and setting it to output nr. 6

GSM gsmAccess; // opens up GSM access on the shield.
GSM_SMS sms;

char remoteNumber[20]; // Variable to store the remote number from the modem.
char c; //Variable for reading the sms messages from the SIM card

int x=0; //Counter for the number of SMS messages processed
char lastm; //Variable to stop SMS replying
String lastMess; //for storing the whole message

// **** 2 Setup ****

void setup() {
//Setup for SMS recieving. Serial setup makes it possible to monitor the status on your PC while connected
Serial.begin(9600);
Serial.println(“SMS Recieving”);

boolean notConnected = true; // this defines a variable that indicates no GSM connection if true
while(notConnected) { // if there is no connection, the program runs gsmAcess. gsmAcess returns GSM_READY when connected
if(gsmAccess.begin(PINNUMBER"0462")==GSM_READY) // If you have a PIN number on your SIM card, write it as parameters here in quotes. PINNUMBER"9876"
notConnected = false;
else {
//messages printed on the serial monitor or LCD screen, then it tries again in 1000 milliseconds
Serial.println(“No connection”);

}
}
// if connection is established
Serial.println(“GSM connected”); //GSM connected
Serial.println(“Waiting”); //Waiting for SMS

}

// **** 3 The loop ****

void loop() {
lastMess = “”;
//reading messages
if (sms.available()) // if there are SMS on the SIM card
{
x++; //message counter adds one
sms.remoteNumber(remoteNumber, 20);

//Show the message on monitor
Serial.println(“Messages received from”);
Serial.println(remoteNumber); //Prints senders number on the serial monitor
Serial.println(“Message:”);

while(c=sms.read()) {
String nextChar = String (c);
String Mess = (lastMess + nextChar);
lastMess = Mess;
/*sms.read collects one digit of the messages at time and stores it in the variable c.
This while loop builds a String variable “lastMess” from each byte in the messages for displaying.
*/
}

Serial.println(lastMess); // prints the whole messages on the monitor and LCD screen

}//end for

sms.flush(); //discards the SMS message

}

but it isn’t correct ! can you tell me the items i have to rectify ??

In what way isn't it working? Does it compile and upload? If so what do you see in Serial Monitor?

And could you use code tags, not quote? It's the button with the hash on it.

hello my friend ! could you explain me step by step how to do the code tags ! i don't understand what do yoy mean ! :frowning:
with codebender gsm remote control by christosxouris i had these three mistakes http://postimg.org/image/4c50ma8ol/
with arduino ide it was uploaded with no mistakes !! :~ :~ :~ How did this happens ?

is it possible to have the external power supply and the usb cable together on my arduinos at the same time ? Only with the external power supply the gsm can receive sms and i thought if i had and the usb cable could see at the serial monitor if the sms received

I'm at work so I cant access the links you provided. There is a section on how to use code tags in the sticky at the top of the page - How to Use...

You can power the Arduino with the USB cable and the shield with an external power supply as long as the grounds are connected, and with a shield stacked on the Arduino this shouldn't be a problem.