Project tutorial

DIY Speedometer Using Arduino and Processing Android App © LGPL

Make a cool speedometer for bikes or any automotive by using Arduino, Bluetooth, and an Android Application.

  • 8,466 views
  • 0 comments
  • 17 respects

Components and supplies

11113 01
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
Allegro a1324lua t image
Hall Effect Sensor
×1
09716 01
SparkFun FTDI Basic Breakout - 5V
×1
3V to 5V DC-DC Boost Converter with USB output
×1
TP4056 Lithium battery module
×1
HC-05 Bluetooth module
or HC-06
×1
18650 Lithium cell
×1
13268 01
SparkFun Snappable Protoboard
×1
Headers (male and female)
×1

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

In this project, we make a cool speedometer for bikes or any automotive by using Arduino to 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 - the speedometer can be hooked up to your 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 it onto 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 will feel they are worth the time and 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 send 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 formula:

Timetaken = millis() – pevtime;

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

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 formula 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 the 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:

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.

Once the connection is made, let us test the set up by using our 18650 Lithium battery. The lithium battery is highly explosive by 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 LEDs:

  • Red - Charging in Progress
  • Green – Charge Complete

Now, let us start with the Hall Sensor Board. This board just contains two components: one is 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.

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 in a big mess. So the easy way to do it is to use magnets as shown below:

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 the 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, let's dump it into our Arduino Pro Mini and test that it's 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 onto 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 and 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:

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 problems or if you want to modify your application a bit, please use the comment section and I will help you out.

The Android program establishes a connection with our Bluetooth module during startup 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 an analog speedometer to make it look a bit attractive. You can come up with your own ideas and tweak the code to personalise 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, it's 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 bicycle 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.

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 a few materials, continue reading, otherwise 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

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.

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 a 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.

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 together 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, let's place all our components inside as shown below and it should look something like this:

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.

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:

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.

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 enclosure into the fixed enclosure, and it’s ready for action.

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.

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 is 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 a lot more features 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 inquiries 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: 

Schematics

Schematic 1
Speedometer using arduino and processing android app circuit diagram f4znc0dab7

Code

Code snippet #1Arduino
/*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
   }
 }

Comments

Similar projects you might like

Make a Wi-Fi Controlled Simple Robot Using Arduino

Project tutorial by rajitha_kumara

  • 300 views
  • 0 comments
  • 1 respect

Picture The Weather

Project tutorial by Windows IoT

  • 31,578 views
  • 23 comments
  • 89 respects

WiFi Weather Station

Project in progress by Dan Fein

  • 18,986 views
  • 15 comments
  • 46 respects

Toothbrush machine

Project tutorial by Simone

  • 8,024 views
  • 8 comments
  • 71 respects

Arduino and Android Based Bluetooth Password Lock

Project tutorial by Md. Khairul Alam

  • 11,578 views
  • 7 comments
  • 26 respects

MatrixClock

Project showcase by Mark Wilson

  • 3,652 views
  • 8 comments
  • 8 respects
Add projectSign up / Login