Versatile digital speedometer uses few components
A speedometer measures a wheel's rotational speed. Unlike conventional mechanical and moving-magnet designs that use analog moving-pointer displays, the electronic speedometer in this Design Idea features a digital readout and a power-saving device that uses few components. Figure 1 shows the digital speedometer's circuit design. An Atmel AVR AT90S2313 microcontroller, IC1, drives IC3, a 16-character, two-row LCD. All components except IC4, an Allegro A3121 Hall-effect sensor reside on a pc board within the reach and view of the vehicle's operator. The Hall-effect sensor attaches to the vehicle near its periphery and a fixed distance from the wheel's axle. When the wheel rotates, a permanent magnet attached to the wheel passes the sensor, activating it and generating one short pulse for each revolution of the wheel.
After you apply the pulse's rising edge to the IC1's INT0 input, the rising edge generates a high-priority interrupt. The AVR calculates the elapsed time between two interrupts, computes the speed and distance traveled, and displays the results on the LCD. One of IC1's internal timers, Timer0, increments after every N clock pulses. Distance traveled equals 2πR, where R is the wheel's radius. To calculate speed, IC1 divides the distance the elapsed time travels. In this application, the display shows speed in kilometers per hour.
In addition, IC1 keeps the track of distance traveled by incrementing a register every time a sensor interrupt occurs. It compares this register value with a number that's equivalent to a 100m distance traveled, and, when the register value exceeds the 100m constant, IC1 increments the distance register. The display shows the distance traveled in kilometers, and a location in IC1's EEPROM retains the distance even when a users switches off power to the speedometer. Maximum values of the design include speeds of 0 to 255 km/hour and distances as far as 9999.9 km.
The design requires a 5V-dc power supply to work properly. To accommodate higher power-supply voltages, a bridge rectifier and a 7805 voltage regulator, IC2, accept power supplies ranging from 6 to 24V dc or ac for indoor applications. At 12V-dc input, the speedometer draws approximately 43 mA, or approximately 500 mW, under normal conditions. Switching on the LCD's backlight for night operation increases current drain by approximately 11 mA for a power consumption of approximately 730 mW.
You can download the source code for IC1's program here and assemble the software with Atmel's AVR Studio 4 software. You can alter constants within the software to accommodate wheels of various radii for other applications. Future enhancements to the software would allow measurement and display of a rotating object's speed in revolutions per minute or show elapsed distances when you use the device as a trip meter.
Check out our Best of Design Ideas section!