IOT

How to design an Arduino GPS Clock?

We are living in a technology-based society where we have lots of innovative ideas day by day. These new innovations in electronics projects come as an ever-growing network that strives constantly to share and gather insight on the latest trends in the industrial  Platform.

Many GPS satellites orbit the Earth and are used to know the exact location of any given area. It also provides other data, such as time, date, altitude, and direction tracking angle, in addition to the geographical coordinates (Latitude and Longitude). So we are going to make a GPS clock using the ‘Time and Date’ data from the GPS satellite. The GPS Updated Clock is extremely accurate, providing real-time data with millisecond precision. Here we use Blox NEO-M8N GPS Module in the Arduino GPS clock construction.

Hardware Required

  • Arduino Uno
  • U-Blox NEO-M8N GPS module
  • 16×2 LCD
  • Connecting wires
  • Power supply

Software Required

Global Positioning System

The GPS (Global Positioning System) is a satellite-based navigation system with at least 24 satellites.  Global Positioning System (GPS) makes use of signals sent by satellites in space and ground stations on Earth to accurately determine their position on Earth. The GPS receives radio frequency signals from satellites and ground stations. These signals are used by GPS to identify their precise location. With no subscription fees or setup charges, GPS works in any weather condition, anywhere in the world, 24 hours a day.

 U-Blox NEO-M8N GPS module 

This popular NEO-M8N is designed as a high Precision GPS Module. It comes with a Built-in Compass HMC5883L digital compass for APM and pixhawk. This module provides a high level of sensitivity and features active circuitry for the ceramic patch antenna. It is enclosed in a plastic case to protect the module from the elements. Also, the module outputs offer precise position updates at 10Hz and also have a rechargeable backup battery for warm starts. The Ublox NEO-M8N is configured to run at a baud rate of 38400 and can be used with Pixhawk and APM. Moreover, this popular neo-M8N is capable of connecting the same module to All versions of the PIXHAWK Flight Controller. 

The NEO-M8N features better performance and the easiest RF integration of all the NEO-M8 configurations. The NEO form factor allows for easy migration from previous NEO generations. Hence, the Sophisticated RF architecture and interference suppression ensure maximum performance even in GNSS-hostile environments. NEO-M8 combines a high level of robustness and integration capability with flexible connectivity options. Finally, the NEO-M8N consists of an internal Flash that allows simple firmware upgrades for supporting additional GNSS systems.

Features of U-Blox NEO-M8N GPS module 

  • Concurrent reception of up to 3 GNSS (GPS, Galileo, GLONASS, BeiDou).
  • industry-leading–167 dBm navigation sensitivity.
  • Security and integrity protection.
  • Onboard ROM memory.
  • Supports all satellite augmentation systems.
  • Advanced jamming and spoofing detectionBackward compatible with NEO-7, NEO-6, and NEO-5 families
  • The default baud rate: is 9600.
  • With a data backup battery.
  • Data-logger For position, velocity, and time

Arduino Clock Using UBlox NEO-M8M GPS Module

The GPS Clock is a satellite-based device that delivers extremely accurate timing. The GPS module also delivers time-related data, which we’ll employ to create an Arduino GPS clock.U-Blox NEO-M8M GPS Module outputs a large amount of data in serial format, which includes the precise location of the location. GPS also gives time and date information, as well as geographic coordinates (latitude and longitude). We’re also using an Arduino board to isolate the essential information from the GPS data.

The data from the GPS module is sent in NMEA format, as shown in the screenshot below. The NMEA format is made up of multiple sentences, one of which is required to extract the Date and Time. This statement begins with $GPRMC and includes the coordinates, time, and other relevant data. The string $GPRMC stands for Recommended minimum particular GPS/Transit data, and it’s around 70 characters long.

The data received by the UBlox NEO-M8M GPS module in NMEA format from several satellites is shown in the above image. There are multiple lines in this output, one of which begins with $GPRMC. 

Code To Receive GPS Time From $GPRMC String

$GPRMC,182306,A,1523.82,N,00022.24,W,173.8,231.8,110120,004.2,W*70
  • $GPRMC string mainly contains velocity, time, date, and position

The letter next to $ GPRMC in the above line stands for Coordinated Universal Time (UTC) (“hhmmss.ss”).

Next, the letter next to the UTC number indicates the status of the data.  

  • An ‘A’ means that you are receiving a signal and that everything is in order.
  • If you see a ‘V,’ that signifies your GPS isn’t connected to any satellites.
  • Your latitude and longitude are determined by the two numbers after the letter “A.”

The chart below will help you comprehend what the NMEA line above means.

