# Arduino GSM connection\[SOLVED\]

**URL:** <https://forum.arduino.cc/t/arduino-gsm-connection-solved/222738>\
**Category:** Programming\
**Created:** [March 27, 2014, 11:07am UTC](https://forum.arduino.cc/t/arduino-gsm-connection-solved/222738 "2014-03-27T11:07:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![patricio\_74](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@patricio\_74](https://forum.arduino.cc/u/patricio_74)\
**Post date:** [March 27, 2014, 11:07am UTC](https://forum.arduino.cc/t/arduino-gsm-connection-solved/222738/1 "2014-03-27T11:07:27Z")

</div>

Hi.I am trying to send sms using Arduino GSM Shield with Arduino Uno r3.The code uploaded is:  
// Include the GSM library  
#include \<GSM.h\>

#define PINNUMBER "1234"

// initialize the library instance  
GSM gsmAccess(true);  
GSM\_SMS sms;

void setup()  
{  
// initialize serial communications and wait for port to open:  
Serial.begin(9600);  
while (!Serial) {  
; // wait for serial port to connect. Needed for Leonardo only  
}

Serial.println("SMS Messages Sender");

// connection state  
boolean notConnected = true;

// Start GSM shield  
// If your SIM has PIN, pass it as a parameter of begin() in quotes  
while(notConnected)  
{  
if(gsmAccess.begin(PINNUMBER)==GSM\_READY)  
notConnected = false;  
else  
{  
Serial.println("Not connected");  
delay(1000);  
}  
}

Serial.println("GSM initialized");  
}

void loop()  
{

Serial.print("Enter a mobile number: ");  
char remoteNum[20]; // telephone number to send sms  
readSerial(remoteNum);  
Serial.println(remoteNum);

// sms text  
Serial.print("Now, enter SMS content: ");  
char txtMsg[200];  
readSerial(txtMsg);  
Serial.println("SENDING");  
Serial.println();  
Serial.println("Message:");  
Serial.println(txtMsg);

// send the message  
sms.beginSMS(remoteNum);  
sms.print(txtMsg);  
sms.endSMS();  
Serial.println("\nCOMPLETE!\n");  
}

/\*  
Read input serial  
\*/  
int readSerial(char result[])  
{  
int i = 0;  
while(1)  
{  
while (Serial.available() \> 0)  
{  
char inChar = Serial.read();  
if (inChar == '\n')  
{  
result _= '\0';_

- Serial.flush();\*
- return 0;\*
- }\*
- if(inChar!='\r')\*
- {\*  
\_ result _= inChar;_\_  
_\* i++;\*_  
_\* }\*_  
_\* }\*_  
_\* }\*_  
_}_  
_..and the serial monitor output is:_  
_SMS Messages Sender_  
_AT%13%_  
_0 9\>AT%13%%13%%10%OK%13%%10%_  
_AT+CPIN=1234%13%_  
_9 44\>AT+CPIN=1234%13%%13%%10%+CPIN: READY%13%%10%%13%%10%OK%13%%10%_  
_AT+CGREG?%13%_  
_44 75\>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%_  
_AT+CGREG?%13%_  
_89 120\>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%_  
_AT+CGREG?%13%_  
_120 23\>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%_  
_AT+CGREG?%13%_  
_but suddenly stop write output code and switch off the NET and the STATUS led on Arduino._  
_I have read that the meaning of CGREG: 0,2% is waiting for connecting .¿Could be about the code?_  
_Thank you very much._

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 27, 2014, 11:10am UTC](https://forum.arduino.cc/t/arduino-gsm-connection-solved/222738/2 "2014-03-27T11:10:43Z")

</div>

You failed to post your code correctly. Read the stickies at the top of the forum, and you'll know what you need to do, if you are to reasonably expect anyone to help you.

Why are you using Serial.flush()? In that code it is absolutely useless.

---

<div class="post-metadata">

**Author:** ![patricio\_74](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@patricio\_74](https://forum.arduino.cc/u/patricio_74)\
**Post date:** [March 27, 2014, 12:05pm UTC](https://forum.arduino.cc/t/arduino-gsm-connection-solved/222738/3 "2014-03-27T12:05:00Z")

</div>

Hi.True,sorry.The ctrl+c and ctrl+v sometimes comes by inertia.  
Respecting to Arduino GSM connection,with another library example( **GSMScannetworks** ) occurs the same but in this occasion the AT code not print on Serial monitor,only 'GSM networks scanner'.The changes i do:

- The PINNUMBER
- GSM gsmAccess( **true** );

Thank you very much.

---

<div class="post-metadata">

**Author:** ![patricio\_74](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@patricio\_74](https://forum.arduino.cc/u/patricio_74)\
**Post date:** [March 27, 2014, 8:23pm UTC](https://forum.arduino.cc/t/arduino-gsm-connection-solved/222738/4 "2014-03-27T20:23:38Z")

</div>

Hi.Solved.I made two changes:  
1 .- Desactivate PIN of sim card with phone.  
2.- Provide a little more power(9v battery).

- SMS sends without problem.
- GSM scan networks perhaps needs more power supply.

Thank you very much to every one.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 8:36pm UTC](https://forum.arduino.cc/t/arduino-gsm-connection-solved/222738/5 "2021-05-05T20:36:35Z")

</div>

Closed on May 5, 2021, 8:36pm UTC


