The readings of the distance traveled are saved in an external serial EEPROM. Here, a 24C02 serial EEPROM based on Philips I2C protocol is used.

I2C bus protocol

The I2C bus consists of two active wires and a ground connection. The active wires, serial data line (SDA) and serial clock line (SCL) are bidirectional.

Every device hooked up to the bus has its own unique address, no matter whether it is an MCU, LCD driver, memory or ASIC. Each of these chips can act as a receiver and/or transmitter, depending on the functionality.Obviously, an LCD driver is only a receiver, while a memory or I/O chip can be both transmitter and receiver.

The I2C bus is a multi-master bus. This means that more than one IC capable of initiating a data transfer can be connected to it. The I2C protocol specification states that the IC that initiates a data transfer on the bus is considered the bus master. Bus masters are generally microcontrollers. Consequently, all the other ICs are regarded as bus slaves at that instant.

Circuit operation

Let’s assume that the MCU wants to send data to one of its slaves. First, the MCU will issue a START condition. This acts as an ‘attention’ signal to all of the connected devices. All ICs on the bus will listen to the bus for incoming data. Then the MCU sends the address of the device it wants to access, along with an indication whether the access is a ‘read’ or ‘write’ operation. Having received the address, all ICs will compare it with their own ad-dress. If it doesn’t match, they simply wait until the bus is released by the stop condition. If the address matches, the chip will produce a response called ‘acknowledge’ signal. We have used write operation in this project.

Once the MCU receives the acknowledge signal, it can start transmitting or receiving data. In our case, the MCU will transmit data. When all is done, the MCU will issue the stop condition. This signals that the bus has been released and that the connected ICs may expect another transmission to start any moment.

We have several states on the bus: start, address, acknowledge, data and stop. These are all unique conditions on the bus. In our project, the microcontroller is the master and the serial EEPROM is the slave.

The readings are periodically stored in the EEPROM and the previous reading is retrieved from the EEPROM each time the bike is started.

Speed sensor

For this project, we make use of a simple homemade speed transducer. The rotation of the wheel is sensed by the combined action of a reed switch and a magnet fixed on the wheel. The sensor sends a pulse to the microcontroller each time a revolution is made.


An optocoupler is used to counter the effects of bouncing when the contact of reed switch is closed.

Power supply

The power supply for various parts of the circuit is drawn from the vehicle’s 12V battery after reducing it to 5V using a three-terminal voltage.


flow chart of the program

The ‘Init_EEPROM’ and ‘Speedo’ source codes of this project are written in Assembly language. These are compiled using an open-source ASEM-51 assembler to generate the Init_EEPROM.hex and Speedo.hex files. The hex files are burnt into the microcontroller chip.

Two internal timers of the microcontroller are configured as 8-bit counters to count the number of pulses generated by the speed sensor. One timer is used to measure the distance and the other for speed calculation.

A software delay of one second is generated after the speed counter is triggered. The speed count value is obtained from the counter registers. To speed up the process, a look-up data table is stored in the ROM that helps the microcontroller to convert the number of pulses into the corresponding speed values. The program flow-chart is shown in Fig. 2.

The ‘distance’ counter is incremented every 100 metres. The wheel has to make 53 revolutions to achieve this. The distance counter is loaded with an initial value of 203 (255-53+1) and is incremented on each revolution. After 53 counts, the timer overflows and generates an interrupt to notify the microcontroller that 100 metres are covered.

In the interrupt service routine, the microcontroller updates the corresponding ‘DS1’ distance variable. Instead of saving distance variables after each cycle, the microcontroller saves these readings when the vehicle is athalt (speed is 00.0 km/hour). In other words, when the vehicle is stopped at traffic signals or before the ignition key is turned off, the last reading is saved to the EEPROM. The same reading is again retrieved from the EEPROM when the bike is turned on next time and the readings are updated for each trip.



Please enter your comment!
Please enter your name here