Project in progress
Magnetic Odometer Sensor Setup

Magnetic Odometer Sensor Setup © GPL3+

Measure distance traveled on any size wheel with the inexpensive and efficient Infineon 3D 2Go Magnetic Sensor!

  • 1 respect

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)

Apps and online services

About this project

Here, I will provide a solution for accurate odometer readings on small vehicles. The Infineon sensor is great for this application because IoT and RC vehicles have a relatively large power consumption, especially if they are fully electric. Because of this, the sensor's low power consumption is ideal.

Essentially, the magnetic sensor checks the amount of times a wheel has rotated and calculates distance traveled on board to save the main board's computational power for other tasks. It sends the current distance traveled through I2C to be as flexible and adoptable as possible. The unit is simple to attach to any wheel or RC vehicle.

Currently, I'm working on a way to improve the accuracy of readings and figuring out a way to calculate wheel slip for areas of low friction. Oh and making a repo for it :P.

Setting Up Development Tools

First off, you're going to need these links:

Sensors 2Go Main Page: Download the Evalkit GUI and User Manual

XMC Arduino Library: Full guide for XMC development in Arduino

I2C Anything Library: To learn more about I2C

The links above are very thorough, so I will leave them as references and summarize below.

Download and install J-Link and the Evalkit GUI. Read the user manual to gain more familiarity with the board itself. Honestly, I just skimmed through it, but it taught me more about the board and its potential applications. After that, plug in your board and follow the Evalkit instructions provided on setup. This is to verify that your sensor is complete and functioning.

If you want to develop in Eclipse, download the Dave IDE from Infineon. If you want to use Arduino IDE like me, download the XMC board manager and install it in the Arduino IDE. Now you can download the XMC Library and plug in your sensor. In the board selection dropdown menu, you should now see "XMC1100 XMC2GO". Select it and you're in business.


The hardware setup for this was pretty easy. Just solder some pins onto the I2C pins at the end and screw the rotation knob onto the sensor.


The program is ready to work as is with a minor modification. The current WHEEL_DIAMETER is 1, so you will get results in Pi. Change this to whatever measurement your wheel is and whatever units. Don't forget to change int to float if you are doing fractions of larger measurements (.2 feet). The variable "disTrav" is output as a float, though the video shows labels for ease of understanding. Since this is my first time using Wire and I2C, I used I2CAnything by Nick Gammon. It was super easy to use and gave me a good experience learning to use I2C. Connect the I2C ports into your board and connect to channel 21. Like I said, the main project is done, but I'll be working on improving accuracy until the contest is over. Let me know in the comments if you have any suggestions or questions.


Main FileC/C++
Paste this into your editor and upload it to your board.
/* Eduardo Pecina, Jr.  June 6, 2018 */
#include <Tle493d_w2b6.h>
#include <Wire.h>
#include <I2C_Anything.h>
int WHEEL_DIAMETER = 1; //units here will determine units for distance
boolean hasBeenCounted;//prevents a large number of false positive revolutions in case the wheel stays at the same position
boolean hasBeenHalfway;//minimizes the amount of false positives if the wheel moves back accidentaly
int numOfRots;//number of times the wheel completed a full revolution
int rpm;//rotations per minute
int lastAngle;//last recorded angle in radians before measurement termination 
int lastPart;//part that didn't count as a full rotation in the end
float disTrav;//distance in units of wheel's diameter
boolean isRecording = true;//user input
boolean isStopped = false;//user input
boolean isForwards;//checks to see if the wheel is going forwards and not backwards
Tle493d_w2b6 TSensor = Tle493d_w2b6();
void setup() {
 //starts sensor
 hasBeenCounted = false;
 hasBeenHalfway = true;
void loop() {
   Wire.beginTransmission (21);
   I2C_writeAnything (disTrav);
   Wire.endTransmission ();
   if((TSensor.getAzimuth() > 0)&&(!hasBeenCounted)&&(hasBeenHalfway)){
     hasBeenCounted = true;
     hasBeenHalfway = false;
     if(TSensor.getAzimuth() > 2){
       isForwards = false;
       isForwards = true;
   if(TSensor.getAzimuth() < 0){
     hasBeenCounted = false;
   if((TSensor.getAzimuth() < 2)&&(TSensor.getAzimuth() > 0)){
     hasBeenHalfway = true;
     //records current position to calculate remaining distance travelled
     //in case it didn't make a full rotation
     lastAngle = TSensor.getAzimuth();
     //this if statement prevents the last rotation from being counted twice
     //in case the user stops right on the rotation boundary
     if((lastAngle == PI)||(lastAngle == -PI)){
       //the direction is important to calculate how much of the wheel has spun
       //going forwards or backwards could be the difference between having spun
       //1/4th of the way versus 3/4ths of the way, a lot on a large wheel
         lastPart = (lastAngle+PI)/(2*PI);
         lastPart = ((2*PI)-(lastAngle+PI)/(2*PI));
     //calculates distance travelled in units of wheel's diameter
     disTrav = ((numOfRots+lastPart) * (PI * WHEEL_DIAMETER));


Similar projects you might like

RGB Infinity Mirror with 3D Magnetic Sensor

Project tutorial by Abdullah Sadiq

  • 12 respects

Touch Sensor and Sound Sensor Controlling AC/DC Lights

Project showcase by Anbumachi

  • 5 respects

Matrix Orbital EVE2 TFT, Servo and an AMS Magnetic Sensor

Project showcase by MatrixOrbital

  • 4 respects

Ultra-Sonic "Ping" Sensor

by MicroBob

  • 37 respects

Distance Sensor and OLED

Project tutorial by javier muñoz sáez

  • 65 respects

Wireless Magnetic Data Transfer

Project tutorial by Tomi Chen

  • 22 respects
Add projectSign up / Login