DIY Speedometer using Arduino and Processing Android App

In this project we make a Cool Speedometer for bikes or any automotives by using Arduino which broadcast the speed using Bluetooth to an Android application that we created using Processing. The complete project is powered by an 18650 Lithium cell and hence highly portable along with your vehicle. To spice it up a bit more I have added the option of charging your mobile phone as it displays your speed. Yes, you can also use this as a power bank for your mobiles on the go as the 18650 has high charge density and can easily be charged and discharged.

I will completely guide you from scratch till the completion, speedometer can he hooked up to our vehicle and tested. The cool feature here is that you can customize your android app for your personalisation and add more features according to your creativity. But, if you do not want to build the app by yourself and just build the Arduino part then no worries, just download the APK file (read further) and install in your Android mobile phone. Also check the full Video at the end.

So let’s see what materials we would need to build this project, and plan our budget. All these components are easily available; if you have trouble buying any of these let me know in the comment section.

 

Hardware Requirements:

  • Arduino Pro Mini (5V 16MHz)
  • FTDI board (for programming mini you can also use UNO)
  • 3V to 5V DC-DC Boost converter with USB output charger
  • TP4056 Lithium battery Module
  • Bluetooth Module (HC-05/HC-06)
  • Hall effect sensor (US1881/04E)
  • 18650 Lithium Cell
  • Small piece of magnets
  • Perf Board
  • Berg sticks connectors (Male and Female)
  • Soldering Kit
  • Small enclosure boxes to mount the kit.

Programming Requirements:

  • Arduino IDE
  • Processing IDE with android ADK (Only if you want to code your own app.)
  • Windows/Mac PC
  • Android Mobile Phone.

It might look like a handful of components and materials, but trust me once you complete this project you would feel they are worth the time the effort.

 

Measuring Speed using Hall Sensor and Arduino:

Before we get our hands on the hardware, let us know how we are actually going to measure the speed using Arduino. There is lots of way to measure the speed of a vehicle using Arduino, but using a hall sensor is the most economic and easiest way of doing it. A Hall Sensor is a component that detects the polarity of a magnet. For example whenever one particular pole of the magnet is brought near the sensor, the sensor will change its state. There are many types of hall sensors available you can use any one of those in this project but make sure that it is a digital hall sensor.

To measure the speed we have to stick a small piece of magnet onto the wheel of the vehicle, each time the magnet crosses the hall sensor it will detect it and sends the information to the Arduino.

An interrupt will be received by the Arduino each time the magnet is detected. We run a continuous timer by using millis() function and calculate the time taken for the wheel to complete two rotations (to minimise error) by using the below formulae:

Timetaken = millis() – pevtime;

 

Once we know the time taken we can calculate the rpm by using the below formulae:

rpm = (1000/timetaken) * 60;

Where (1000/timetaken) gives the rps (Revolutions per second) and it is multiplied by 60 to convert rps to rpm (Revolutions per minute). 

 

After calculating the rpm we can calculate the velocity of the vehicle using the below formulae provided we know the radius of the wheel.

v= radius_of_wheel * rpm * 0.37699;

The Arduino, after calculating the velocity, will broadcast it using the Bluetooth Module. The complete code has been given below in Code section. Also check our other projects involving Bluetooth Module HC-05 here.

 

Schematics and Hardware Part:

The complete Circuit diagram of the project is given below:

Speedometer-using-Arduino-and-Processing-Android-app-circuit-diagram

Here, the hardware part is split into two parts one is the main board which contains all the main files. The other board just consists of a hall sensor and a resistor which will be mounted near the wheel. Let us start building the main board.

Building-Perf-board-for-Arduino-speedometer

Speedometer-using-Arduino-and-Processing-Android-app

Once the connection is made let us test the set up by using our 18650 Lithium battery. Lithium battery is highly explosive in nature, hence it must be handled with extreme caution. It is for this reason why we use a TP4056 Lithium Battery Charging Module. This module has over charge/discharge protection and Reverse polarity protection. Hence the battery can be easily charged using a normal micro USB charger and can be safely discharged till it reaches the under voltage cut off limits. Some important details of the TP4056 charge module is given in the table below.

Parameters :

Value per Cell :

Under Voltage cut-off

2.4V

Over voltage Cut-off

4.2V

Charging current

1A

Protection

Over Voltage and reverse polarity protection

IC’s present

TP4056 (charger IC) and DW01 Protection IC

Indication LED’s

Red- Charging in Progress

Green – Charge Complete

 

Now, let us start with the Hall Sensor Board. This board just contains two components one it the 10K resistor and the other is the hall sensor.  The connections can be made as shown in the schematics above. Once the board is ready, connect them using jumper wires as per the schematics. Once it is done it should look something like this.

