Hi,
A coupe of years ago, I had post a question regarding my 0-40 MPH old school speedometer for a bike that uses a 1575R-A gps module to calculate speed and a servo with an orange needle to show the speed. The speedometer design has been tweaked a little bit, the scale now goes to 50, but it's still the same concept. Someone replied with saying that first I need to get the gps to calculate speed, then implement the code for the servo so it will point to the correct number once hit that speed. My question is, how? I looked at YouTube videos and other forums, but it's not making sense to me. Also, when I do find information on Arduino speedometers, they are using a LCD to display speed, but not my project as I mentioned earlier.
Here's what I have so far
#include <NMEAGPS.h>
#include <NeoSWSerial.h>
NeoSWSerial gpsSerial(0,1);
NMEAGPS gps;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
gpsSerial.begin(9600);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(17); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(17); // waits 15ms for the servo to reach the position
}
}
void displayGPS( gps_fix & fix )
{
int mph = 0;
// Print speed
if (fix.valid.speed && (fix.spd.whole > 5)) {
mph = (fix.spd.whole * 185) / 100;
}
if (mph > 30)
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
}
}
Anything is much appreciated