Project tutorial
Bike Speedometer Using Reed Switch

Bike Speedometer Using Reed Switch

A mechanism that determines the speed at which your bike is traveling at.

  • 8 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

This is a project that determines the velocity of a bike using a reed switch. It works by the reed switch returning a time that it took to do one full rotation then putting that value over the circumference which returns the speed.

Pictures of the project are shown below.



Here is a YouTube Video of the project in use.

YouTube Video of the Bike Speedometer in use.

Hope you enjoyed my project and it was of use to you! Thanks.

Code

Bike Speedometer Using Arduino Uno and a Reed SwitchC/C++
Finds speed of the bike.
//This code was made by Alex Cockman with inspiration from the theory from the websites linked below.
//Adruino.com's link: https://www.arduino.cc/en/Tutorial/LibraryExamples/HelloWorld
//danielleamya's linked: https://forum.arduino.cc/t/bike-speedometer-using-reed-switch/514581
//Arduino.com's linked: https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
//Adminastrator from Eletronics Hub eletronic - set up and understanding of reed switches: https://www.electronicshub.org/how-to-interface-reed-switch-with-arduino/#:~:text=Connect%20one%20end%20of%20the,of%20a%20Pull%2Dup%20Resistor


#include <LiquidCrystal.h>

int reedSwitch = 2;  //Declaring pin for reed switch to be used. Pin 2 or 3 must be used for the reed switch on the Uno
int radius = 12.5;   //hard coding in the radius of the wheel for future conversion into circumference 
int circumference;   //declaring the circumference variable
int totaltime;       //declaring the total time until the next trip on the reed switch variable
int Speed;           //declaring the Speed variable
int timer;           //declaring the timer to calculate the total time variable

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 6;   // Declaring pins for LCD Display
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void isr()           
 {
      timer++;                        // Begin the timer and start counting
      delayMicroseconds(9600);        // Delay to start after a 0.0096 seconds
 }
void setup(){
  Serial.begin(9600);                 // Start serial monitor after a few seconds. Mainly for testing code to get it to work.

  lcd.begin(16,2);                    // Declare the scope that the LCD screen displays on
  lcd.setCursor(6, 0);                // Set Speed in the middle of the lCD display
  lcd.print("Speed");                 // Print on LCD screen what is inbetween the quotation marks
   
   attachInterrupt(digitalPinToInterrupt(2), isr, RISING);    //Begins the count of seconds when the reed switch in pin 2 is set off

   pinMode(reedSwitch, INPUT_PULLUP);                         // Sets the reed switch to be an input
   timer = 0;                                                 // Sets timer to 0 seconds
   Speed = 0;                                                 // sets the speed to 0 seconds
   totaltime = 0;                                             // sets the total time to start off at 0
   circumference = 6.28 * radius;                             // calculated the circumference
}
void loop() {

   if (millis() - totaltime >= 1000) {                                      // Gets varibales to go into the loop everytime the millis() - the total time elapsed is less than 1ms
                                                                            // So unless I become superman then no human will be able to achieve this. 
        detachInterrupt(digitalPinToInterrupt(2));                          // Stops the timer from the reading from pin 2 aka the reed switch

        Speed = ((8.181818182*circumference)/(millis() - totaltime)*timer); // Calculates the speed of the bike. The 8.18 number is converting the time in seconds into hours and inches into feet.

        timer = 0;                                                          // Makes the timer go back to zero
        totaltime = millis();                                               // Makes the total time the new time
        attachInterrupt(digitalPinToInterrupt(2), isr, RISING);             // Make the ISR loop attach back

        lcd.setCursor(8,1);                                                 // Sets cursor to the bottom left 
        lcd.print(Speed);                                                   // Prints the speed to the LCD display
        Serial.print("Speed");                                              // Prints "Speed" to serial monitor. Mainly for troubleshooting.  
        Serial.print(Speed);                                                // Prints the speed to the serial monitor. Mainly for troubleshooting.

   }
}

Schematics

BreadBoard View
Breadboard view 0yrgg6rjxv
Schematic
Schematic zuetmazw61

Comments

Similar projects you might like

Ninja Dollar - LCD game

Project tutorial by anime

  • 10,133 views
  • 12 comments
  • 15 respects

Community Safety Protector

Project tutorial by H@ck5treet B0y5

  • 3,095 views
  • 0 comments
  • 7 respects

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 6,519 views
  • 1 comment
  • 19 respects

WiFi Robot

Project tutorial by Team Kartik

  • 6,472 views
  • 1 comment
  • 16 respects

Arduino Game By LCD

Project tutorial by Mohammed Magdy

  • 101,863 views
  • 121 comments
  • 294 respects

LCD (Liquid Crystal Display)

by MicroBob

  • 89,933 views
  • 92 comments
  • 236 respects
Add projectSign up / Login