In many vehicles, there are devices that calculate the distance traveled and are essential for presenting information to the driver.

Thus, through this information, it is possible to monitor the distance traveled between two points, for example, through the vehicle odometer.

For this project you'll use the following components:

Therefore, through this article, we will teach you how to assemble your distance calculation device using the reed switch sensor.

The Project

The following project was created to calculate the traveled distance by the bicycle of the gym. 

In addition, you'll learn how to create programming for the project.

This project has three functionalities:

  • Calculate the distance traveled by bicycle;
  • Device Startup Radius Configuration;
  • Adaptable to any bike.

To access these functionalities, the user will use the three buttons of the system. Each button has your functionality. In the system we have the following buttons:

  • Increment Button: It will be used to enter in the option to configure the radius of the wheels and increment the radius value;
  • Decrement Button: It will be used to decrement the option to configure the radius of the wheels;
  • Enter Button: It will be used to insert the value of the radius in the system.

In addition, we have the Reed Switch Sensor. It is responsible to detect when the wheels do a complete turn.

For detecting this, itis needs to install a magnet on the wheels. The Reed Switch is presented.


Figure 1 - Reed Switch Sensor.

Thus, every time the magnet approaches the sensor, it will actuate the Reed Switch sensor. The process works through the following equation:

Travelled Distance = 2 *π * radius * TurnNumber

Through this equation, we'll know what is the traveled distance performed by the bicycle. In the equation, the radius is inserted by the user and Turn Number is calculated through the number of turns of the wheel.

And to detect the turns of the wheel is needed to install a magnet in the bicycle wheel and to install the Reed Switch Sensor near the Wheel.

To easier the process, we create a printed circuit board to connect the Reed Switch Sensor and the three buttons. The Printed Circuit Board is presented below in Figure 2.


Figure 2 - Printed Circuit Board of the Project.

As is shown in the PCB is possible to see the Arduino Nano. It is responsible to control all systems. In addition, we have 5 JST connectors.

The C1 until C4 connectors are used to connect the three buttons and the Reed Switch Sensor. Now, the C5 Connector is used to connect the LCD 16x2 I2C.

Therefore, through this system, you can install the project in your bicycle and obtain the traveled distance value.

For this, you can use the code presented below.

        #include <EEPROM.h>
#include <LiquidCrystal.h>

Pinos de conex?o dos bot?es e sensor reed switch
8 — Sensor Reed Switch
9 — Decremento
12 — Incremento
11 — Enter

#define MEMORIA 120
#define PosRaio 125

#define ReedSwitch 8
#define BotaoEnterOk 11
#define BotaoIncremento 12
#define BotaoDecremento 9

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

bool sensor = 0, estado_anterior = 0, Incremento = 0, Decremento = 0;
bool IncrementoAnterior = 0, DecrementoAnterior = 0, BotaoEnter = 0, EstadoAnteriorIncremento = 0;

byte cont = 0;

unsigned long int VoltaCompleta = 0;
unsigned long int tempo_atual = 0, ultimo_tempo = 0;

float DistKm = 0;
unsigned int raio = 0;
float Distancia = 0;

void setup()
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(12, INPUT);


//Regiao de codigo para configurar o raio da roda do veiculo
if( != 73)
Read more »