Speed Measurement System

A DIY Gatsometer with infra-red light barriers

The light barrier system described in this article allows accurate measurement of the absolute speed of model cars, planes and other moving objects. In education and training programs, the system forms a perfect contactless speedometer. Over to you to football and golf fans to see who has the meanest ball kick or club swing.

Features
– Speed measurement within range of 0.01 to 999 km/h
– Speed readout in m/s or km/h on 1×16 character dot matrix display
– Elapsed time readout (max. 16.777215 seconds)
– Resolution 1 μs
– Light barrier distance adjustable between 1 and 255 cm
– Optical alignment aid
– Single or continuous measurements
– Powered by 9-V battery
– Current consumption approx. 45 mA.

1

Light barriers systems are around us in more situations than you would expect. Unnoticed, they do their job scanning items at the supermarket checkout, detecting vehicles in parking lots, video tapes in VCRs or persons entering or leaving buildings. Usually, infra-red light is employed because it is invisible to the human eye and ensures a high degree of immunity against interfering light sources.

Whereas simple light barriers operating without modulation, like the slotted light barriers that check if a CD or disk is inserted in the PC, have relatively simple functions, the above mentioned

applications in parking lots, garages and security systems have far more challenging requirements in respect of ‘noise’ immunity. The solution, in nearly all cases, is to employ a 36- kHz carrier. The receivers are then designed to respond only to changes in the frequency. A microcontroller system is then  thrown in to analyse the receiver output signal and evaluate the length of any interruption. This is done to prevent erroneous triggering of an alarm in the case of, say, an insect flying or crawling through the barrier.

As illustrated in Figure 1, speed measurement using a light barrier may be achieved with just one sender and one receiver. A disadvantage of this system is the risk of inconsistent measurement results if the moving object has an irregular shape causing multiple

11interruptions of the light beam. In addition, there’s no assurance that the measured object follows the same, straight path when travelling through the barrier, again causing unreliable results.

Several infra-red detector ICs have been used in many projects published in this magazine over the past few years. One of these, the SFH505 from Siemens, has become a kind of standard component for this function. The SFH505 and a other functionally compatible devices (including IS1U detectors from Sharp) are found in lots of equipment of the ‘consumer electronics’ variety. Although these components are versatile and cost effective, they are less suitable for the project we have in mind, mainly because of the following aspects.

– The output response time to beam interruption is subject to too many time tolerance factors;

– For an acceptable range, the infrared light may not be modulated all the time. Pulses need to be inserted to prevent the control electronics from considerably reducing the receiver sensitivity.

– Because of the required pauses within the modulated signal, reproducible speed measurement is not feasible mainly because beam interruption (by the object) can not be distinguished from a pause (inserted by the system).

Despite the extra hardware, the system proposed in Figure 2 is the better alternative, if only for its much higher accuracy and more reliable measurement results when used to measure the speed of objects passing through the barrier.

To make real-life application of the above system as flexible as possible, the design allows the user to set up the length of the path the object has to travel along in order to interrupt the two light beams. In practice, this is done by placing the first and second barrier at a suitable distance from each other, and ‘informing’ the system about the exact distance before the measurement commences.

Sender and receiver

The Kodenshi Company from Korea have developed two modules (Emitter PIE-310 and Detector PID-310) for light barrier applications. Thanks to their high degree of integration, these modules contain all components necessary for a long-range yet noise immune light barrier system. From the datasheets (in Korean) we were able to distil the following important characteristics:

– IR LED with internal modulation and associated photo detector in a separate, compact case with a lens system.
– Size approx. 17 × 8 × 7 mm
– Range 1 to 8.5 m (3 to 25 ft.)
– Active-low open-collector output
– Control input on sender
– Highly tolerant of ambient light thanks to optical filters and internal modulation.
– Low-cost sensor applications at large distances
– Suitable for use in Reflection mode
– 3-pin wire connection
– Supply requirements 5 V/5 mA (receiver) and 5 V/15 mA (transmitter)
– Switching speed 0.5 ms
– Half-sensitivity angle +/-5 degrees
– operating temperature –10 to +60 ºC

