Hardware components | ||||||
![]() |
| × | 1 | |||
| × | 1 | ||||
| × | 1 | ||||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
![]() |
| |||||
| ||||||
Hand tools and fabrication machines | ||||||
![]() |
| |||||
![]() |
|
The story of this project is extremely simple. I needed a bike counter and all the projects I found either used a sensor that had to be attached to the wheel, which I don't want, or used a gps but counted the distance in a straight line
That is why my project uses gps and counts the distance along the track.
In near future I will add 3d printed case with bike mount, and maybe update Interface.
P.S. I forgot to draw on schematic that bl should be connected to D8 on Arduino
/*
-----------Bike comuter-----------
----by Trybulski Mikolaj----------
*/
//gps libaries
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
//lcd libaries
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
//variables used for distance calculations
float latold;
float longold;
float wholedistance;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(7, 6); //tx (on gps) - 7, rx (on gps) - 6
//lcd settin
//pinout 9 CLK , 10 DIN , 11 DC , 12 CE , 2 RST , 8 BL
const int clk = 9;
const int din = 10;
const int dc = 11;
const int ce = 12;
const int rst = 2;
const int bl = 8; //low - on, high - off
Adafruit_PCD8544 display = Adafruit_PCD8544(clk, din, dc, ce, rst);
void setup(){
wholedistance = 0;
latold = 0;
longold = 0;
ss.begin(9600);
delay(300);
pinMode(bl, OUTPUT);
digitalWrite(bl, LOW);
display.begin();
display.setContrast(60);
display.clearDisplay();
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(1);
display.print("Bike computer v1.0, made by Trybulski Mikolaj ");
display.display();
delay(2000);
display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(2);
display.print("waitingfor gps... ");
display.display();
}
void loop(){
display.clearDisplay();
display.setTextColor(BLACK);
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
//dist calculations
if(latold == 0 || longold == 0){//dont calculate using 0 coordinates (which are set for stary value)
latold = gps.location.lat();//update ealier position
longold = gps.location.lng();
delay(300);
}
else{
if(gps.location.lat() == latold || gps.location.lng() == longold){
delay(1000);
}
else{
float distLat = abs(gps.location.lat() - latold) * 111194.9;
float distLong = 111194.9 * abs(gps.location.lng() - longold) * cos(radians((gps.location.lat() + latold) / 2));
float distance = sqrt(pow(distLat, 2) + pow(distLong, 2)); // equation form https://www.instructables.com/Distance-measuring-and-more-device-using-Arduino-a/
latold = gps.location.lat();//update ealier position
longold = gps.location.lng();
wholedistance = distance + wholedistance; // add newly calculated distance to ealier one for trip distance
}
}
//dist display
display.setTextSize(1.5);
display.setCursor(0,25);
display.print(wholedistance / 1000);
display.println("km");
int readvalue = gps.course.deg(); //define and round heading
int speedo = gps.speed.kmph(); // define and round speed
display.setCursor(0,0);
display.setTextSize(3);
display.print(speedo);
display.setTextSize(1);
display.print("kph ");
display.setTextSize(2);
if (readvalue >=338 || readvalue < 22){
display.println("N");
}
else if (readvalue >= 22 && readvalue < 68)
{
display.println("NE");
}
else if (readvalue >= 68 && readvalue < 113)
{
display.println("E");
}
else if (readvalue >= 113 && readvalue < 158)
{
display.println("SE");
}
else if (readvalue >= 158 && readvalue < 203)
{
display.println("S");
}
else if (readvalue >= 203 && readvalue < 248)
{
display.println("SW");
}
else if (readvalue >= 248 && readvalue < 293)
{
display.println("W");
}
else if (readvalue >= 293 && readvalue < 338)
{
display.println("NW");
}
display.display();
delay(1000); //wait. we dont need to update so many times
}
}
}
Comments
Please log in or sign up to comment.