Pages: [1]   Go Down
Author Topic: GSM shield help  (Read 379 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im currently trying to create a device that would alert me when a certain limit is reahced, and it would alert me via GSM.


I modified the sample code, and it works great, although, I noticed one problem, when I run it as a standalone system, it does not work, but when i plug it into the computer, it works, WHEN the serial monitor is started. How do i overcome this?

here's the code.

Code:
/*
  GSM Send Sketch for Arduino
 
  Initializes GSM Module and sends an SMS to recipient
 
  The circuit:
  *Arduino pin 0 (RX) - GSM Module (TX)
  *Arduino pin 1 (TX) - GSM Module (RX)
 
  Created 2010
  by Meann Zabanal
  Modified
  by John for GSM Shield testing
*/

char Rx_data[50];
unsigned char Rx_index = 0;
int i = 0;
char msg[160];
int sig;

void setup() {
 
  Serial.begin(38400);
 
  initGSM();
  send_msg("09276191847", "Hello");
}

void loop() {
 

}

void send_msg(char *number, char *msg)
{
 
  int val = 1;
 
  if (val==1){
  char at_cmgs_cmd[30] = {'\0'};
  char msg1[160] = {'\0'};
  char ctl_z = 0x1A;

  sprintf(msg1, "%s%c", msg, ctl_z);
  sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number);
 
  sendGSM(at_cmgs_cmd);
  delay(100);
  delay(100);
  delay(100);
  sendGSM(msg1);
  delay(100);
  send_msg("09******47", "Hello");
  }
 
  if (val == 0);
  {
    Serial.println("The value is Zero");
    send_msg("09276191847", "Hello");
  }

}

void sendGSM(char *string){
  Serial.write(string);
  delay(90);
}

void clearString(char *strArray) {
  int j;
  for (j = 100; j > 0; j--)
    strArray[j] = 0x00;
}

void send_cmd(char *at_cmd, char clr){
  char *stat = '\0';
  while(!stat){
    sendGSM(at_cmd);
    delay(90);
    readSerialString(Rx_data);
   
    stat = strstr(Rx_data, "OK");
  }
  if (clr){
    clearString(Rx_data);
    delay(200);
    stat = '\0';
  }
}

void initGSM(){
  send_cmd("AT\r\n",1);
//  send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module

  send_cmd("AT+CMGF=1\r\n",1); // Set message format to text mode
  //Sucess
 
  Serial.println("Success");

  delay(1000);
  delay(1000);
  delay(1000);
 
}

void readSerialString (char *strArray) {
 
  if(!Serial.available()) {
    return;
  }
 
  while(Serial.available()) {
    strArray[i] = Serial.read();
    i++;
  }
}

Logged

--Gin319

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which kind of GSM module are you using? I think that it's simply not detected by the Arduino because it doesn't perform some sort of handshaking on the serial port, which requires more than the RX and TX pins. The serial terminal does this handshaking and the modem will listen "parasitically" to the messages sent to the PC and send the SMS.
The SoftwareSerial library would allow you to use different pins... so the trick of opening the serial terminal wouldn't work anymore  smiley-eek But then you could connect the GND pin, which can be used for the handshaking part.
Logged

Pages: [1]   Go Up
Jump to: