SIM900 and Arduino Uno

Good day sir!
My project is to light an LED via SMS. I am using a SIM900 GSM Module and Arduino Uno.
A very nice guy from portugal tells me that i should use SoftwareSerial because using the Tx and Rx pin on arduino and the serial connection to the PC will ruin everything.
The problem is i am still receiving garbage on my serial monitor.
He tells me to use a TTL converter but i dont know how to connect it and where should i connect it.

Can someone tell me the setup of the connection? I badly need your help. I am losing hope now =(

Last I looked the SIM900 runs at about 4v, it probably doesn't like 5v from the Arduino.

Is this your own board or a standard shield?

Can you post your code and schematics?


Rob

Good day!
I'm new to Arduino and GSM Modem programming.
Im going to use it as a Home Automation System.
For now im trying to display the incoming message in my serial monitor. But all I can see in my serial monitor are garbages.

This is my sample code.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3);

char number[14];
char sms_array[250];
char Rx_data[50];
int i = 0;
int Led = 13;


boolean smsReceived = false;

void setup()  
{
  pinMode(Led, OUTPUT);      
  Serial.begin(9600);
  Serial.println("Initialize GSM");
  mySerial.begin(9600);
  initializeGSM();  
  delay(30);
}

void loop()  
{
load_array_data();
Serial.println(getdata());
}


//_____________________________
void load_array_data()
{
int k = 0 ;
mySerial.print("AT+CMGR=1\r\n"); //Read Message
delay(100);
while (mySerial.available() > 0)
{
  sms_array[k] = mySerial.read();
  delay(80);
  k++;
  if(k >= 150)break;
}
mySerial.flush();
clear_ReceivedSMS();
}


//____________________________
void clear_ReceivedSMS()
{
if(smsReceived == false) 
{
  send_cmd("AT+CMGD=1\r\n",1); 
  delay(80);
  Serial.println("SMS Deleted");//Diagnostic
  smsReceived = true;
 }
}






//____________________________
String getdata()
{
int n = 0;
for(int i=0;i<=150;i++)
  {
    body[i] = sms_array[n];
    n++;
  }
  

return body;
}


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




//____________________________
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)
  {
    sendtoGSM(at_cmd);
    delay(90);
    readSerialString(Rx_data);
    stat = strstr(Rx_data, "OK");
  }
  if (clr)
  {
    clearString(Rx_data);
    delay(200);
    stat = '\0';
  }
}


//____________________________
void sendtoGSM(char *string)
{
  mySerial.print(string);
  delay(90);
}


//____________________________
void initializeGSM()
{
  send_cmd("AT\r\n",1);
  send_cmd("AT+CMGF=1\r\n",1);		
  Serial.print("Success");
  
  delay(1000);
  delay(1000);
  delay(1000);
}

I've been using this modem: gsm gprs shield.pdf - Google Drive
And Arduino Uno as my MCU.

What do you think is wrong?

Topics merged.

Thanks mod! I can't find the thread i started yesterday. Thanks for this.

I can't find the thread i started yesterday.

Click on "Profile", and got to "Show posts"

Good day!
Refer first at my GSM Modem.
Here is the link:
https://docs.google.com/file/d/0BxdLxDCD6HidRUJ5UXphTlUwVGM/edit?pli=1

My GSM Modem can only communicate via Port 1 and 0, am i going to connect my ARDUINO UNO Pin 1 and 0 to that given pins respectively?

And a good guy told me that the solution is to use SoftwareSerial and make the pins 2 and 3 of the Arduino as a serial connection to my PC.
The question is, do i need a TTL Converter to do this? And if it is needed is that the connection where i can upload my sketch and i will not be using the USB connection anymore?

My GSM Modem can only communicate via Port 1 and 0, am i going to connect my ARDUINO UNO Pin 1 and 0 to that given pins respectively?