The modules, whose pinouts are given in Figure 3, are intended for use in paper sensors, distance sensors in reflection mode, counter and registration systems or proximity detectors.

The simplicity, relatively low cost and reliability of the circuit to be discussed is mainly due to these ready-made modules from Kodenshi. The module connection cables are available as accessories. They are essential, however, because it is very difficult to solder wires to the device pins.

11

The microcontroller

By virtue of a programmed microcontroller, the circuit is relatively uncluttered. The circuit shown in Figures 3 and 4 consists of two light barriers, a display for the speed readout and system settings, four pushbuttons and, of course, the central microcontroller.

A ‘low power, low price, low pin count microcontroller’ (to use the words of Philips) type 87LPC762 is employed here. This device is based on the well-established 8051 architecture. Here, it is clocked at 6 MHz (1 us cycle time), in view of the calculation load and the high time resolution required by the system.

The main features of the 87LPC762 may be found in the datasheet:

– 2 KBytes ROM
– 128 Bytes RAM
– 32 Bytes user programmable EEPROM
– 2.7 to 6 V supply voltage
– Two 16 Bit Timer/Counter
– Integrated Reset
– Internal RC oscillator for optional use
– 20mA drive capacity at all port pins
– up to 18 I/O pins
– 2 analogue comparators
– I2C interface
– Full duplex UART
– Serial in-circuit programmable

Because there are not enough I/O pins available for direct connection of the pushbuttons and the LCD in 8-bit mode, some pins have been given a double function by clever programming. Pushbutton connections ‘+’ and ‘–’ share a port pin line with the display control lines. For the display control these pins are programmed as push-pull stages, while input-only mode is briefly selected when polling the pushbuttons for activity. Resistors R1 and R2 limit the short-circuit current when a pushbutton is pressed at the same time the display is being controlled.

The light barrier receiver outputs are directly connected to the microcontroller inputs. The internal pull-up resistors are used because the light barrier has an open-collector output.

Circuit and construction

The display is an alphanumeric dot matrix type with one line of 16 characters. This version should be widely available because it represents a kind of industry standard, including the use of the Hitachi HD44780 LCD controller and its command set. The display requires a single supply voltage of +5 V (no additional –5 V!). Important things to watch out for are the pinout and with it the order of the connections (upper left corner), as well as the internal RAM address allocation. Only LCD modules with a multiplex rate of 1/16 have the right address order 00, 01, 02, 03, 04, 05, 06, 07, 40, 41 to 47. Although more information has to be displayed than can be fitted on a single line, a 1-line display is used instead of a 4-line type because the user is prompted to press a button to view the information. The display contrast is adjusted by preset P1. Turn P1 across its full travel if no characters are displayed when the circuit is first started and you are sure that no construction  errors have been made.

As usual the circuit is powered via a 7805 fixed voltage regulator.

With simplicity and cost in mind, the sender and receiver are connected to the processing electronics via a single 9-way sub-D connector. The light barrier wires have to be connected in accordance with Figure 3.

In this application, the sender control inputs are not used — they are either not connected or hardwired to ground.

Practical use

To enable the controller to respond instantly to changes at the light barrier outputs, the measurement routine is interrupt-driven. As a consequence, port pins P1.3 and P1.4 are not constantly polled by the software. Instead, a piece of logic inside the microcontroller is set up to control the time measurement. The advantage of this arrangement is that in addition to instant reaction to events, the software has sufficient spare time for other chores like driving the display and scanning the pushbuttons for activity. This is not possible just like that and using any input pin — P1.3 and P1.4 are ‘specially prepared’ to handle such exacting jobs.

At a falling pulse edge, the internal program halts instantly and jumps to a special routine written to handle the task on hand.

Any speed measurement starts when the first light beam is interrupted. Instantly, the 16-bit counter inside the microcontroller is started at a count rate of 1us. Overflows that occur are added in an 8-bit register, allowing a maximum period of 16.777215 seconds to be measured. The object velocity, v, is then computed by the microcontroller using the simple equation v = d / t using the distance, d, between the barriers and the timer state, t.

