Scalextric Lap Counter

Not rated 12,818

Circuit Image

After receiving a Micro Scalextric set for Christmas and acquiring a large quantity of second-hand track from eBay, a lap counter was deemed necessary for racing against the clock and opponents. The objective was to accurately time laps, rather than simply counting them. This project involves a Scalextric Lap Counter based on a PIC Microprocessor, two IR LEDs, IR Photodiodes, and a character LCD display. The operation principle relies on the PIC running a timer that records each lap time when a car crosses the finish line, breaking an IR light beam. The circuit design includes two IR LEDs (one for each track) that are continuously powered, along with two IR Photodiodes for light detection. When the IR beam is uninterrupted, a 5V signal is sent to the PIC input pin; breaking the beam results in a voltage drop to approximately 0V. Additionally, push buttons are incorporated to reset individual lap times and counters for each track. The circuit also features a 16x2 character LCD display, which utilizes all available pins on the PIC. This display has multiple control lines and eight data lines for text display. After initializing the display, sending text is straightforward: set the R/S line high for text, R/W low for writing, and the Enable line high. The ASCII code for the desired character is sent by adjusting the data lines (e.g., the ASCII code for 'A' is 65, or 1000001 in binary), followed by setting the Enable line low to clock the data into the display. The display then shows the sent character and advances the cursor for the next character. Initializing the display was a challenge, as it is powered off upon startup, requiring specific instructions to turn it on and control the cursor visibility. An instruction set was found that is standard for these LCD displays, leading to the development of an LCD library for the PIC Microprocessor. Although assembly language could have been used, a free C compiler was chosen for its ease of use and debugging capabilities. The C code for the LCD library includes methods for initializing the LCD, moving the cursor, clearing the screen, and sending text either as strings or individual characters. A FOR loop is utilized to introduce delays between instructions, accommodating the slower response time of the LCD compared to the PIC's processing speed.

The Scalextric Lap Counter circuit is designed to provide an effective solution for timing laps in a racing scenario. The core components include a PIC Microcontroller, which serves as the brain of the operation, managing the timing and data processing tasks. The use of IR LEDs and Photodiodes allows for non-contact lap detection, ensuring that the system is responsive and reliable. Each IR LED emits infrared light, which is detected by the corresponding photodiode. When a car crosses the finish line, it interrupts the IR beam, signaling the PIC to record the lap time.

The choice of a 16x2 LCD display allows for clear visualization of lap times and counters, facilitating easy reading during races. The integration of push buttons provides user-friendly control for resetting lap times, enhancing the functionality of the system. The software implementation in C enables straightforward coding practices, making it easier to implement features and debug issues. The initialization and control of the LCD are critical components of the project, as they ensure that the display functions correctly and presents the desired information to the user.

Overall, the Scalextric Lap Counter project exemplifies the application of microcontroller technology in hobbyist electronics, combining hardware and software elements to create an interactive and engaging racing experience. The approach taken in this project can be adapted for similar applications, showcasing the versatility of PIC microcontrollers in various electronic designs.After getting some Micro Scalextric for Christmas and shortly after acquiring a vast mount of second-hand track from eBay I decided I needed a lap counter so I could race against the clock with opponents. I didn`t just want to see who could do 10 laps first I wanted to time the laps to a reasonable degree of accuracy to see who was fastest.

Bu ilding something to do that shouldn`t be too difficult I thought, and now here is my project page for my Scalextric Lap Counter. The lap counter is based around a PIC Microprocessor, a couple of IR LEDs and IR Photodiodes, and an LCD character display.

The basic theory of operation is that the PIC will be running a timer and each time the IR light beam is broken by a car crossing the finish line the lap time will be recorded and displayed in the LCD. The circuit for the lap counter is actually fairly simple. There are 2 IR LEDs (one for each track) that are constantly powered and 2 IR Photodiodes to detect the light.

When the IR light is detected (beam not broken) the voltage going to the input pin on the PIC is 5v. When the beam is broken the voltage drops to 0v (or thereabouts). I`ve also added a couple of push buttons to let the user reset the individual lap times and counter for each track. The last bit of the circuit is the LCD display which uses up all the spare pins on the PIC! The LCD display I chose to use is a 16G—2 character display. These displays have a number of control lines and eight data lines in order to display text on the screen.

Once the display is initialised sending text to the the screen is pretty straight forward. You simply set the R/S line high  as you`re sending text, set the R/W line low  as you`re writing to the display, and set the Enable line high . You then send the ASCII code for the character you want to display by setting the 8 data lines accordingly (e.

g. to send A  the ASCII code is 65 which in binary is 1000001), and finally set the Enable line low  to clock the data into the display. The display should then show the character you just sent and advance the cursor along ready for you to send the next character.

Easy! You`ll notice that I said once the display is initialised  just now. This is the bit that caught be out for quite a while. I was sure I had connected the LCD screen up properly and I was sure I was sending text correctly but nothing was being displayed. After some extensive googling I found out that when the screen is powered up the display and cursor are turned off.

Therefore you need send an instruction to the LCD display to get it to turn the display on and set the cursor to be visble (or not if you wish). After more Googling I came across an instruction set that seems to be pretty standard across these LCD character displays: Once I`d figured out how to initialise the display, move the cursor around and display text, it was time to write an LCD library for the PIC Microprocessor that I could use in my Lap Counter code as well as future projects.

Now I`m sure most hobbyists who have used PIC Microprocessors will have done so using assembly language, and although this project is simple enough that I could have used assembly language to write the program code I chose to use a free C compiler because it`s just that much easier and quicker to write the code, plus it`s easier to debug. The C code for my LCD library is shown below. This basically consists of an init method to initialise the LCD screen, and some methods to move the cursor, clear the screen, and send text wither by sending a string or individual characters at a time.

Notice that when I am toggling the LCD control lines I have used a FOR loop to insert a delay between the instructions. This is because the LCD screen is relatively slow compared to the speed of the PIC and if I simply toggled all the data and control lines with out any delays the LCD screen wouldn`t be able to keep up.

The minimum time delays 🔗 External reference




Warning: include(partials/cookie-banner.php): Failed to open stream: Permission denied in /var/www/html/nextgr/view-circuit.php on line 713

Warning: include(): Failed opening 'partials/cookie-banner.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/nextgr/view-circuit.php on line 713