Gps speedometer

Hae ,arduino community.I was working on a gps speedometer project but was unable to add a warning alarm or led when the vehicle attain a certain speed eg 70 km/h.Can someone asisst me on this issue .
here is my code;

#include <TinyGPS.h>
#include <SoftwareSerial.h>
SoftwareSerial GPS(2,3); // configure software serial port

// Create an instance of the TinyGPS object
TinyGPS shield;

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.print("tronixstuff.com");
GPS.begin(9600);
delay(1000);
lcd.clear();
}

// The getgps function will interpret data from GPS and display on serial monitor
void getgps(TinyGPS &gps)
{
int year;
byte month, day, hour, minute, second, hundredths, kmh, mph;
shield.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);

// Print data and time
lcd.setCursor(0,0);
kmh=gps.f_speed_kmph();

lcd.print(kmh, DEC);
lcd.print(" km/h ");
/*
mph = kmh * 1.6;
lcd.print(mph, DEC);
lcd.print(" MPH ");
*/
}

void loop()
{
byte a;
if ( GPS.available() > 0 ) // if there is data coming from the GPS shield
{
a = GPS.read(); // get the byte of data
if(shield.encode(a)) // if there is valid GPS data...
{
getgps(shield); // then grab the data and display it on the LCD
}
}
}

Have your getgps function return the speed (kmh). Compare the kmh returned by getgps to your threshold speed.
This will give the idea:

float getgps(TinyGPS &gps)  // assuming float here?
{
  int year;
  byte month, day, hour, minute, second, hundredths, kmh, mph;
  shield.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
  lcd.setCursor(0,0);
  kmh=gps.f_speed_kmph();
  lcd.print(kmh, DEC);
  lcd.print(" km/h      ");
  return kph;
}

// then

if(getgps() > 70) 
{
   // sound alarm, light indicator
}

This doesn't answer your question, but I though I aught to point out:

I know that it is commented out, but your conversion from kph to mph is wrong.

mph = kmh * 1.6;

You need to divide by 1.6, not multiply by 1.6.

It's nice to see the correct loop structure for a GPS program! So many examples are incorrect, and they break when you try to add something. A suggestion for the 70kph speed limit is in the code section below. Before that...

I would suggest using something besides SoftwareSerial. It is very inefficient because it disables interrupts for long periods of time. This can interfere with your sketch or with other libraries. You may notice some delays while the LCD is being updated.

The best choice is to connect your GPS to HardwareSerial (i.e., the Serial object). It doesn't look like you're using it for debug prints, so you might consider that. You would have to disconnect the GPS when uploading, however.

The 2nd best choice is to use AltSoftSerial. It is very efficient, but it only works on pins 8 & 9 (of an UNO). Unfortunately, those pins are used for the LCD.

The 3rd best choice is my NeoSWSerial library. It is almost as efficient, and it works on any two pins (i.e., 2 & 3 in your sketch). It supports baud rates 9600, 19200 and 38400, so you could use it for the GPS device.

The absolute worst choice is SoftwareSerial. It works at all baud rates, on any two pins.

I also wrote the smallest, fastest and most accurate GPS library, NeoGPS. NeoGPS can be configured to only parse the fields you really use (i.e., speed and time). Everything else is quickly skipped. Here's a NeoGPS version of your sketch, with the speed limit test:

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

#include <NMEAGPS.h>
#include <NeoSWSerial.h>
NeoSWSerial gpsSerial(2,3);
NMEAGPS gps;

const int WARNING_LED = 13;

void setup()
{
  pinMode( WARNING_LED, OUTPUT );

  lcd.begin(16, 2);
  lcd.clear();
  lcd.print( F("tronixstuff.com") ); // F macro saves RAM!
  gpsSerial.begin(9600);
  delay(1000);
  lcd.clear();  
}

void printTime( NeoGPS::time_t & time )
{
  if (time.hours < 10)
    lcd.print( '0' );
  lcd.print( time.hours );
  if (time.minutes < 10)
    lcd.print( '0' );
  lcd.print( time.minutes );
  if (time.seconds < 10)
    lcd.print( '0' );
  lcd.print( time.seconds );

} // printTime


void displayGPS( gps_fix & fix )
{
  int kmh = 0;

  // Print speed
  lcd.setCursor(0,0);
  if (fix.valid.speed && (fix.spd.whole > 5)) {
    kmh = (fix.spd.whole * 185) / 100;
  }
  lcd.print( kmh );
  lcd.print( F(" km/h      ") );

  if (kmh > 70)
    digitalWrite( WARNING_LED, HIGH );
  else
    digitalWrite( WARNING_LED, LOW );

  // Print time
  if (fix.valid.time) {
    printTime( fix.dateTime );
  }
} // displayGPS

void loop()
{
  while (gps.available( gpsSerial )) {  // if there is data coming from the GPS shield
    gps_fix fix = gps.read();           // get the complete fix structure
    displayGPS( fix );                  // Show pieces of the fix on the LCD
  }
}

Notice that the GPS speed is calculated with integer values, not floating-point numbers. The TinyGPS library uses floats, so this is much faster and uses much less program space. It also checks for a minimum speed value to display. Below 5kph, the speed will jump around to different small values.

The original sketch used 7818 bytes of program space and 347 bytes of RAM.
The NeoGPS version uses 6536 bytes of program space and 196 bytes of RAM, a significant savings.

If you want to display the local time instead of the UTC (GMT) time, the NeoGPS time structure is easy to shift. Just add these lines of code, and print localTime instead of fix.dateTime:

    // Print time
    if (fix.valid.time) {

      NeoGPS::clock_t seconds = fix.dateTime;

      // Set these values to the offset of your timezone from GMT
      const int32_t         zone_hours   = -5L; // EST
      const int32_t         zone_minutes =  0L; // usually zero
      const NeoGPS::clock_t zone_offset  = (zone_hours * 60 + zone_minutes) * 60;

      // Adjust for local time
      NeoGPS::time_t localTime( seconds + zone_offset );

      printTime( localTime );
    }

The NMEAtimezone.ino example program shows how to detect Daylight Savings Time, if you'd like that, too.

If you want to try it, be sure to get NeoSWSerial from the link above. You can also get NeoGPS from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.

Cheers,
/dev