使用Arduino和GSM的GPS跟踪器

问题描述

我目前正在制作GPS追踪器。我正在使用SIM900A迷你GSM模块,NEO 6m GPS模块和arduino nano。我想通过GSM模块发送位置信息。

我使用的代码在串行监视器上没有任何输出,但是Arduino和GSM指示灯闪烁。我的联系如下:

GSM --- ARDUINO 5VR --- D9 5VT --- D8 GND --- GND VCC --- VCC

ARDUINO --- GPS 5V--VCC GND--接地 D5 --- TX D6 --- RX

草图如下:

#include <NeoSWSerial.h>
#include <AltSoftSerial.h>

// GPS
#include <TinyGPS.h>

// GSM
static const int RXPin = 8,TXPin = 9;
AltSoftSerial SIM900A(RXPin,TXPin);

static const int RXP = 5,TXP = 6;
NeoSWSerial mySerial(RXP,TXP);
TinyGPS gps;

void setup()
{
Serial.begin(9600);
SIM900A.begin(9600);
SIM900A.println("AT+CNMI=2,2,0");
mySerial.begin(9600);
delay(1000);
}

void loop()
{
bool newdata = false;
String buffer = readSIM900A();
if(SIM900A.available() > 0)
  Serial.println(SIM900A.read());
if (buffer.startsWith("\r\n+CMT: "))
{
    // printing the number
    Serial.println(buffer.substring(9,22)); 

    // Remove first 51 characters
    // buffer.remove(0,51);
    int len = buffer.length();
    // Remove \r\n from tail
    // buffer.remove(len - 2,2);
    // printing message
    Serial.println(buffer.substring(51,len-2));
    if (buffer.substring(51,len-2) == "location")
    {
      Serial.println("Sending location");

      // GPS
      if (mySerial.available()) 
      {
         char c = mySerial.read();
         if (gps.encode(c)) 
         {
            newdata = true;
         }
      }
      if (newdata)
      {
        long int lat,lon;
        unsigned long age,age1,date,time,chars;

        gps.get_position(&lat,&lon,&age);
        gps.get_datetime(&date,&time,&age);
        Serial.print("Lat/Long(10^-5 deg): ");
        Serial.print(lat);
        Serial.print(",");
        Serial.print(lon); 
        Serial.print(" Fix age: "); 
        Serial.print(age); Serial.println("ms.");

        Serial.print("Date(ddmmyy): "); Serial.print(date); Serial.print("Time(hhmmsscc):");
        Serial.print(time);
        Serial.print(" Fix age: "); Serial.print(age); 
        Serial.println("ms.");

        Serial.print("Alt(cm): "); Serial.print(gps.altitude());
        Serial.print(" Speed(mps): "); Serial.print(gps.f_speed_mps());

        // setting GSM module
        SIM900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
        delay(1000);  // Delay of 1000 milli seconds or 1 second
        // sending location from which code word had come
        SIM900A.println("AT+CMGS=\"" + buffer.substring(9,22) + "\"\r"); // 
        //Replace x with mobile number
        Serial.println("AT+CMGS=\"" + buffer.substring(9,22) + "\"\r");
        delay(1000);

        SIM900A.print("Lat/Long(10^-5 deg): ");
        SIM900A.print(lat);
        SIM900A.print(",");
        SIM900A.print(lon); 
        SIM900A.print(" Fix age: "); 
        SIM900A.print(age); SIM900A.println("ms.");

        SIM900A.print("Date(ddmmyy): "); SIM900A.print(date); 
        SIM900A.print(" Time(hhmmsscc): ");
        SIM900A.print(time);
        SIM900A.print(" Fix age: "); SIM900A.print(age); 
        SIM900A.println("ms.");

        SIM900A.print("Alt(cm): "); SIM900A.print(gps.altitude());
        SIM900A.print(" Speed(mps): "); SIM900A.print(gps.f_speed_mps());

        SIM900A.println((char)26);// ASCII code of CTRL+Z
        delay(1000);
      }
    }
    }
    delay(100);
   }

 String readSIM900A()
{
String buffer;

while (SIM900A.available())
{
    char c = SIM900A.read();
    buffer.concat(c);
    delay(10);
}

return buffer;
}

当arduino和gps连接在一起时,它们似乎工作正常。但是,集成提到的所有组件似乎并没有给我任何输出。感谢您的帮助,因为我对此几乎不了解。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)