You are on page 1of 18

w 



‡ A speedometer is a instrument that measures


and displays the instantaneous speed.
‡ Its was invented in 1888 and was called as
velocimeter.
‡ Later as it found its prominent application in the
field of automobiles it was termed as
speedometer.
‡ Its also used in boats and aircrafts and are
referred as PIT LOG and AIRSPEED
INDICATOR respectively.
á  


‡ Microcontroller (arduino)
‡ Infra red sensor
‡ Resistors
‡ Bread board
‡ LCD display
‡ Buttons
‡ Connecting wires
ë 


‡ Microcontroller (arduino) - 1500


‡ Infra red sensor - 100
‡ Resistors - 10
‡ Bread board - 70
‡ LCD display - 170
‡ Buttons - 30
‡ Connecting wires - 20
‡ total  1900
i   

á 
  
V    
‡ /* Digital Speedometer Based on IR Proximity Sensor */
‡ /* Functionalities - Option to Set Radius, Switch between Mph / Kmph, See Total Distance Covered. */

‡ #include <LiquidCrystal.h>

‡ #define Sensor 2 // This is an interrupt pin on the Arduino to which we have connected the IR proximity
Sensor

‡ #define RS 12 // the lcd's Registry Select PIN


‡ #define E 4 // the lcd's Enable Pin
‡ #define D4 8 // D4 Pin
‡ #define D5 9 // D5 Pin
‡ #define D6 10 // D6 Pin
‡ #define D7 11 // D7 Pin

‡ #define Set 7 // 3 switches for setting options - SET, Increase , Decrease


‡ #define Increase 3 // Used to see the Distance Covered.
‡ #define Decrease 6 // Also used to Swap between Kmph & Mph
‡ int rpm = 0;
‡ int radius= 500; // Radius in Cms, Default taken as 40
‡ boolean kmph = 1; // A Flag variable that helps toggle between Kmph / Mph(Miles Per Hour) Set this variable
to 1 for Kmph and 0 for Mph
‡ double distance = 0, tmp_distance = 0; // This is to keep track of the Distance Travelled.
‡ int old_time=0,time= 0, tmp_time=0; // variable to store time parameters for calculation
‡ LiquidCrystal lcd(RS,E,D4,D5,D6,D7);
‡ double Speed = 0;
‡ void setup()
‡ {
‡ pinMode(Sensor,INPUT);
‡ pinMode(Increase,INPUT);
‡ pinMode(Decrease,INPUT);
‡ pinMode(Set,INPUT);
‡ attachInterrupt(0, counter, RISING);// The IR Sensor is connected to PIN2 which is also Interrupt 0 on
Arduino.
‡ //The Attach Interrupt function calls the counter function whenever the sensor goes from 0 to 1
‡ lcd.begin(16,2);
‡
‡ }
‡ void loop()
‡ {
‡ tmp_time = millis()-old_time;
‡ if(tmp_time >999) // the LCD is refreshed with speed information every 100 milliseconds.
‡ {
‡ Disp_Speed();
‡ old_time = millis();
‡ }
‡ // Here we are toggling the kmph variable to switch over to Mph mode. Rest of the coding for this is in
Disp_Speed function
‡ if(digitalRead(Decrease))
‡ {
‡ while(digitalRead(Decrease));
‡ kmph = !kmph ;
‡ } if(digitalRead(Increase))
‡ {
‡ while(digitalRead(Increase));
‡ lcd.clear();
‡ Disp_Distance();
‡ delay(2000);
‡ lcd.clear();
‡ } if(digitalRead(Set))
‡ { while(digitalRead(Set));
‡ lcd.clear();
‡ Set_Radius();
‡ }}void counter()
‡ { rpm++;
‡ distance = distance + (6.28 * radius);}
‡ void Disp_Speed()
‡ { Speed = ((rpm * (radius * 6.28))/tmp_time) * 36 ; // Speed Calculation for Kilometers by Default
‡ if(kmph)
‡ { lcd.clear();
‡ lcd.setCursor(0,0);
‡ lcd.print("Speed : ");
‡ lcd.setCursor(8,0);
‡ lcd.print(Speed);
‡ lcd.setCursor(12,1);
‡ else
‡ {
‡ Speed = (Speed)/(.62);
‡ lcd.clear();
‡ lcd.setCursor(0,0);
‡ lcd.print("Speed : ");
‡ lcd.setCursor(8,0);
‡ lcd.print(Speed);
‡ lcd.setCursor(13,1);
‡ lcd.print("Mph");
‡ } noInterrupts();
‡ rpm = 0;
‡ interrupts();
‡ }void Disp_Distance()
‡ {
‡ tmp_distance = distance / 100000 ; // Distance Calculation for Kilometers by Default
‡ if(kmph)
‡ {
‡ lcd.clear();
‡ lcd.setCursor(0,0);
‡ lcd.print("Dist : ");
‡ lcd.setCursor(7,0);
‡ lcd.print(tmp_distance);
‡ lcd.setCursor(13,1);
‡ lcd.print("Kms");
‡ }
‡ else
‡ {
‡ tmp_distance = (tmp_distance)/(.62);
‡ lcd.clear();
‡ lcd.setCursor(0,0);
‡ lcd.print("Dist : ");
‡ lcd.setCursor(7,0);
‡ lcd.print(tmp_distance);
‡ lcd.setCursor(13,1);
‡ lcd.print("Mls");
‡ }
‡ }

‡ void Set_Radius()
‡ {
‡ while(digitalRead(Set)); // Waiting for the Set Button to be Released - Debounce
‡
‡ while(!digitalRead(Set))
‡ {
‡ lcd.clear();
‡ lcd.setCursor(0,0);
‡ lcd.print("Radius : ");
‡ lcd.setCursor(8,0);
‡ lcd.print(radius);
‡ lcd.setCursor(13,1);
‡ lcd.print("Cms");
‡ if(digitalRead(Increase))
‡ {
‡ while(digitalRead(Increase));
‡ radius++;
‡ }
‡ if(digitalRead(Decrease))
‡ {
‡ while(digitalRead(Decrease));
‡ radius--;
‡ }
‡ delay(5);
‡ }
‡ lcd.clear();
‡ lcd.print("Radius Changed!!!");
‡ delay(1000);
‡ }
w 

‡ The ir sensor is used to sense the interrupts a


feed it as an input to aurdino. The white light is
the transmitter and the black light is the
interrupt.
‡ One interrupt will be generated every one
revolution.
‡ So the number of revolution¶s can be
monitored.
‡ The microcontroller is programmed to display
the speed in km/h and m/h
‡ The radius of the disc is to be fed in the
microprocessor and we know the perimeter of
the dis.
‡ Using which the distance travelled by the
vehicle can also be found out. The required
program is fed in the aurdino.
‡ The radius by default is set as 5 centimeters
and can be modified using the buttons.
‡ All these outputs are displayed on the LCD
display.
ë  

You might also like