hi,
i tried to take phone number from incoming SMS from serial data of GSM Module 800 with arduino.
But i have not getting success .
here is my code
#include <SoftwareSerial.h>
SoftwareSerial SIM900A(11, 10);
#include <Wire.h>
// Array to hold the number a SMS is retreived from
const byte numChars = 30;
char receivedChars[numChars];
boolean newData = false;
char tempChars[numChars];
void setup()
{
SIM900A.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
Serial.println ("SIM900A Ready");
delay(1000);
Serial.println ("Type s to send message or r to receive message");
SIM900A.println("AT+CMGF=1");
delay(500);
SIM900A.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
}
void loop()
{
if (SIM900A.available() > 0)
Serial.write(SIM900A.read());
strcpy(tempChars, receivedChars);
recvWithEndMarker();
showNewData();
if (Serial.available() > 0)
switch (Serial.read())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
}
void RecieveMessage()
{
Serial.println ("SIM900A Membaca SMS");
delay (4000);
SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(500);
//Serial.write ("Unread Message done");
}
void SendMessage()
{
Serial.println ("Sending Message");
SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000);
SIM900A.println("AT+CMGS=\"+917987553768\"\r"); //Mobile phone number to send message*/
delay(1000);
SIM900A.println("hipp");// Messsage content
delay(1000);
SIM900A.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void recvWithEndMarker()
{
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (SIM900A.available() > 0 && newData == false) {
rc = SIM900A.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars)
{
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
Serial out will be "This Justin......+CMT: "+91798755xx68","","21/12/13,18:32:56+22" Hfd
But iam getting the out put is This just in ... +979855768,","2/1/131832:7+2" H
Note:-I have made this program compile the other two program available in forum's old conversation and tutorials
where will be the problem ..please advice me......