Try this:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial(rxPin, txPin);
void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600); // setting baud to 9600
Serial.begin(9600);
}
void loop()
{
mySerial.write("AT\r\n");
char rcv;
while (mySerial.available()==0) // Sit in a loop awaiting some input
{
}
if(mySerial.available()) // Which it will be
{
rcv = mySerial.read();
Serial.print(rcv);
}
delay(1000);
}
It's just a modification of your code, not the way I would do it. It will only print out the first character of any response. You might also wish to consider printing out the ASCII value of what is received just in case it's a control character.