There are different ways to build an Arduino based real time clock, one of the ways is using a real time clock chip (like: DS1302, DS1307, DS3231 …) and another way is by using a GPS module. The GPS based clock receives time from satellites and automatically sets its time. This topic shows how to build an Arduino GPS clock with NEO-6M GPS module where time and date are displayed on 16×2 LCD screen.
Related Projects:
Last time I made a simple interfacing of Arduino with NEO-6M GPS module in order to get position, time, date and speed, project page link is below:
Interfacing Arduino with NEO-6M GPS module
Arduino GPS clock with local time using NEO-6M module
and the links below shows how to build a real time clock using Arduino and RTC chips:
Arduino real time clock with DS1307
Arduino and DS3231 real time clock
Hardware Required:
To build this project the following components are needed:
- Arduino (or compatible) board
- NEO-6M GPS module
- 16×2 LCD screen
- 10k ohm variable resistor (or potentiometer)
- 330 ohm resistor
- Breadboard
- Jumper wires
Arduino GPS real time clock with NEO-6M module circuit:
Project circuit diagram is shown below.
NEO-6M GPS module has 4 pins where:
NEO-6M GPS board GND pin goes to Arduino GND
TX pin goes to Arduino digital pin 9
RX pin is not connected
VCC pin goes to Arduino 5V pin (can be connected to 3.3V pin)
The 1602 LCD screen is used to display the real time clock time and date where:
RS —> Arduino digital pin 2
E —> Arduino digital pin 3
D4 —> Arduino digital pin 4
D5 —> Arduino digital pin 5
D6 —> Arduino digital pin 6
D7 —> Arduino digital pin 7
VSS, RW, D0, D1, D2, D3 and K are connected to Arduino GND (ground)
VEE to the variable resistor (or potentiometer) output
VDD to Arduino 5V and A to Arduino 5V through 330 ohm resistor
VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.
Arduino GPS clock code:
The Arduino code below uses TinyGPS++ library, it can be downloaded from the link below. After downloading the library, unzip the folder and add it to Arduino libraries folder (for example: C:\Program Files\Arduino\libraries). You should rename the folder “TinyGPSPlus”.
TinyGPS++ Library — direct link
Full Arduino code is below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
// Arduino GPS real time clock with NEO-6M GPS module #include <TinyGPS++.h> // Include TinyGPS++ library #include <SoftwareSerial.h> // Include software serial library #include <LiquidCrystal.h> // Include LCD library TinyGPSPlus gps; #define S_RX 9 // Define software serial RX pin #define S_TX 8 // Define software serial TX pin SoftwareSerial SoftSerial(S_RX, S_TX); // Configure SoftSerial library // LCD module connections (RS, E, D4, D5, D6, D7) LiquidCrystal lcd(2, 3, 4, 5, 6, 7); byte last_second; char Time[] = "TIME:00:00:00"; char Date[] = "DATE:00/00/2000"; void setup(void) { SoftSerial.begin(9600); // set up the LCD's number of columns and rows lcd.begin(16, 2); lcd.setCursor(0, 0); lcd.print(Time); // Display time lcd.setCursor(0, 1); lcd.print(Date); // Display calendar } void loop() { while (SoftSerial.available() > 0) { if (gps.encode(SoftSerial.read())) { if (gps.time.isValid()) { Time[5] = gps.time.hour() / 10 + 48; Time[6] = gps.time.hour() % 10 + 48; Time[8] = gps.time.minute() / 10 + 48; Time[9] = gps.time.minute() % 10 + 48; Time[11] = gps.time.second() / 10 + 48; Time[12] = gps.time.second() % 10 + 48; } if (gps.date.isValid()) { Date[5] = gps.date.day() / 10 + 48; Date[6] = gps.date.day() % 10 + 48; Date[8] = gps.date.month() / 10 + 48; Date[9] = gps.date.month() % 10 + 48; Date[13] =(gps.date.year() / 10) % 10 + 48; Date[14] = gps.date.year() % 10 + 48; } if(last_second != gps.time.second()) { last_second = gps.time.second(); lcd.setCursor(0, 0); lcd.print(Time); // Display time lcd.setCursor(0, 1); lcd.print(Date); // Display calendar } } } } |
The following video shows how a hardware circuit should work (UTC time):
this module we need to connect to the Internet?
No need for an internet connection.
The Arduino is getting the time from the GPS unit.
It is reading the data from the GPS unit (line 37) through a serial connection (connected to pins 8 and 9) then extracting the time and date from that GPS data (lines 39 thru 55).
Your wiring diagram shows connection from the GPS to the Arduino on Digital pin 9 but your text description says “TX pin goes to Arduino digital pin 4 “. The code is written for pin 9 so I guess it’s just a typo.
Yes you’re right, now it’s corrected.
Thank you.
Thank you for your clear tutorial and code. It works well.
Very good but, my watch is showing 3 hours early, for example, 14:00 is showing 17:00; Brazil is -3 hours. Thank you
This project may help you:
https://simple-circuit.com/arduino-gps-clock-local-time-neo-6m/
Yes, I’m doing this in the 16×2 display sketch; I changed the Time Zone as follows:
from: #define time_offset 3600
to: #define time_offset -7200 (Brazil -3) but nothing is changing on the display.
What about 3rd and 4th rows?
I want to adapt the code “Arduino GPS clock with local time using NEO-6M module” in the sketch “Arduino GPS real time clock with NEO-6M module” for the Display 16×2 because I need to change the Timezone in Display 16×2.
OK it worked; thank you very much
I need a little help
I’m working on a project for a local church.
It is necessary to ring the bells every day at 7 am and 7 pm.
The bells are connected with relay.
What I need to add to code to turn on the relay at 7 am and 7 pm.
Hi,
can we use other GPS receiver as G-STAR IV BR355S4
The LCD does not seem to display any thing other than back light.
I ddnt put a 10k Pot
Does the above code also apply to Ublox M8N GPS module …?