Friday, March 29, 2024

PC-Based Wireless Control for Toy Car

By Bodhibrata Mukhopadhyay, Gourabsil & Subhajit Mazumdar

Controlling the toy car

‘W’ forward movement (Q1=1, Q2=0, Q3=1, Q4=0). The toy car moves forward when all the motors move clockwise. To achieve this, the output logic at Q1, Q2, Q3 and Q4 should be high (1), low (0), high (1) and low (0), respectively. Character ‘W’ is defined in the code to give 1010 bits in the output. That is, when you type ‘W’ character from the keyboard, the microcontroller generates 1010 bits at its port pins `p1.1 through p1.4. This signal is sent to relay-driver section T1 through T4.

‘S’ backward movement (Q1=0, Q2=1, Q3=0, Q4=1). The backward movement takes place when all the motors move anticlockwise. So signal 0101 is sent to relay-driver section T1 through T4. Character ‘s’ is defined in the code to give 0101 bits in the output.

‘D’ right drift (Q1=1, Q2=0, Q3=1, Q4=0 (for 54 ms) and Q1=1, Q2=0, Q3=0, Q4=0 (for 108 ms)). Right drift is possible by rotating the left motors at a high speed and the right motors at a low speed. This is possible with the pulse-width-modulated (PWM) pulse given to the right motors. The right motors are given a pulse train of 33 percent duty cycle so that these rotate at one-third the speed of the left motors. The car takes a right turn in forward direction resulting in a drift. So signal 1010 is sent for 54 ms and a signal of 1000 for the next 108 ms to transistors T1 through T4. Character ‘D’ is defined in the code to generate the 1010 and 1000 signals with 54 ms and 108 ms delays, respectively.

‘A’ left drift (Q1=1, Q2=0, Q3=1, Q4=0 (for 54 ms) and Q1=0, Q2=0, Q3=1, Q4=0 (for 108 ms)). Left drift is possible by rotating the right motors at a high speed and the left motors at a low speed. This is possible with the PWM pulse given to the left motors. The left motors are given a pulse train of 33 percent duty cycle so that these rotate at one-third the speed of the right motors. The car takes a left turn in forward direction, resulting in a drift. So signal 1010 is sent for 54 ms and signal 0010 for the next 108 ms to transistors T1 through T4. Character ‘A’ is defined in the code to generate 1010 and 0010 signals with 54ms and 108ms delays, respectively.

‘Q’ sharp-forward left turn (Q1=0, Q2=0, Q3=1, Q4=0). The toy car moves to the left sharply in the forward direction when the left motors are static and the right motors move clockwise. So signal 0010 is sent to transistors T1 through T4. Character ‘Q’ is defined in the code to generate 0010 bits in the output.

- Advertisement -

‘E’ sharp-forward right turn (Q1=1, Q2=0, Q3=0, Q4=0). The car moves to the right sharply in the forward direction when the left motors move clockwise and the right motors are static. So signal 1000 is sent to transistors T1 through T4. Character ‘E’ is defined in the code to generate 1000 bits in the output.

‘C sharp-backward left turn (Q1=0, Q2=0, Q3=0, Q4=1). Sharp left turn takes place when the left motors are static and the right motors move anticlockwise. The car moves to the left sharply in the backward direction. So signal 0001 is sent to transistors T1 through T4. Character ‘C’ is defined in the code to generate 0001 bits in the output.

‘Z’ sharp-backward right turn (Q1=0, Q2=1, Q3=0, Q4=0). The car moves to the right sharply in the backward direction when the left motors move anticlockwise and the right motors are static. So signal 0100 is sent to transistors T1 through T4. Character ‘z’ is defined in the code to generate 0100 bits in the output.

- Advertisement -

‘U’ stop (Q1=0, Q2=0, Q3=0,Q4=0). To stop the car, all the motors should be static. This is achieved by sending signal 0000 to the output of the microcontroller at its port pins p1.1 through p1.4. The character ‘u’ is defined in the code to generate 0000 bits in the output to stop the toy car.

Software program

Flow-chart of the program
Flow-chart of the program

Here is the flow-chart of the program. The program is written in ‘C’ and compiled using Keil C software. The hex code generated using Keil software is burnt into the chip using Flash Magic programming software from NXP (Philips) Semiconductors.

Keil C μVision3 operations

  1. Run Keil μVision3 application from the desktop. From ‘Project’ menu, select ‘New Project’ option. Name the project as ‘efytoy.uv2’ and save it.
  2. Select microcontroller P89V51RD2 from the database under NXP (Philips) option.
  3. Right-click ‘Source Group1’ option in ‘Project Workspace’ window on the left-hand side of the screen. Click ‘Add Files to Source Group 1’ option to add the toycar.c file.
  4. Right-click ‘Target1’ option from ‘Project Workspace’ and select ‘Options for Target 1.’ The window appears as shown below.

    Options for Target 1
    Options for Target 1
  5. Change the Xtal (MHz) value to 11.0592 as used in the project. Click ‘Output’ menu and tick the button against ‘Create HEX File’ option.
  6. Now close the window and go to the main window. Compile the project by clicking ‘Build Target’ option. The program will be compiled with the message as shown here.
Program compilation output screen
Program compilation output screen

Now, the efytoy.hex code will be generated in the directory where the project file efytoy.uv2 is located. This hex code is used for programming the chip.

Programming the chip using Flash Magic

Flash Magic window
Flash Magic window
  1. Run the Flash Magic software and select the device as P89V51RD2 and ‘Erase all Flash’ option as shown above.
  2. In the ‘Advanced Option,’ uncheck ‘Use DTR to control RST’ and ‘Assert dtr and rst while com port open’ options.
  3. Browse the efytoy.hex file from your PC and load it onto the main screen. Press ‘Start’ button to program the chip.

Construction and testing

A single-side PCB of the transmitter circuit and its component layout, and a single-side PCB of the receiver circuit and its component layout is available for download here.

Burn the code into P89V51RD2 and mount the components on the receiver PCB.

Mount the populated PCB, 12V battery and four motors on a suitable chassis, preferably a 20×15 cm2 metal chassis. Use proper nuts and bolts to fix them firmly on the chassis. Four wheels, each of 7cm dia., are attached to shafts of respective motors.

After mounting the components on the transmitter PCB, connect the circuit to the serial port of the computer using a serial cable. If your PC has a USB port only, you may use a USB-to-serial converter. Now switch on the 9V power supply using switch S1.

Before sending the data from your computer, check which comport is connected to the circuit. Set the baud rate of the comport to 1200, stop bit to 1 and data bits to 8. Go to ‘Device Manager’ option from your desktop to do these settings. Now run a serial communication software such as Terminal v1.9b, select the com port and make the aforementioned settings. After completing all the settings and component assembly, switch on the power supply to the transmitter and receiver circuits.

Run Terminal v1.9b software and activate the connection by pressing ‘Connect’ button followed by W, S, D, A, Q, E, C, Z or U key on the keyboard. The ASCII code corresponding to that key will be transmitted serially in a 10-bit (1 start bit+8 data bits for ASCII code+1 stop bits) binary data stream. The toy car will move as per the input from the keyboard.

Source Code

The source code of this project is available here.


The project was first published in September 2010 and has recently been updated.

SHARE YOUR THOUGHTS & COMMENTS

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Calculators