Hey guys, I am trying to interface my SIM800 gsm module with my arduino MEGA to send or receive a text using hardware serial ports. Connected Tx of modem to Rx1 and Rx of modem to Tx1. checked my serial monitor and tried to send a text to my phone number but then it wouldnt send it. i don't want to use SoftwareSerial since I am already using a fingerprint sensor to interface that. What should I do?
here's my code:
void setup()
{
Serial.begin(9600); // Setting the baud rate of Serial1Monitor (Arduino)
Serial1.begin(38400); // Setting the baud rate of GSM Module
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (Serial1.available()>0)
Serial.write(Serial1.read());
}
void SendMessage()
{
Serial1.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
Serial1.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
Serial1.println("I am SMS from GSM");// The SMS text you want to send
delay(100);
Serial1.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
Serial1.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}
pylon:
Yes. But try first with above sketch and typing the commands on the Serial Monitor to see if you get errors from your GSM modem.
You mean the AT commands?
I tried that but there is no response in the serial window.
Should I type the commands as
AT+CMGF=1
"AT+CMGS="+91xxxxxxxxxx"\r" ?
Should I type the commands as
AT+CMGF=1
"AT+CMGS="+91xxxxxxxxxx"\r" ?
Yes, and the modem should answer with OK or something similar. Keep in mind that I chose 38400 for the baud rate to the PC too. So you have to configure your Serial Monitor to that.
Yes, and the modem should answer with OK or something similar. Keep in mind that I chose 38400 for the baud rate to the PC too. So you have to configure your Serial Monitor to that.
I tried it. there was no OK or error but whatever I typed appeared on the serial monitor