Versatile Digital Speedometer Uses Few Components
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 100 m 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 5 V-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 24 V dc or ac for indoor applications. At 12 V-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.
Schematics on theme: