
I tricked out my dad bike with an arduino nano based speedometer, odometer, clock, and temperature sensor.
A DS3231 RTC keeps the time and temperature. I implemented a attachInterrupt() function to keep track of tire rotation via a reed switch.

This way, I do not have to programmatically monitor the reed switch; a routine is executed (in this case that calculates the distance traveled) each time the state of the digital pin the switch is connected to changes.
//bike speedometer #include #include "RTClib.h" RTC_DS3231 rtc; char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; // initialize the library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 10; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); float start, finished; float elapsed, time; //float circMetric=2.164; // wheel circumference relative to sensor position (in meters) float circMetric=1; // wheel circumference relative to sensor position (in meters) float circImperial; // using 1 kilometer = 0.621371192 miles float speedk, speedm; // holds calculated speed vales in metric and imperial float miles_traveled = 0; float feet_traveled = 0; char miles[100]; void setup () { attachInterrupt(0, speedCalc, CHANGE); //digital pin 2 start=millis(); // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("cr3d0"); lcd.setCursor(0,1); lcd.print("BIKE SPEEDOMETER!"); delay(4500); lcd.clear(); Serial.begin(9600); circImperial=circMetric*.62137; // convert metric to imperial for MPH calculations //rtc stuff int temp = 0; if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); }//end if if (rtc.lostPower()) { Serial.println("RTC lost power, lets set the time!"); // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); }//end if rtc lost power }//end setup void speedCalc() { elapsed=millis()-start; start=millis(); speedk=((3600*circMetric)/elapsed) * 0.12; // km/h speedm=((3600*circImperial)/elapsed) * 0.12; // Miles per hour feet_traveled += 1.1; miles_traveled = feet_traveled / 5280; //sprintf(miles, "%.2f", miles_traveled); } void loop() { DateTime now = rtc.now(); int temp = 0; lcd.clear(); lcd.setCursor(0,0); //lcd.print(int(speedk)); //lcd.print(" km/h "); lcd.print(int(speedm)); lcd.print(" MPH "); lcd.print(miles_traveled); lcd.print(" mi");; //lcd.setCursor(0,1); //lcd.print(int(elapsed)); //lcd.print(" ms/rev "); lcd.setCursor(0,1); lcd.print(now.hour(), DEC); lcd.print(':'); lcd.print(now.minute(), DEC); lcd.print(':'); lcd.print(now.second(), DEC); lcd.print(' '); temp = rtc.getTemperature() * 9/5 + 32; lcd.print(temp); lcd.print('F'); delay(1000); // adjust for personal preference to minimise flicker }
