You may not have good satellite reception. Get closer to a window or go outside. The first fix can take 10 minutes or longer.
You should also try a sketch that displays what is coming from the GPS. A simple echo sketch can confirm that you have connected the device correctly:
#include <NeoSWSerial.h>
NeoSWSerial gpsPort(2, 3);
void setup()
{
Serial.begin(115200);
gpsPort.begin(9600);
}
void loop()
{
if (gpsPort.available())
Serial.write( gpsPort.read() );
}
If you see lines of text on the Serial Monitor window with $GPRMC and $GPGGA, the GPS device is connected correctly and the baud rate is correct.
You might be interested in my NeoGPS library. It is smaller, faster, more accurate and more reliable than all other libraries. Here is a NeoGPS version of the above sketch:
#include <NMEAGPS.h>
#include <NeoSWSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 6, 7, 8);
NeoSWSerial gpsPort(2, 3);
// --> AltSoftSerial on pins 8 & 9 would be better!
NMEAGPS GPS;
void setup()
{
Serial.begin(115200);
gpsPort.begin(9600);
GPS.send_P( &gpsPort, F("PGCMD,33,0") ); // Turn Off Antenna Update
GPS.send_P( &gpsPort, F("PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") ); // RMC & GGA only
GPS.send_P( &gpsPort, F("PMTK220,1000") ); // 1 Hz update rate
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print( F("Starting GPS") );
delay( 500 );
lcd.setCursor(0,0);
lcd.print( F("Wait for FIX-GPS") );
lcd.setCursor(0,1);
lcd.print( F("Approx. 45 sec") );
}
void loop() // run over and over again
{
if (GPS.available( gpsPort )) {
gps_fix fix = GPS.read();
if (fix.valid.altitude) {
lcd.setCursor(0,0);
lcd.print( F(" ") );
lcd.setCursor(0,1);
lcd.print( F(" ") );
lcd.setCursor(0,0);
lcd.print( F("Altitude= ") );
lcd.setCursor(0,1);
lcd.print( fix.altitude() );
Serial.println( fix.altitude() );
} else {
Serial.print( '.' );
}
}
}
If you'd like to try it, NeoGPS is available from the Ardino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.
Some speedometer projects that use NeoGPS:
GPS Nixie Speedometer
Gps speedometer
GPS Speedometer, problems when still
[GPS Speedometer] Slow display updates on Mode 3 Fix.
Adafruit Ultimate GPS, SSD1306 0.96" 128x64 OLED (Lengthy! Mostly timezone work after that post.)
GPS 7 Segment Speedometer
Pay special attention to Choosing Your Serial Port connection and the required level-shifting for safely connecting the 3.3V NEO-6M to your 5V Arduino.
Cheers,
/dev