Using the default settings, the software assumes a barrier distance of  0.1 m, a readout in m/s and ‘continuous’ as the measurement mode.

To simplify the calculations, the resolution is limited to two decimals, which should be sufficient in most if not all cases. If you require better accuracy, get out your pocket calculator and use the indicated counter value and the light barrier distance. You should, however, always take the 0.5-ms delay of the light barriers into account. Note, however, that this delay is about equal on both receivers so that should not be a problem.

More important than tweaking the numbers behind the decimal point (or comma, in this case) is to make sure that the senders and receivers are correctly aligned and properly secured, while their distance remains easily adjustable for the speed measurement you want to perform.

With the barriers installed, connected up and the software switched on, the software takes over, guiding you through a menu in which various options may be selected.

MODE key

Press this key to step through the four menu items, as follows

TEST – DISTANCE – MODE –

SPEED – TEST

TEST causes the state of the light barrier receivers to be displayed. The message OK means ‘high level measured’ and indicates that the light beam from the sender is being picked up. A Low indicates that the beam is either interrupted or not properly aimed at the receiver. Before any measurement is started, both outputs should flag ‘OK’. After a reset or after the circuit is switched on, this menu always appears first.

It should be noted that a unconnected light barrier receiver will also cause OK to be displayed, simply because of the internal pull-up resistors at the controller inputs. Therefore, as a ‘security check’, make a habit of interrupting the light beam manually while watching the display indication.

Another source of errors is the lobe shape of the light beam, which may reach the other receiver when the barriers are placed at a relatively small distance.

When DISTANCE is displayed, the value to be processed by the microcontroller is entered in centimetres. The default value is 10 cm. As a matter of course, you have to make sure that the displayed value is the real distance between the light barriers.

MODE allows you to select the measurement mode: SINGLE performs just one measurement. When the barriers are triggered again, no new measurement is performed.

CONTINUOUS enables results to be refreshed by any new measurement. The current measured value is always overwritten.

SPEED indicates the measured velocity of the object. Three units are available to choose from: m/s, km/h and seconds. The maximum time is 16.777215 seconds. Exceeding this value causes ERROR to be displayed.

START key

This pushbutton is only read in SINGLE mode. It launches a measurement when neither of the light barriers is interrupted. The display then indicates READY. If a barriers fails to detect a signal, the software jumps to TEST, where the user can see

what’s wrong. Once the problem is solved, another press of the START key causes the SPEED or DISTANCE menu to appear.

+ and – keys

In traditional fashion these two keys are used to select different parameters in the individual menus. In the DISTANCE menu, for example, the keys allow values between 1 cm and 255 cm to be set up.

In the MODE menu, both keys have the same function, changing between SINGLE and CONTINUOUS.

In the SPEED menu, finally, the + and – keys allow you to choose between a readout in m/s, km/h or seconds (the latter for the convenience of pocket calculator users).

Components

Resistors:
R1,R2 = 4kOhm 7
R3 = 10kOhm
R4,R5 = 100kOhm
P1 = 10kOhm preset
Capacitors:
C1 = 10µF 16V
C2-C5 = 100nF
C6,C7 = 15pF
Semiconductors:
IC2 = 7805
IC3 = 87LPC762, programmed, download from Rapidshare password 010206-41
Speed_Measurement_System_Hex_File
Miscellaneous:
K1 = 9-way sub-D socket (female), angled pins, PCB mount
K2 = 14-way SIL pinheader
S1-S4 = pushbutton
S5 = on/off switch
X1 = 6MHz quartz crystal
LCD dot matrix display, 1×16 characters, 44780-compatible
2 combinations of IR-Sender PIE-310 and IR receiver PID-310
4 module connecting cables

l010206 51

Reference

Dot matrix display:
http://www.datamodul.de/displaytechnik/lcd-alpha/bt_11608.htm
http://electronicassembly.de/
http://www.schukat.com (Display Fa. Sharp)
Microcontroller:
www-us.semiconductors.philips.com/ mcu/
Light barrier datasheets:
http://www.kodenshi.com/pdfs/g-1.pdf

Electro032002

Leave a comment