Arduino Uno uses those pins for serial communication, that's probably why you get garbage in the serial monitor.
As far as I know (correct me if I'm wrong though), you can't use the Serial Monitor properly if something has been connected to the RX and TX pins, at least if there's a signal coming through.

If all of the above is true, you can't use the GSM Modem on those ports if you wish to see something useful in the serial monitor.
The link you provided said it can use Recieve and Transmit on pins 2 and 3 in SUART mode, see if you can make use of that.

Or connect the GSM Module to pins 0 & 1 and don't use the serial.

After reading the Sim900 shield manual at page 5 you will see some jumper settings that allow you to choose what pins you want to use in RX and TX of the modem.This way you can free the hardware arduino UART to use as you want and use the SoftSerial to communicate with the modem.

SIM900_HD_V1.01(091226).pdf (2.18 MB)

Good day ladies and gentlemen!
I am having problem with lighting up my Led connected to pins 10, 11, 12 and 13.
Here is my code:

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"

SMSGSM sms;

int numdata;
boolean started=false;
char smsbuffer[160];

int PinOne = 10;
int PinTwo = 11;
int PinThree = 12;
int PinFour = 13;
boolean One = false;
boolean Two = false;
boolean Three = false;
boolean Four = false;


void setup() 
{

  pinMode(PinOne, OUTPUT);
  pinMode(PinTwo, OUTPUT);
  pinMode(PinThree, OUTPUT);
  pinMode(PinFour, OUTPUT);

  Serial.begin(9600);
  Serial.println("GSM Shield testing.");

  if (gsm.begin(9600))
  {
    Serial.println("\nstatus=READY");
    started=true;  
  }
 
  else Serial.println("\nstatus=IDLE");
  delay(1000);
}

void loop() 
{
  char position;
  char phone_num[20] = {'\0'};
  char sms_text[100] = {'\0'};

  if (started)
  {
    position = sms.IsSMSPresent(SMS_UNREAD);
    
    if (position)
    {
      sms.GetSMS(position, phone_num, sms_text, 100);
      Serial.println("Data Received");
      delay(500);
      Serial.println(phone_num);
      Serial.println(sms_text);
            
      get_cmd(sms_text);
      delay(500);
      delay(500);
      gsm.SimpleWrite("AT+CMGD=");
      gsm.SimpleWriteln("1,4");
      Serial.println("SMS DELETED");
      delay(1000);
    }
    
    clearstring_num(phone_num);
    delay(250);
    clearstring_txt(sms_text);
    delay(250);
  }

}

void clearstring_num(char *strArray_num) 
{
  int j;
  for (j = 20; j > 0; j--)
  strArray_num[j] = 0x00;
}

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


void get_cmd(char *command)
{
  char sms_ctext[100] = {'\0'};
  sprintf(sms_ctext, "%s", command);
  
  if (strcmp(sms_ctext,"ON 1") == 0 )
  {
    if(One)
    {
      Serial.println("Port One is Already ON");
      delay(1000);
    }  
    else if(!One)
    {
      digitalWrite(PinOne,HIGH);
      delay(1000);
      Serial.println("Port Three is ON");
      delay(1000);
      One = true;
      delay(200);
    }
  }

  else if (strcmp(sms_ctext,"ON 2") == 0 )
  {
    if(Two)
    {
      Serial.println("Port Two is Already ON");
      delay(1000);
    }  
    else if(!Two)
    {
      digitalWrite(PinTwo,HIGH);
      delay(1000);
      Serial.println("Port Three is ON");
      delay(1000);
      Two = true;
      delay(200);
    }
  }

  else if (strcmp(sms_ctext,"ON 3") == 0 )
  {
    if(Three)
    {
      Serial.println("Port Three is Already ON");
      delay(1000);
    }  
    else if(!Three)
    {
      digitalWrite(PinThree,HIGH);
      delay(1000);
      Serial.println("Port Three is ON");
      delay(1000);
      Three = true;
      delay(200);
    }
  }

  else if (strcmp(sms_ctext,"ON 4") == 0 )
  {
    if(Four)
    {
      Serial.println("Port Four is Already ON");
      delay(1000);
    }  
    else if(!Four)
    {
      digitalWrite(PinThree,HIGH);
      delay(1000);
      Serial.println("Port Four is ON");
      delay(1000);
      Four = true;
      delay(200);
    }
  }
  
  else if (strcmp(sms_ctext,"OFF 1") == 0 )
  {
    digitalWrite(PinOne,LOW);
    delay(1000);
    Serial.println("Port One is Off");
    One = false;
    delay(200);
  }

  else if (strcmp(sms_ctext,"OFF 2") == 0 )
  {
    digitalWrite(PinTwo,LOW);
    delay(1000);
    Serial.println("Port Two is Off");
    Two = false;
    delay(200);
   
  }

  else if (strcmp(sms_ctext,"OFF 3") == 0 )
  {
    digitalWrite(PinThree,LOW);
    delay(1000);
    Serial.println("Port Three is Off");
    Three = false;
    delay(200);
  }

  else if (strcmp(sms_ctext,"OFF 4") == 0 )
  {
    digitalWrite(PinFour,LOW);
    delay(1000);
    Serial.println("Port Four is Off");
    Four = false;
    delay(200);
  }
  
  else if (strcmp(sms_ctext,"CHECK STATUS") == 0 )
  {
    check_status();
    delay(1000);
  }
  
  else if (strcmp(sms_ctext,"OFF ALL") == 0 )
  {
    off_all();
    delay(1000);
  }
  
  else
  {
    Serial.println("Invalid Command/s");
  }
  
}


void check_status()
{
    
    char str[150]; 
  
    Serial.println(check_one());
    delay(500);
    Serial.println(check_two());
    delay(500);
    Serial.println(check_three());
    delay(500);
    Serial.println(check_four());
    delay(500);
}


String check_one()
{
  String status_one;
  
  if (One == true)
  {
    delay(200);
    status_one = "Pin One: ON";
  }
  
  if (One == false)
  {
    delay(200);
    status_one = "Pin One: OFF";
  }
  
  return (status_one);
}


String check_two()
{
  String status_two;
  
  if (Two == true)
  {
    delay(200);
    status_two = "Pin Two: ON";
  }
  
  if (Two == false)
  {
    delay(200);
    status_two = "Pin Two: OFF";
  }
  
  return(status_two);
  
}


String check_three()
{
  String status_three;
  
  if (Three == true)
  {
    delay(200);
    status_three = "Pin Three: ON";
  }
  
  if (Three == false)
  {
    delay(200);
    status_three = "Pin Three: OFF";
  }
  
  return(status_three);
  
}


String check_four()
{
  
  String status_four;
  
  if (Four == true)
  {
    delay(200);
    status_four = "Pin Four: ON";
  }
  
  if (Four == false)
  {
    delay(200);
    status_four = "Pin Four: OFF";
  }
  
  return(status_four);
  
}


void off_all()
{
  digitalWrite(PinOne, LOW);
  One = false;
  delay(500);
  digitalWrite(PinTwo, LOW);
  Two = false;
  delay(500);
  digitalWrite(PinThree, LOW);
  delay(500);
  Three = false;
  digitalWrite(PinFour, LOW);
  Four = false;
  delay(500);
  delay(500);
}

I use Pins 2 and 3 of the Arduino for Rx and Tx.
Pins 10, 11, 12 and 13 for Digital Output to control the LEDs.
What may be the problem to this?
I need your expertise on this. I cant figure it out.

Did you get the prints on the Serial Port?
Post those prints to debug what is happening

Yes! I get the right message on the serial monitor. The problem I think is on digitalWrite(); because it cannot give a logic 1 output or 5V on my LEDs. You know how to solve this stuff? Do you think i need a supply voltage on my arduino? But when i reset it the LED on pin 13 blinks. Hmmm.

Write yourself a much simpler sketch to check your wiring - i.e. take a copy of blink and adapt it to flash all your LEDs. Once you know you can light them, then move on to debugging your code. Take a look at your serial prints - a number of them appear to have been copy/pasted - you've got several messages about port three that look out of place.

I still cant light it. There is no wrong in my wiring.

The Rx and Tx of my arduino is placed on pins 2 and 3 by using SoftwareSerial. And my LEDs(in which im trying to lght u) are located on pins 10,11,12 and 13. Im thinking, maybe my GND is wrong. Where should i put the common ground on the Arduino and GSM Shield? Or is it okay to place it anywhere? My current set-up is like this;

The GSM Shield and Arduino have common GND on the pin above the Vin.

The grounds of my LED is located above Pin 13 of Digital I/O.