HSC Project - Help Needed with GPS Device Options

Project is a device that will go on the back of a bus to let motorists behind the bus know an approximate distance for when the bus will get to the next stop. (The purpose of this is to allow drivers to change lanes early enough so that it’s safe)

I need some sort of GPS device that will allow me to change the display from 1000m, 500m, 200m etc. - I am thinking I will just have those numbers painted on the outside and then have a bulb light up next to them to indicate where the bus is up to.

Thanks!

Hi Emily,

Here’s some sudo C code that I’ve adapted from here that should work on Arduino that calculates the distance between two coordinates (all going well):

``````float degreesToRadians(float degrees) {
return degrees * PI / 180;
}

float distanceInKmBetweenEarthCoordinates(float lat1, float lon1, float lat2, float lon2) {

float a = sin(dLat/2) * sin(dLat/2) + sin(dLon/2) * sin(dLon/2) * cos(lat1) * cos(lat2);
float c = 2 * atan2(sqrt(a), sqrt(1-a));
}
``````

And two examples:

``````distanceInKmBetweenCoordinates(0,0,0,0) // Distance between same points should be 0 0

distanceInKmBetweenCoordinates(51.5, 0, 38.8, -77.1) // From London to Arlington 5918.185064088764
``````

With that in mind, you only need to grab the coordinates of each bus stop and check each of them in turn for distance. If any are within 1000m, 500m, 200m etc, then react accordingly.

I recommend the Ultimate GPS module from Adafruit and this code would run on an Uno R3 easily enough despite heavy use of floats.

A hookup/code guide for the above hardware:

Use `GPS.fix` to ensure you have a fix. Once you do, use `GPS.latitude` and `GPS.longitude` as needed.

Don’t forget to report back with how things went!

Thanks so much! I will let you know how that goes!