user3030: I connected SIM300cz module's GSM board with Arduino Mega. The GSM board has the pins VCC, GND, RXD, TXD, GND, RI, DTR, STATUS, PWKEY and GND. I connected the GNDs with Arduino's GND, VCC to Arduinos 5V (took power from Arduino), RXD to pin 5, TXD to pin 6 (because of using software serial) and PWKEY to pin 53. My code is as follows:
#include<SoftwareSerial.h>
SoftwareSerial GPRS(5, 6);

int inputPinTempSensor = 0;
float tempCelsius = 0 ;
float thresholdTemp = 45;

void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate
  Serial.begin(9600);  // the Serial port of Arduino baud rate.
  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);
  delay(100);
}

void loop() {
  GPRS.print("AT+CREG/r");
  Serial.print(GPRS.read());
  delay(2000);
}

The AT command response should be something like "ok" but it's returning -1 for every loop waiting 2 seconds. Why and what could be the solution?
Edit:
Sorry for the mistakes. I was trying different ways with carriage return and new line characters to make it work. Now the code is:
#include<SoftwareSerial.h>
SoftwareSerial GPRS(5, 6);

void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate
  Serial.begin(9600);  // the Serial port of Arduino baud rate.
  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);
  delay(2000);
  GPRS.println("AT+CREG");
}

void loop() {
  while(GPRS.available()){
    Serial.print(GPRS.read());
  }
}

Now it gives no responses at all. Actually after buying the module I was trying with these examples and they were not working either. So, I thought to test if the AT commands were working properly. I could be a problem with my wiring too.

user84: I think there are 2 mistakes in your code:
First, you should ensure that the 3AT3 commands are termintaed by a new line character:
GPRS.print("AT+CREG/r");

should be changed into:
GPRS.println("AT+CREG/r");

or:
GPRS.print("AT+CREG/r\n");

Nite that I am not sure why you added /r at the end of the AT command, is that supposed to be part of the command? If your intention was to force a new line, then you meant \r not /r, which is not really a new line character but a carriage return (that might be interpreted the same by yur GSM module, but not necessarily).
The the second mistake in your code, is directly calling GPRS.read() without first waiting for a character to be available; in this situation, GPRS.read() will always return -1 as a specific value meaning "no available character to read".
So you should change your code to something like:
// 1st wait for a character to be available
while (!GPRS.available()) {
}
// Then read all available characters and log them to Serial
while (GPRS.available()) {
    Serial.print(GPRS.read());
}


user11763: The correct AT command is AT+CREG?\r. A delay of at least 500ms is also advised after every command, though a timeout loop would be better. Since you didn't send any other commands, the modem will have no further responses for you and the Arduino will return -1 to any Serial.read()s, indicating there's nothing to be read.

3030: <p>I connected SIM300cz module's GSM board with Arduino Mega. The GSM board has the pins VCC, GND, RXD, TXD, GND, RI, DTR, STATUS, PWKEY and GND. I connected the GNDs with Arduino's GND, VCC to Arduinos 5V (took power from Arduino), RXD to pin 5, TXD to pin 6 (because of using software serial) and PWKEY to pin 53. My code is as follows:</p>

<pre class="lang-c prettyprint-override"><code>#include&lt;SoftwareSerial.h&gt;
SoftwareSerial GPRS(5, 6);

int inputPinTempSensor = 0;
float tempCelsius = 0 ;
float thresholdTemp = 45;

void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate
  Serial.begin(9600);  // the Serial port of Arduino baud rate.
  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);
  delay(100);
}

void loop() {
  GPRS.print("AT+CREG/r");
  Serial.print(GPRS.read());
  delay(2000);
}
</code></pre>

<p>The AT command response should be something like "ok" but it's returning -1 for every loop waiting 2 seconds. Why and what could be the solution?</p>

<p><strong>Edit:</strong></p>

<p>Sorry for the mistakes. I was trying different ways with carriage return and new line characters to make it work. Now the code is:</p>

<pre class="lang-c prettyprint-override"><code>#include&lt;SoftwareSerial.h&gt;
SoftwareSerial GPRS(5, 6);

void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate
  Serial.begin(9600);  // the Serial port of Arduino baud rate.
  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);
  delay(2000);
  GPRS.println("AT+CREG");
}

void loop() {
  while(GPRS.available()){
    Serial.print(GPRS.read());
  }
}
</code></pre>

<p>Now it gives no responses at all. Actually after buying the module I was trying with <a href="https://github.com/Arduino-IN/demos/tree/master/GSM%2BArduino/Arduino-Code" rel="nofollow">these</a> examples and they were not working either. So, I thought to test if the AT commands were working properly. I could be a problem with my wiring too.</p>
 84: <p>I think there are 2 mistakes in your code:</p>

<p>First, you should ensure that the 3AT3 commands are termintaed by a new line character:</p>

<pre><code>GPRS.print("AT+CREG/r");
</code></pre>

<p>should be changed into:</p>

<pre><code>GPRS.println("AT+CREG/r");
</code></pre>

<p>or:</p>

<pre><code>GPRS.print("AT+CREG/r\n");
</code></pre>

<p>Nite that I am not sure why you added <code>/r</code> at the end of the AT command, is that supposed to be part of the command? If your intention was to force a new line, then you meant <code>\r</code> not <code>/r</code>, which is not really a new line character but a carriage return (that might be interpreted the same by yur GSM module, but not necessarily).</p>

<p>The the second mistake in your code, is directly calling <code>GPRS.read()</code> <strong>without</strong> first waiting for a character to be available; in this situation, <code>GPRS.read()</code> will always return <code>-1</code> as a specific value meaning "no available character to read".</p>

<p>So you should change your code to something like:</p>

<pre><code>// 1st wait for a character to be available
while (!GPRS.available()) {
}
// Then read all available characters and log them to Serial
while (GPRS.available()) {
    Serial.print(GPRS.read());
}
</code></pre>
 11763: <p>The correct AT command is <code>AT+CREG?\r</code>. A delay of at least 500ms is also advised after every command, though a timeout loop would be better. Since you didn't send any other commands, the modem will have no further responses for you and the Arduino will return -1 to any Serial.read()s, indicating there's nothing to be read.</p>
