0% found this document useful (0 votes)
134 views6 pages

Arduino Code

This document contains code for detecting vehicle speed using a GPS module. It includes libraries for LCD display, software serial communication, and GPS parsing. The setup function initializes the LCD and serial ports. The main loop function gets time and location data from the GPS, calculates speed in km/h, displays it on the LCD, and prints it over serial. It delays between readings to allow the GPS time to acquire satellites and get an accurate fix. Several static functions format and print GPS data components like time, date, and strings to the serial port.

Uploaded by

anon_645372799
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
134 views6 pages

Arduino Code

This document contains code for detecting vehicle speed using a GPS module. It includes libraries for LCD display, software serial communication, and GPS parsing. The setup function initializes the LCD and serial ports. The main loop function gets time and location data from the GPS, calculates speed in km/h, displays it on the LCD, and prints it over serial. It delays between readings to allow the GPS time to acquire satellites and get an accurate fix. Several static functions format and print GPS data components like time, date, and strings to the serial port.

Uploaded by

anon_645372799
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

#include<LiquidCrystal.

h> // lcd(7, 6, 5, 4, 3, 2);

#include <SoftwareSerial.h>

#include <TinyGPS++.h>

#include <SPI.h>

#include <Wire.h>

char timeinmin[32];

String speedinkm;

int f=0;

int valid=0;

static const uint32_t GPSBaud = 9600;

TinyGPSPlus gps;

void setup()

lcd.begin(16,2); // Start lcd n semua pin

Serial.begin(9600);

Serial1.begin(GPSBaud);

display.println(speedinkm);

void loop()

Time(gps.time); // start function gps

valid=gps.location.lat(); // detect location guna gps sebab equation speed =distance/time

f = round( gps.speed.kmph());
speedinkm = String(f);

Serial.print(speedinkm);

Serial.println();

smartDelay(500);

Display_data();

lcd.print("Detecting Vehicle Speed"); // initial display sblm detect speed

lcd.setCursor(0,1);

lcd.clear()

static void Time(TinyGPSTime &t)

sprintf(timeinmin, "%02d:%02d", t.hour(), t.minute());

// timeinmin[0]='1';

//timeinmin[1]='9';

Serial.print(timeinmin);

//Serial.print(" ");

// Serial.print(timeinmin[1]);

int temp1 = (int)timeinmin[0];

temp1=temp1-48;

temp1=temp1*10;

temp1=temp1+((int)timeinmin[1]-48);
temp1=temp1+5;

if(temp1>=24){temp1=temp1-24;}

char a[2];

itoa(temp1, a, 10);

timeinmin[0]=a[0];

timeinmin[1]=a[1];

static void smartDelay(unsigned long ms)

unsigned long start = millis();

do

while (Serial1.available())

gps.encode(Serial1.read());

} while (millis() - start < ms);

static void printFloat1(float val, bool valid, int len, int prec)

if (!valid)

while (len-- > 1)

Serial.print('*');
Serial.print(' ');

else

Serial.print(val, prec);

int vi = abs((int)val);

int flen = prec + (val < 0.0 ? 2 : 1); // . and -

flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;

for (int i=flen; i<len; ++i)

Serial.print(' ');

smartDelay(0);

static void printInt(unsigned long val, bool valid, int len)

char sz[32] = "*****************";

if (valid)

sprintf(sz, "%ld", val);

sz[len] = 0;

for (int i=strlen(sz); i<len; ++i)

sz[i] = ' ';

if (len > 0)

sz[len-1] = ' ';

Serial.print(sz);
smartDelay(0);

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)

if (!d.isValid())

Serial.print(F("********** "));

else

char sz[32];

sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());

Serial.print(sz);

if (!t.isValid())

Serial.print(F("******** "));

else

char sz[32];

sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());

Serial.print(sz);
}

printInt(d.age(), d.isValid(), 5);

smartDelay(0);

static void printStr(const char *str, int len)

int slen = strlen(str);

for (int i=0; i<len; ++i)

Serial.print(i<slen ? str[i] : ' ');

smartDelay(0); // detect speed smpai sini je

You might also like