Arduino Joystick Demo

 


 int joyPin1 = A0;                 // slider variable connected to analog pin 0
 int joyPin2 = A1;                 // slider variable connected to analog pin 1
 int value1 = 0;                  // variable to read the value from the analog pin 0
 int value2 = 0;                  // variable to read the value from the analog pin 1

 void setup() {
  pinMode(joyPin1, INPUT);              
  pinMode(joyPin2, INPUT); 
  Serial.begin(9600);
 }

 void loop() {
  value1 = analogRead(joyPin1);             
  value2 = analogRead(joyPin2);  

  delay(100);
  Serial.print("Pin1: ");
  Serial.print(value1);
  Serial.print(" Pin2: ");
  Serial.println(value2);
}

Source.

Arduino Serial Demo

void setup() {
  Serial.begin(9600);
}
int i = 1;
void loop() {
  Serial.println("Each line of code will be delayed by 1 second");
  delay(1000);
  Serial.println("Also, integer i will count upwards by one!");
  delay(1000);
  Serial.println(i);
  i = i+1;
}

Current Bogie Code *Change Port Definitions*

#define left1 32
#define left2 26
#define right2 30
#define right1 28
#define eLeft A8
#define eRight A9
//********************************************************************************************************************************************************************************************
#include <LiquidCrystal.h>
int lcd_key     = 0;
int adc_key_in  = 0;
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//********************************************************************************************************************************************************************************************
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;
//********************************************************************************************************************************************************************************************
int longitude, latitude;
//********************************************************************************************************************************************************************************************
void setup() {
  pinMode(right1, OUTPUT);
  pinMode(right2, OUTPUT);
  pinMode(left1, OUTPUT);
  pinMode(left2, OUTPUT);
  pinMode(eLeft, OUTPUT);
  pinMode(eRight, OUTPUT);  
  digitalWrite(eLeft, HIGH);
  digitalWrite(eRight, HIGH);
//********************************************************************************************************************************************************************************************
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println(0);
  delay(1000);
  pinMode(21, OUTPUT);
  digitalWrite (21, HIGH);
  pinMode(20, OUTPUT);
  digitalWrite (20, LOW);
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  lcd.print("Initializing GPS"); // print a simple message
}
bool clipped = 0;
//********************************************************************************************************************************************************************************************
void loop() {
  gpsBoi();
  clipped = 0;
}
//********************************************************************************************************************************************************************************************
void turnLeft(int speed){
  analogWrite(left2, speed);
  digitalWrite(left1, LOW);
  analogWrite(right1, speed);
  digitalWrite(right2, LOW);
}
//******************************
void turnRight(int speed){
  analogWrite(left1, speed);
  digitalWrite(left2, LOW);
  analogWrite(right2, speed);
  digitalWrite(right1, LOW);
}
//******************************
void moveForwards(int speed){
analogWrite(right1, speed);
digitalWrite(right2, LOW);
analogWrite(left1, speed);
digitalWrite(left2, LOW);
}
//******************************
void moveBackwards(int speed){
analogWrite(right2, speed);
digitalWrite(right1, LOW);
analogWrite(left2, speed);
digitalWrite(left1, LOW);
}
//******************************
void turn90right(){
  turnRight(150);
  delay(985);
}
void turn90left(){
  turnLeft(150);
  delay(985);
}
//******************************
void halt(){
digitalWrite(right2, LOW);
digitalWrite(right1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left1, LOW);
}
//******************************
void gpsBoi(){
    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");
        lcd.clear();
      }
      else{
        Serial.println("Your position is not valid.");
      }
      //lcd.clear();
      clearCoord();
      Serial.print("Date:");
      Serial.println(Date);
      Serial.print("UTCtime:");
      Serial.print(RMCUTCtime);
      Serial.print("   ");
      Serial.println(GGAUTCtime);
      Serial.print("Latitude:");
      Serial.print(RMClatitude);
      lcd.setCursor(0,0);
      lcd.print(latitude);
      Serial.print("   ");
      Serial.println(GGAlatitude);
      Serial.print("Longitude:");
      Serial.print(RMClongitude);
      lcd.setCursor(0,1);
      lcd.print(longitude);
      Serial.println("LONGITUDE THE REAL ONE");
      Serial.println(longitude);
      Serial.println("LATITUDE THE REAL ONE");
      Serial.println(latitude);
      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;
}
//******************************
void clearCoord(){
  if(clipped == 0){
    RMClatitude.remove(RMClatitude.length()-1);
    RMClongitude.remove(RMClongitude.length()-1);
    RMClatitude.remove(0,5);
    RMClongitude.remove(0,6);
    latitude = RMClatitude.toInt();
    longitude = RMClongitude.toInt();
  }
  clipped = 1;
  }

Rocker-Bogie GPS and Motor Control Code

