How to make a Tachometer for bicycle

To make a tachometer for bicycle tachometer we will be using Arduino and reed switch as the main component. We will design the tachometer to Display Speed and also temperature. Following are the list of components required.

Parts list:

  • Arduino
  • Bicycle with reed switch
  • LCD display 16×2
  • thermometer DS18B20
  • Servo
  • resistor 1.2k Ω , 4.7k Ω
  • potentiometer 10 kΩ
  • Miscellaneous – 9V battery, cables, switch, button
  • Enclosure
  • breadboard

Note that you can omit the Servo if you do not want to display speed in graphical way.

You may refer my earlier post on how to connect LCD display, measure temperature using DS18b20 sensor and how to control servo using Arduino

How to connect 16*2 LCD display Arduino UNO

How to Measure temperature with Arduino and DS18B20 sensor?

Servo Motor Control using Arduino

Step 1: Connecting the LCD display

  • VSS –> GND Arduino
  • VDP –> 5V Arduino
  • VO –> output potentiometer (potentiometer VCC -> 5V Arduino, potentiometer GND -> Arduino GND).
  • RS –> pin 12 Arduino
  • RW –> GND Arduino
  • E –> pin 11 Arduino
  • D4 –> pin 5 Arduino
  • D5 –> pin 4 Arduino
  • D6 –> pin 3 Arduino
  • D7 –> pin 2 Arduino
  • A –> 5V Arduino with 1.2 k resistor
  • K –> GND Arduino

Step 2: Connecting the Servo

  • VCC –> 5V Arduino
  • mass –> GND Arduino
  • Data –> pin 6 Arduino

Step 3: Connecting the Thermometer

  • VCC –> 5V Arduino
  • mass –> GND Arduino
  • Data –> pin 1 Arduino

data and power is connected via a 4.7 kΩresistor

Step 4: Sensor on wheel (reed switch)

  • one end -> 5V Arduino
  • second end -> A0 Arduino and resistor 1.2 kΩ

The other end of the resistor to ground in the Arduino

Step 5: Connect the Button

  • one end –> 5V Arduino
  • second end –> A1 Arduino

If you have a different wheel diameter you have to change it. You can calculate it with this formula:

circuit = π*d*2,54 (d=diameter of your wheel, I multiplied it by 2.54 to get the result in meters).

//Code
 #include  < Servo.h>
 #include <LiquidCrystal.h>
 #include <OneWire.h>
 #include <DallasTemperature.h>

#define ONE_WIRE_BUS 1
 OneWire oneWire(ONE_WIRE_BUS);
 DallasTemperature sensors(&oneWire);

//LCD display pins
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 //servo name
 Servo myservo;
 //definition of variables
  long previous, triptime, time, impulses;
  float speedometer, dist, aspeed;
  int servo;
  int screen=1;
  //If you have other diameter of wheel you need change it
  float circuit=2.0;
  double temperature;
  
  void setup() {

lcd.begin(16, 2);
   pinMode(A0, INPUT);
   pinMode(A1, INPUT);
   
   //servo definition and setting the tachometer to 0
   myservo.attach(6); 
   myservo.write(180);
   lcd.print("Bike tachometer");
   delay(1000);
   lcd.setCursor(5, 1);
   lcd.print("V 1.0");
   delay(4000);
   lcd.clear();
   delay(500);
   lcd.setCursor(0, 0);
   lcd.print("Dist:");
  }

void loop() {
    //if wheel turns
    if(analogRead(A0)>=300){
       //number of turns++
       impulses++;
       //count turn time
     time=(millis()-previous);
     //count speed
     speedometer=(circuit / time)*3600.0;
   previous=millis();
     Tachometer();
   delay(100);
 }

Lcd(); 
    }
    
    //display speed on tachometer
    void Tachometer(){
      //map speed 0-180 to servo
   speedometer=int(speedometer);
   servo = map(speedometer, 0, 72, 180, 0);
   //setup servo
   myservo.write(servo);
    }
   
   
   
     void Lcd(){
        //when button is clicked
       if(analogRead(A1)>=1010){
         lcd.clear();
       screen++;
       if(screen==5){
           screen=1;
         }
       }
    
         if(screen==1){
         //displays speed
         lcd.setCursor(0, 1);
         lcd.print("Speed:");
         lcd.setCursor(7, 1);
         lcd.print(speedometer);
         lcd.print("km/h");
         }
         
         if(screen==2){
           
         //displays themperature
         temperature=sensors.getTempCByIndex(0);
         sensors.requestTemperatures(); 
         lcd.setCursor(0, 1);
         lcd.print("Temp:");
         lcd.setCursor(7, 1);
         lcd.print(temperature);
         lcd.print(" C");
         }
         
         if(screen==3){
           //displays averagr speed
         aspeed=dist/(millis()/1000.0)*3600.0;
         lcd.setCursor(0, 1);
         lcd.print("A.speed:");
         lcd.setCursor(8, 1);
         lcd.print(aspeed);
         lcd.print("km/h");
         }
         
         if(screen== 4){
           //diplays trip time
         triptime=millis()/60000;
         
         lcd.setCursor(0, 1);
         lcd.print("Time:");
         lcd.setCursor(7, 1);
         lcd.print(triptime);
            
         }
             
         lcd.setCursor(0, 0);
         lcd.print("Dist:");
         //calculation of the distance
        dist=impulses*circuit/1000.00;
        //dislays distance
        lcd.setCursor(6,0);
        lcd.print(dist);
        lcd.print("km");
       }                                                     

Cut the image below and stick on top of the enclosure. You need to position the servo at the Centre. Movement of the arm will indicate the speed in the tachometer for bicycle. To make it simple you can omit this part and just use the LCD to display the speed and distance only. Temperature display is also optional. May be you can add extra features one by one.

 

Leave a Reply