Arduino MEGA2560 to Drive U-BLOX NEO-6M GPS Module

1) )Objective:

Use Arduino Mega2560 to get Latitude ,longitude and altitude from U-BLOX NEO-6M GPS module

2)Parts
1 x Arduino Mega2560 board

1 x U-BLOX NEO-6M GPS module

459px-GPSEZ3

3) About U-BLOX NEO-6M GPS module

The module uses U-BLOX NEO-6M module.The module comes with high-performance ceramic antenna, which is equival of the integrated active antenna.Module comes with EEPROM. All configuration information can be stored in the EEPROM. A variety of configurations to meet your needs.The module also comes with a rechargeable backup battery (to support warm or warm start. after the main power supply power off, back-up battery power can maintain a half hour for GPS receiver data stored).

Features

  • Use U-BLOX NEO-6M modular, compact, and excellent performance.
  • Comes with ceramic antenna, capability of searching star is quite good.
  • You can set various parameters via the serial port, and can be stored in the EEPROM, and easy to use.
  • Compatible with 3.3V / 5V level, for easy connection to a variety of microprocessor systems.
  • built-in rechargeable backup battery, can retentive ephemeris data

Technical Parameters

Parameters Value
Power Supply 3V/5V
Model GPS-NEO-6M-001
Antenna ceramic antenna
Battery rechargeable battery back-up
Signal light LED light
Antenna size 25*25mm
Model size 25.5mm*31.5mm
Mounting Hole 2mm
The default baud rate 9600
The default output Compatible with NMEA0183 protocol

Notice

  • Outdoor use
  • Note Lightning and waterproof
  • Do not support Raspberry Pi 3 B (Because of RPi 3B’s serial port problem, it may have other solution)

4) Circuit connection and graph

mega2560 GPS Module
5V VCC
GND GND
RX1(19) TXD
TX1 (18) RXD

gpsgrgrbvggr

4) Source code:

 
String data="";
int mark = 0;
boolean Mark_Start=false;
boolean valid=false;
String GGAUTCtime,GGAlatitude,GGAlongitude,GPStatus,SatelliteNum,HDOPfactor,Height,
PositionValid,RMCUTCtime,RMClatitude,RMClongitude,Speed,Direction,Date,Declination,Mode;
void setup(){
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println(0);
  delay(1000);
}

void loop(){
  while (Serial1.available()> 0){
    if(Mark_Start){
      data=reader();
      Serial.println(data);
      if(data.equals("GPGGA")){
        //Serial.println(1);
        GGAUTCtime=reader();
        GGAlatitude=reader();
        GGAlatitude+=reader();
        GGAlongitude=reader();
        GGAlongitude+=reader();
        GPStatus=reader();
        SatelliteNum=reader();
        HDOPfactor=reader();
        Height=reader();
        Mark_Start=false;
        valid=true;
        data="";

      }
      else if(data.equals("GPGSA")){
        Serial.println(2);
        Mark_Start=false;
        data="";
      }
      else if(data.equals("GPGSV")){
        Serial.println(3);
        Mark_Start=false;
        data="";
      }
      else if(data.equals("GPRMC")){
        //Serial.println(4);
        RMCUTCtime=reader();
        PositionValid=reader();
        RMClatitude=reader();
        RMClatitude+=reader();
        RMClongitude=reader();
        RMClongitude+=reader();
        Speed=reader();
        Direction=reader();
        Date=reader();
        Declination=reader();
        Declination+=reader();
        Mode=reader();
        valid=true;
        Mark_Start=false;
        data="";
      }
      else if(data.equals("GPVTG")){
        Serial.println(5);
        Mark_Start=false;
        data="";
      }
      else{
        Serial.println(6);
        Mark_Start=false;
        data="";
      }
    }
    if(valid){
      if(PositionValid=="A"){
        Serial.println("Position Valid");
      }
      else{
        Serial.println("Your position is not valid.");
      }
      Serial.print("Date:");
      Serial.println(Date);
      Serial.print("UTCtime:");
      Serial.print(RMCUTCtime);
      Serial.print("   ");
      Serial.println(GGAUTCtime);
      Serial.print("Latitude:");
      Serial.print(RMClatitude);
      Serial.print("   ");
      Serial.println(GGAlatitude);
      Serial.print("Longitude:");
      Serial.print(RMClongitude);
      Serial.print("   ");
      Serial.println(GGAlongitude);
      Serial.print("GPStatus:");
      Serial.println(GPStatus);
      Serial.print("SatelliteNum:");
      Serial.println(SatelliteNum);
      Serial.print("HDOPfactor:");
      Serial.println(HDOPfactor);
      Serial.print("Height:");
      Serial.println(Height);
      Serial.print("Speed:");
      Serial.println(Speed);
      Serial.print("Direction:");
      Serial.println(Direction);
      Serial.print("Declination:");
      Serial.println(Declination);
      Serial.print("Mode:");
      Serial.println(Mode);     
      valid=false;
    }
    if(Serial1.find("$")){
      Serial.println("capture");
      Mark_Start=true;
    }
  }

}

String reader(){
  String value="";
  int temp;
startover:
  while (Serial1.available() > 0){
    delay(2);
    temp=Serial1.read();
    if((temp==',')||(temp=='*')){
      if(value.length()){
        //Serial.println("meaningful message");
        return value;
      }
      else {
        //Serial.println("empty");
        return "";
      }     
    }
    else if(temp=='$'){
      //Serial.println("failure");
      Mark_Start=false;
    }
    else{
      //Serial.println("add");
      value+=char(temp);
    }
  }
  while (!(Serial1.available()>0)){
  }
  goto startover;
}

5) Result:

Bring U-BLOX NEO-6M GPS module outdoor, open serial monitor window in Arduino IDE(upper right corner)

You will see following data information:

GPS1111