#define left1 32
#define left2 26
#define right2 30
#define right1 28
#define eLeft A8
#define eRight A9
//********************************************************************************************************************************************************************************************
#include <LiquidCrystal.h>
int lcd_key     = 0;
int adc_key_in  = 0;
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//********************************************************************************************************************************************************************************************
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;
//********************************************************************************************************************************************************************************************
int longitude, latitude;
//********************************************************************************************************************************************************************************************
void setup() {
  pinMode(right1, OUTPUT);
  pinMode(right2, OUTPUT);
  pinMode(left1, OUTPUT);
  pinMode(left2, OUTPUT);
  pinMode(eLeft, OUTPUT);
  pinMode(eRight, OUTPUT);  
  digitalWrite(eLeft, HIGH);
  digitalWrite(eRight, HIGH);
//********************************************************************************************************************************************************************************************
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println(0);
  delay(1000);
  pinMode(21, OUTPUT);
  digitalWrite (21, HIGH);
  pinMode(20, OUTPUT);
  digitalWrite (20, LOW);
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  lcd.print("Initializing GPS"); // print a simple message
}
//********************************************************************************************************************************************************************************************
void loop() {
  gpsGet();
}
//********************************************************************************************************************************************************************************************
void turnLeft(int speed){
  analogWrite(left2, speed);
  digitalWrite(left1, LOW);
  analogWrite(right1, speed);
  digitalWrite(right2, LOW);
}
//******************************
void turnRight(int speed){
  analogWrite(left1, speed);
  digitalWrite(left2, LOW);
  analogWrite(right2, speed);
  digitalWrite(right1, LOW);
}
//******************************
void moveForwards(int speed){
analogWrite(right1, speed);
digitalWrite(right2, LOW);
analogWrite(left1, speed);
digitalWrite(left2, LOW);
}
//******************************
void moveBackwards(int speed){
analogWrite(right2, speed);
digitalWrite(right1, LOW);
analogWrite(left2, speed);
digitalWrite(left1, LOW);
}
//******************************
void turn90right(){
  turnRight(150);
  delay(985);
}
void turn90left(){
  turnLeft(150);
  delay(985);
}
//******************************
void haltyoudemon(){
digitalWrite(right2, LOW);
digitalWrite(right1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left1, LOW);
}
//******************************
void gpsGet(){
    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.");
      }
      lcd.clear();
      CoordNum();
      Serial.print("Date:");
      Serial.println(Date);
      Serial.print("UTCtime:");
      Serial.print(RMCUTCtime);
      Serial.print("   ");
      Serial.println(GGAUTCtime);
      Serial.print("Latitude:");
      Serial.print(RMClatitude);
      lcd.setCursor(0,0);
      lcd.print(RMClatitude);
      Serial.print("   ");
      Serial.println(GGAlatitude);
      Serial.print("Longitude:");
      Serial.print(RMClongitude);
      lcd.setCursor(0,1);
      lcd.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;
}
//******************************
void CoordNum(){
  RMClatitude.remove(RMClatitude.length()-1);
  RMClongitude.remove(RMClongitude.length()-1);
  latitude = RMClatitude.toInt();
  longitude = RMClongitude.toInt();
}

L293N Arduino Motor Control Code – Non-Variable Speed

//L293D
//Motor A
const int motorPin1  = 9;  // Pin 14 of L293
const int motorPin2  = 10;  // Pin 10 of L293
//Motor B
const int motorPin3  = 6; // Pin  7 of L293
const int motorPin4  = 5;  // Pin  2 of L293

//This will run only one time.
void setup(){
 
    //Set pins as outputs
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(motorPin3, OUTPUT);
    pinMode(motorPin4, OUTPUT);
    
    //Motor Control - Motor A: motorPin1,motorpin2 &amp;amp; Motor B: motorpin3,motorpin4

    //This code  will turn Motor A clockwise for 2 sec.
    analogWrite(motorPin1, 180);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 180);
    analogWrite(motorPin4, 0);
    delay(5000); 
    //This code will turn Motor A counter-clockwise for 2 sec.
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 180);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 180);
    delay(5000);
    
    //This code will turn Motor B clockwise for 2 sec.
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 180);
    analogWrite(motorPin3, 180);
    analogWrite(motorPin4, 0);
    delay(1000); 
    //This code will turn Motor B counter-clockwise for 2 sec.
    analogWrite(motorPin1, 180);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 180);
    delay(1000);    
    
    //And this code will stop motors
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 0);
  
}


void loop(){
  

}

Source code here.

L298N Arduino Control Code 2 Non-Variable Speed

/*  Arduino DC Motor Control - PWM | H-Bridge | L298N  -  Example 01
    by Dejan Nedelkovski, www.HowToMechatronics.com
*/
#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  // Set initial rotation direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}
void loop() {
  int potValue = analogRead(A0); // Read potentiometer value
  int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
  analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
  // Read button - Debounce
  if (digitalRead(button) == true) {
    pressed = !pressed;
  }
  while (digitalRead(button) == true);
  delay(20);
  // If button is pressed - change rotation direction
  if (pressed == true  &amp;amp; rotDirection == 0) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 1;
    delay(20);
  }
  // If button is pressed - change rotation direction
  if (pressed == false &amp;amp; rotDirection == 1) {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    rotDirection = 0;
    delay(20);
  }
}

 

Source code available here.

Arduino OSEPP LCD Display 16×2 Sample Code

//Sample using LiquidCrystal library
#include &lt;LiquidCrystal.h&gt;
 
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in &gt; 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (adc_key_in &lt; 50)   return btnRIGHT; 
 if (adc_key_in &lt; 195)  return btnUP;
 if (adc_key_in &lt; 380)  return btnDOWN;
 if (adc_key_in &lt; 555)  return btnLEFT;
 if (adc_key_in &lt; 790)  return btnSELECT;  
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
 lcd.print("Push the buttons"); // print a simple message
}
  
void loop()
{
 lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(millis()/1000);      // display seconds elapsed since power-up
 
 
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print("RIGHT ");
     break;
     }
   case btnLEFT:
     {
     lcd.print("LEFT   ");
     break;
     }
   case btnUP:
     {
     lcd.print("UP    ");
     break;
     }
   case btnDOWN:
     {
     lcd.print("DOWN  ");
     break;
     }
   case btnSELECT:
     {
     lcd.print("SELECT");
     break;
     }
     case btnNONE:
     {
     lcd.print("NONE  ");
     break;
     }
 }
 
}

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