GSM interfacing help!

Good day guys!

I'm new to Arduino and I am trying to interface a SIM340DZ GSM/GPRS Module to AtMega. I have my code written, but it does not work properly. Here is my code:

char Rx_data[50]; unsigned char Rx_index = 0;

void setup() { Serial1.begin(9600); // connect to the serial port Serial.begin(9600); initGSM(); sendPC("Successful START\n\n"); }

void loop () { }

void sendGSM(char *string){ Serial1.write(string); delay(10); }

void sendPC(char *string){ Serial.write(string); delay(10); }

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

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

void initGSM(){ sendPC("Start\n");

send_cmd("AT\n",1); sendPC("init ok\n");

send_cmd("ATE0\n",1); sendPC(" echo ok\n");

send_cmd("AT+CMGF=1\n",1); sendPC("Successful Initialization!\n\n");

delay(1000); }

void readSerialString (char string) { int i = 0; if(!Serial1.available()) { Serial.print("Not available\n"); return; } while(Serial1.available()) { string *=; * i++;* * }* } I checked Rx_data and it does not return "OK".. BTW, the code is for the initialization of the GSM.. What could be wrong with my code? Hope anyone can help me.. Thanks in advance!

It might not be a software problem. It might be a hardware problem. How do you have the GSM module connected to the Arduino?

I connected the Tx pin of the uC to Rx of GSM and the Rx pin of the uC to Tx of the GSM.

Thanks for the reply.. Hope you can help me solve my problem..

Power? Ground?

I have a 5V adapter to power the module.

Is the module's ground connected to the Arduino's ground?

No.. So, is that what I need?

Run a wire and find out.

I tried what you said.. Still does not work..

How about posting a picture of your setup, then?

Here's a link to the image.. Sorry, I can't get a good photo.. I don't have a cam with me..

I connected the Tx pin of the uC to Rx of GSM and the Rx pin of the uC to Tx of the GSM.

Have you tried reversing these connections ( Rx to Rx and Tx to Tx)? The serial communications "standards" are almost never implemented as originally intended, so you cannot always assume that the Rx pin is an input and the Tx pin is an output.


I alreadt tried, and it also does not work..=(

Hi guys! I was able to make it work already... I added \r before the new line in every AT command.. Thanks to all who helped.. =)

Special thanks to PaulS and floresta..=)