Hall-sensor-board-for-Speedometer-using-Arduino-and-Android

 

Another crucial step in the project is connecting the 18650 battery to the B+ and B- terminals of the TP4056 module using a wire. Since Li+ cells are explosive it is highly not recommended to use a soldering iron over these cells. Although people have done it, it is highly risky and can easily end up in a big mess. Hence the easy way to do it, is to use magnets as shown below

18650-Lithium-battery-for-Arduino-speedometer

Simply solder the wire to a small piece of magnet and then stick the magnets to the terminals of the battery (they get attracted to terminals very well) as shown above. You might use some duck tap to further secure the position of the magnet.

 

Programming the Arduino:

The program for this project is very simple. We just have to calculate the speed of rotating wheel by using the hall sensor interrupt inputs and broadcast the calculated speed over the air using Bluetooth Module. The complete program is given in the Code section below and explained using the comment lines.

Each time the hall sensor detects the magnet it triggers an interrupt. This interrupt function is called by the magnet_detect() function. This is the place where the rpm of the vehicle is calculated.

Once the rpm is calculated the velocity of the wheel is calculated in the loop () function. Once the code is ready lets dump it to our Arduino pro mini and test its working as shown in the Video given at the end.

 

Android Mobile Application for Speedometer:

The Android application for this project is made using software called Processing. If you are not interested in making your own Android application and would like to just install the one used here, you can download the APK file and install it directly in your Smart Phone by following the below steps.

1. You can directly download the APK file from the below link. This APK file is made for Android version 4.4.2 and above (Kitkat an above). Extract the APK file from the zip file.

Android Application for Speedometer

2. Transfer the .Apk file from your computer to your mobile phone.

3. Enable installing application from Unknown sources in your android settings.

4. Install the application.

 

If successfully installed, you will find the application named “Processing_code” installed on your phone as shown below:

Android-app-for-Arduino-speedometer-using-processing

 

Develop your own Application using Processing:

Either you can use the .APK file given above or you can build your own app using Processing as explained here. You can download the all the Processing Android application code from here. The program is self-explained using the comment lines. But if you have any problem or if you want to get your application a modified a bit please use the comment section and I will help you out.

The android program establishes a connection with our Bluetooth module during start up of the application and receives the speed of the vehicle which was calculated and broadcasted by the Arduino Pro mini. I have created a small graphics also to display the speed using a Analog speedometer to make it look a bit attractive. You can come up with your own ideas and tweak the code to personalize it for your needs. Also check our other Processing Projects to learn more about it: 

Once you have installed the application to your mobile phone its time to test our project. But we have not yet mounted our kit to a vehicle yet. Let’s do it.

 

Mounting the Speedometer kit to a vehicle:

I have mounted this kit over my bi-cycle and tested it, and it works like a charm. Mounting the kit is left to your creativity, you can get your own small box from a shop and drill holes for the wires and connections and mounted it to your vehicle. One common important thing to note is that the magnet should be stuck to the rim of the wheel and the hall sensor should be mounted as close as possible to the magnet so that each time the magnet crosses the hall sensor it should be able to detect it, the arrangement is shown below.

Place-for-installing-3D-printed-arduino-speedometer-box-on-bicycle Installing-3D-printed-hall-sensor-board-box-on-bicycle

 

Since I have a 3D printer with me, I designed my own enclosures to make them look good and in way that it can be easily mounted and disconnected from our bike for charging the battery. So if you have a 3D printer or if you can gain access to one to print few materials continue reading, else skip this part and use your own creativity to mount these things. Learn to user 3D printer here.

 

If you have decided to use my design files and print your enclosures then make sure your main perf board is close to the below dimensions

Perf-board-for-Arduino-speedometer

The complete Design and STL files for 3D printing can be downloaded from here. If the board is similar to what is have made here then you can directly 3D print your enclosures using the given STL files or else you can use the Design files and modify it according to your board.

 

Let us start with the 3D printed small enclosure which will be used for the hall sensor module. Print the enclosure, place the circuit into it and harness your wires though the hole provided and then mount it to your vehicle so that the hall sensor is near the magnet as shown below.

3D-printed-box-for-Hall-sensor-perf-board-for-Speedometer Installing-3D-printed-hall-sensor-board-box-on-bicycle

 

It is recommended to model the main board before designing the enclosure for it so that we can make sure it fits in properly, because trust me it would be nightmare when you print your enclosure for 6 long hours and in the end it won’t fit into your perf board.  The model board for my main perf board is shown below.

Speedometer-using-Arduino-and-Processing-Android

Speedometer-using-Arduino-and-Processing-Android-3D-model

 

