need basic codes for GSM and GPS module
hello,
how can interface gsm module (sim 900a) , gps module (reb-1315s4) on single arduino uno?
from should start , how can programming?
can 1 pass me code send , receive message , check longitude , latitude?
thanx
how can interface gsm module (sim 900a) , gps module (reb-1315s4) on single arduino uno?
from should start , how can programming?
can 1 pass me code send , receive message , check longitude , latitude?
thanx
heres little sketch wrote send , receive texts sim900 shield or communicate via @ commands. , bonus, if text + turns on light , - turns off. might start pull from. luck.
code: [select]
#include <softwareserial.h>
#include <string.h>
softwareserial gsmserial(7, 8);
int num[10];
unsigned char text[300];
char mess[300];
char choice;
string message = "";
string phone = "";
string received = "";
string str= "";
int count = 0;
int = 0;
boolean light = true;
int relaypin = 13;
void setup()
{
serial.begin(9600);
gsmserial.begin(19200);
pinmode(relaypin, output);
}
void loop()
{
if(gsmserial.available()) // if date comming softwareserial port ==> data comming gsmserial shield
{
while(gsmserial.available()) // reading data char array
{
text[count]=gsmserial.read(); // writing data array
//serial.print(text[count]); // debug
if(text[count] == '"') i++;
if(i >= 6 && text[count] != '"')
{
if((char)text[count] == '+') light = true;
if((char)text[count] == '-') light = false;
received += (char)text[count];
}
if(count == 300)break;
count++;
}
serial.println(received);
serial.println(light);
digitalwrite(relaypin, light);
received = "";
serial.write(text,count); // if no data transmission ends, write text hardware serial port
cleartextarray(); // call cleartextarray function clear storaged data array
count = 0; // set counter of while loop zero
i = 0;
}
//serial.println(received);
if (serial.available())
{
while(serial.available()) // reading data char array
{
text[count]=serial.read();
if(text[count] == '~')
{
text[count]=null; serial.flush(); count = 0; function();
}
count++;
if(count == 300)break;
}
gsmserial.write(text,count); // if no data transmission ends, write text hardware serial port
cleartextarray(); // call cleartextarray function clear storaged data array
count = 0; // set counter of while loop zero
}
}
void function()
{
int bytes_read = 0;
serial.print("send text(s) or exit(x): ");
while(bytes_read < 1)
{
if(serial.available() > 0)
{
choice = serial.read();
}
switch(choice)
{
case 's': serial.println(choice); bytes_read++; choice = ' '; sendtextmessage();
break;
case 'x': serial.println("at command mode"); bytes_read++;
break;
bytes_read++;
}
choice = ' ';
}
}
void setnumber()
{
serial.print("enter phone number: ");
int bytes_read = 0;
while (bytes_read < 10) //amount of numbers read - corresponds array decleration , print loop
{
//serial.println(num[bytes_read]); //debug
//serial.println("number"); //debug
if(serial.available()>0)
{
num[bytes_read] = serial.read() - 48; //its adds 48 it? dont know
phone += num[bytes_read];
//serial.print(num[bytes_read]); //debug
//serial.print("num[]"); //debug
bytes_read ++;
}
}
}
void printnumber()
{
serial.println(phone);
}
void setmessage()
{
serial.print("type message: ");
int bytes_read = 0;
boolean done = false;
while (done == false) //amount of numbers read - corresponds array decleration , print loop
{
//serial.println("message"); //debug
if (serial.available() > 0)
{
mess[bytes_read] = serial.read();
if(mess[bytes_read] == '~')
{
done = true;
}
if(mess[bytes_read] != '~')
{
message += mess[bytes_read];
}
bytes_read ++;
}
}
}
void printmessage()
{
for(int = 0; < 300; i++)
if(mess[i] != '~')
{
serial.print(mess[i]);
}
serial.println(" ");
}
void sendtextmessage()
{
setnumber();
printnumber();
setmessage();
printmessage();
gsmserial.println("at+cmgf=1"); //because want send sms in text mode
delay(100);
string str = "";
str += "at+cmgs = \"+1";
str += phone;
str += "\"";
gsmserial.println(str);
delay(100);
//serial.println(message); //the content of message
gsmserial.println(message); //the content of message
delay(150);
gsmserial.println((char)26); //the ascii code of ctrl+z 26
delay(200);
serial.println("message sent!");
phone = "";
message = "";
clearmessage();
serial.flush();
gsmserial.flush();
}
void cleartextarray() // function clear text array
{
for (int i=0; i<300;i++)
{ text[i]=null;} // clear index of array command null
}
void clearmessage()
{
for (int i=0; i<300;i++)
{ mess[i]=null;}
}
//void receivetextmessage()
//{
//
// char incoming[300];
// serial.println("checking messages");
// int bytes_read = 0;
// boolean finished = false;
// gsmserial.println("at+cnmi=2,2,0,0,0"); //"at+cmgr=1"
// if(gsmserial.available())
// {
// while(gsmserial.available())
// {
// incoming[bytes_read] = gsmserial.read();
// delay(20);
// received += incoming[bytes_read];
// incoming[bytes_read] = null;
// bytes_read++;
// }
//
// //serial.println(bytes_read);
// }
//
// serial.println(received);
//
// choice = ' ';
// received = "";
// message = "";
// function();
//}
Arduino Forum > Using Arduino > Project Guidance > need basic codes for GSM and GPS module
arduino
Comments
Post a Comment