Saturday, 12 September 2015

Arduino With GPS SKM53

    GPS WITH ARDUINO MEGA 2560

Sebarang pertanyaan/pembelian/bantuan boleh dm saya dia twitter eh:


1. Where to buy this SKM53 GPS ?



Memang dari kedai beli SKM53 ni akan dapat cam ni je. Kaki dia tak ngam dengan breadboard & jumper cable. Kena beli jumper cable lain sikit dari biasa.










So, i solder this component with jumper cable.













This how to connect SKM53 to Arduino



VCC >  +5V
Gnd > Gnd
TX > digital pin 10
RX > digital pin 11

Lets go to the next steps.


Software

In this test i use TinyGPS and SoftwareSerial library. I've make a little bit changes with original code to make user easier to search their current position in Google Map.


Download Link

TinyGPS Library

Arduino Code






Arduino Code

Just copy and paste this code! Make sure you have added TinyGPS library first.
Check my older post (under ultrasonic sensor post) for tutorial adding library to Arduino IDE!


#include <SoftwareSerial.h>
#include <TinyGPS.h>   //include library

long lat, lon;

SoftwareSerial gpsSerial(10, 11);  //connect Tx and Rx pin on digital 10 and 11
TinyGPS gps;

void setup() {
  Serial.begin(9600);    //baud rate with serial monitor
  gpsSerial.begin(9600);  //GPS baud rate
}
void loop() {
  while (gpsSerial.available()) {      ///kalau GPS available, Arduino akan mula read
    if (gps.encode(gpsSerial.read()))  ///Encode signal dari GPS
    {
      gps.get_position(&lat, &lon);     ///lepas Arduino encode signal GPS, baru akan dapatkan global position
      float real_lat = (lat/1000000.000);   //divide by 1m to make user easier to get their current global postion
      float real_lon = (lon/1000000.000);
      Serial.print("google: ");
      Serial.print(real_lat);   //print latitude on Serial monitor (in two decimal places)
      Serial.print(", ");
      Serial.println(real_lon); //print longitude on serial monitor (in two decimal places)
      //////////////////////////////////////////////////////////////////////////////////////////////////
      Serial.print("Position: ");
      Serial.print("lat: ");
      Serial.print(lat);
      Serial.print(" ");
      Serial.print("lon: ");
      Serial.println(lon);
    }
  }
}




Code Explaination


#include <TinyGPS.h> 
-include TinyGPS library.

SoftwareSerial gpsSerial(10, 11);
-communication between arduino and skm53 on pin digital 10 and 11.

Serial.begin(9600);    
-baud rate with serial monitor

gpsSerial.begin(9600);
-GPS baud rate

while (gpsSerial.available())
-check if GPS available

if (gps.encode(gpsSerial.read()))
-encode GPS signal

gps.get_position(&lat, &lon);
-get the position

 float real_lat = (lat/1000000.000);
-convert latitude in two decimal places to make user easier search their curent global postion

 float real_lon = (lon/1000000.000);
-convert longitude in two decimal places to make user easier search their curent global postion

Serial.print(real_lat);
-print latitude on serial monitor

 Serial.println(real_lon);
-print longitude on serial monitor

No comments:

Post a Comment