Now it will be easy to design the main enclosure box. I have designed the main box in two files, so that one part of the box will hold the electronics and the other will be permanently fixed to the cycle using clamps and bolts. These two parts can easily be fixed to gather to make a complete enclosure and then be separated when we need to recharge our lithium battery or work on our electronics. 

Once the first part of the enclosure is designed and printed lets place all our components inside as shown below and it should look something like this..

3D-printed-case-for-Speedometer-using-Arduino-and-Processing-1 3D-printed-case-for-Speedometer-using-Arduino-and-Processing-2

As you can see there are two openings in front of the box, one is used for the USB through which we can charge our mobile phone. The other is for the micro USB using which we can charge our lithium battery.

 

Now let us print the second part of the main enclosure and check if it fits the first part as expected.

3D-printed-case-for-Speedometer-using-Arduino-and-Processing-3 3D-printed-case-for-Speedometer-using-Arduino-and-Processing-4

Once we are satisfied with the parts we can mount the second part of the enclosure using a C-clamp and some nuts and bolt as shown below:

nut-bolts-for-tightening-3D-printed-speedometer-box Installing-3D-printed-arduino-speedometer-box-on-bicycle

 

Now let us connect the battery to our main circuit using magnets and tape as discussed above and keep it permanently safe inside our enclosure.

Perf-board-inside-3D-printed-speedometer-box-with-battery-1

Perf-board-inside-3D-printed-speedometer-box-with-battery-2

That is it our hardware is ready for the final mounting. Simply connect the hall sensor module with the main board and slide the movable enclose into the fixed enclosure and it’s ready for action.

Arduino-speedometer-setup-mounted-on-bicycle Installed-3D-printed-arduino-speedometer-box-on-bicycle

 

Working Explanation:

After making sure your lithium battery is charged up, simply turn on the kit by using the toggle switch and open your Android application. If everything goes well you should get the below screen and it should display that your app has connected to your Bluetooth module HC-05 as shown below. Remember to pair your Bluetooth module with phone before opening the application.

measuring-speed-using-android-app-and-arduino-Speedometer-1 measuring-speed-using-android-app-and-arduino-Speedometer-2

Now simply ride your vehicle and you should notice the speedometer showing the current speed of your vehicle. You can also charge you mobile phone while riding by using a normal charger cable. Once you are done with your ride, you can slide off the box from the cycle and charge it from AC mains by using any smart phone mobile charger.

 

So this how, you can not only measure the speed of your vehicle but also charge the Mobile at the same time. Hope, you enjoyed the project. You can add app a lot more feature to this project, just by tweaking the codes. You can calculate the distance covered by your ride, the top and the average speed of your ride etc. Let me know if you have any quires through the comments and I will be happy to help you out.

As usual the entire working of the Project will be shown in the video below

Code: 

/*Arduino Code for measuring speed of the Vechile using Hall Sensor
 * Coded by Circuitdigest.com
 * On 14-04-2017
 */

 /*CONNECTION DETIALS
  * Arduino D11 -> RX of BT Module
  * Arduino D12 -> Tx of BT
  * Arduino D2  -> Hall sensor 3rd pin
  */

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Cycle_BT(11, 12);  // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer

float radius_of_wheel = 0.33;  //Measure the radius of your wheel and enter it here
volatile byte rotation; // variale for interrupt fun must be volatile
float timetaken,rpm,dtime;
int v;
unsigned long pevtime;

 
void setup()
 {
   Cycle_BT.begin(9600); //start the Bluetooth communication at 9600 baudrate
   //pinMode(ledpin,OUTPUT); //LED pin aoutput for debugging
   attachInterrupt(0, magnet_detect, RISING); //secound pin of arduino used as interrupt and magnet_detect will be called for each interrupt
   rotation = rpm = pevtime = 0; //Initialize all variable to zero
 }
 
void loop()
{
  /*To drop to zero if vehicle stopped*/
 if(millis()-dtime>1500) //no magnet found for 1500ms
 {
  rpm= v = 0; // make rpm and velocity as zero
  Cycle_BT.write(v);
  dtime=millis();
 }
 v = radius_of_wheel * rpm * 0.37699; //0.33 is the radius of the wheel in meter
}
 
void magnet_detect() //Called whenever a magnet is detected
{
  rotation++;
  dtime=millis();
  if(rotation>=2)
  {
    timetaken = millis()-pevtime; //time in millisec for two rotations
    rpm=(1000/timetaken)*60;    //formulae to calculate rpm
    pevtime = millis();
    rotation=0;
    Cycle_BT.write(v);
    //Cycle_BT.println("Magnet detected...."); //enable while testing the hardware
  }
}

Video: 

Leave a comment