IDENTIFIERDESCRIPTION
220516Time in hour minute seconds and milliseconds format.(h-m-s) 18-23-06
AStatus // A= Active and V= No signal
LatitudeLatitude 15 deg. 23.82 min. North
NDirection N=North, S=South
LongitudeLongitude(Co-ordinate)  22.24 min. West
WDirection E= East, W=West
Speed173.8 speed in knots
Angle231.8
DateDATE in UTC – 11/01/20
MVMagnetic Variation
WThe direction of variation E/W

By counting the commas in the string, we can extract Time and Date from $GPRMC. We locate the $GPRMC string and put it in an array using Arduino and programming, then Time (24-hour format) is found after one comma, and Date is found after nine commas. Strings are used to save time and date.

We must convert the time and date provided by a GPS satellite to Coordinated Universal Time (UTC). We added 5:30 to UTC time to convert to Indian time because Indian time is 5 and a half hours ahead of UTC/GMT.

.

Circuit Diagram:

The Arduino is in charge of the entire process; it receives GPS data from the satellite via the GPS module, extracts the Date and Time from the $GPRMC string, and displays it on the LCD.

Data pins D4, D5, D6, D7 of the 16×2 LCD are linked to Arduino pins 5, 4, 3, 2, and command pins RS and EN are connected to Arduino pins 7 and 6, respectively. Tx pin 10 of the GPS receiver module is connected to Rx pin 10 of the Arduino. The Arduino’s ground pin and the GPS are wired together. Here the GPS module is set with a baud rate of 9800 bits per second. Arduino is also set to a baud rate of 9800 bps.

Code For Arduino GPS Clock


#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

#include <SoftwareSerial.h>
SoftwareSerial Serial1(9, 10); // RX, TX

char str[70];
char *test=”$GPRMC”;
int temp,i;

void setup() 
{
  lcd.begin(16,2);
  Serial1.begin(9600);
  lcd.setCursor(0,0);
  lcd.print(“GPS Updated Clock”);
  lcd.setCursor(0,1);
  lcd.print(” Circuit Digest “);
  delay(300);
}

void loop()
{
  serial1Event();
  if (temp) 
  {
    lcd.clear();
    int str_lenth=i;
    int x=0,comma=0;
    String UTC_hour=””;
    String UTC_minut=””;
    String UTC_second=””;
    String UTC_date=””;
    String UTC_month=””;
    String UTC_year=””;
    String str1=””;
    while(x<str_lenth)
    {
     if(str[x]==’,’)
     comma++;
      if(comma==1)
      {
        x++;
        UTC_hour+=str[x++];
        UTC_hour+=str[x++];
        UTC_minut+=str[x++];
        UTC_minut+=str[x++];
        UTC_second+=str[x++];
        UTC_second+=str[x];
        comma=2;
      }

      if(comma==10)
      {
        x++;
          UTC_date+=str[x++];
          UTC_date+=str[x++];
          UTC_month+=str[x++];
          UTC_month+=str[x++];
          UTC_year+=str[x++];
          UTC_year+=str[x];
      }  
      x++;
    }

    int UTC_hourDec=UTC_hour.toInt();
    int UTC_minutDec=UTC_minut.toInt();
    int Second=UTC_second.toInt();
    int Date=UTC_date.toInt();
    int Month=UTC_month.toInt();
    int Year=UTC_year.toInt();

    int Hour=UTC_hourDec+5;
    if(Hour>23)
    {
     Hour-=24;
     Date+=1;
    }
    int Minut=UTC_minutDec+30;
    if(Minut>59)
    Minut-=60;
    
    
   // UTC_ind_zone_time
    lcd.clear();
    lcd.print(“Date: “);
    lcd.print(Date);
    lcd.print(“/”);
    lcd.print(Month);
    lcd.print(“/”);
    lcd.print(“20”);
    lcd.print(Year);
     
     lcd.setCursor(0,1);
     lcd.print(“Time: “);
     lcd.print(Hour);
    lcd.print(“:”);
    lcd.print(Minut);
    lcd.print(“:”);
    lcd.print(Second);
  //  delay(100);
    temp=0;
//    j=0;
    i=0;
    x=0;
    str_lenth=0;
//    k=0;
  }
 // delay(1000);
}

void serial1Event()
{
  while(1)
  {
   while (Serial1.available())            //checking serial data from GPS
   {
    char inChar = (char)Serial1.read();
     str[i]= inChar;                    //store data from GPS into str[]
     i++;
     if (i < 7)                      
     {
      if(str[i-1] != test[i-1])         //checking for $GPRMC sentence
      {
        i=0;
      }
     }
    if(i>65)
    {
     temp=1;
     break;
    }
  }
   if(temp)
    break;
  }
}

Conclusion

I hope all of you are clear about the design of the Arduino GPS clock..We MATHA ELECTRONICS will be back soon with more interesting topics.

Leave a Reply

Your email address will not be published. Required fields are marked *