Control Your Remote Control Car With PC Keyboard

This is something I have been working with for some time. The goal is to control my remote controlled car using my computer's keyboard. Isn't it cool? I haven't used any complicated circuit diagrams etc! The idea is really simple; the only base theory used is, "a transistor can act as a switch".

There are 2 major modules

  1. Building the intermediate circuit that connects the PC interface to the car remote controller
  2. Creating the program that writes the values to the parallel port

MODULE (1)

Dispatching the remote controlled car

Inside the car (we don't need to do anything here; I have just dispatched it).

Control1.gif

Inside of your toy car remote controller;

I have marked the important components for us.

Control2.gif

We are going to control these 4 switches via our computer parallel port.

TRANSISTOR CAN ACT AS SWITCH!

A transistor can act as a switch, which means theoretically a small current flowing to the base controls the larger collector's current.

Please refer if you need more info.

http://www.kpsec.freeuk.com/trancirc.htm
http://www.kpsec.freeuk.com/components/tran.htm

The idea is based on this concept... so I used a BC548c transistor for mine (previously I used a 2SC828). You can use any general-purpose NPN transistor. And I used my serial port to send a signal to the transistor base, which makes the transistor act as a switch!!

So, here we are getting started:

Control3.gif

WAIT!!!

Do not implement this circuit and try to use it, there's one more thing left to do which is essential. Note what I said above, that we should send a small current (pulse) to the transistor's base, otherwise the transistor will be explode. So how can we do this?
The answer is simple; use a resistor to control your base current.

Control4.gif

Ok, so far so good...But again, how much resistance do I need? The answer is it depends on the transistor you are using. Here is the way you can calculate the resistance you need.

Calculation of Resistance

For 2SC828 Transistor

Supply Volt = 3v
Load = 50MA
HFE = 65MA
Min base current = 50/65 = 0.77MA

R = supply volt / (load/hfe * (0.77+= (0.77*30%)))
R = 4K (nearly)

For BC548c Transistor use the fallowing figures
Load =100MA
HFE = 110MA

Please refer to the transistor data sheets for the above info.

Attaching wires to the control points of the remote controller

Control5.gif

You have to find the four control points (four points for four switches) of the remote controller and there's one common wire (in Red). After finding those points attach wires to them.

Completed circuit

So the completed module contains four transistors inline with four resistors which connects the car remote controller to the parallel port of the computer through it.

Control6.gif

MODULE (2)

Writing the code

You have to write values (on/off pins) to the data pins of the  parallel  port. It will depend upon the pins you have chosen (D0 to D7).

I have used C# to do this. Since C# does not allow writing values directly to the parallel port I have used the 'Inpout32.dll' that you can download from:
http://logix4u.net/parallel-port/16-inpout32dll-for-windows-982000ntxp

If you are using any other language such as C++ where you can directly write to the parallel port, then you should be aware that it will be depend on the Operating System you are using. For example my experience is that Windows 7 will block you from directly writing to the port.

Here is my program in C#:

  1. [DllImport("inpout32.dll")]  
  2. public static extern void Out32(short PortAddress, short data);  
  3.   
  4. /* Parallel port number in decimal */  
  5. private short zPort = 888;  
  6. Keys k = Keys.None;  
  7.   
  8. /* Constructor */  
  9.   
  10. public RC_CAR()  
  11. {  
  12.     InitializeComponent();  
  13.   
  14.     Out32(zPort, 0);  
  15.     Thread.Sleep(100);  
  16. } 

Handler of the key down event of the user:

  1. /* 
  2. * up 1 
  3. * down 2 
  4. * left 4 
  5. * right 8 
  6. * */  
  7. private void RC_CAR_KeyDown(object sender, KeyEventArgs e)  
  8. {           
  9.     if (e.KeyCode == Keys.Up)  
  10.     {  
  11.         if (k == Keys.Left)  
  12.         {  
  13.             Out32(zPort, 5);  
  14.             Thread.Sleep(100);  
  15.             return;  
  16.         }  
  17.   
  18.         else if(k == Keys.Right)  
  19.   
  20.         {  
  21.   
  22.             Out32(zPort, 9);  
  23.             Thread.Sleep(100);  
  24.             return;  
  25.         }  
  26.         else{}  
  27.   
  28.         Out32(zPort, 1);  
  29.         Thread.Sleep(100);  
  30.         k = Keys.Up;  
  31.         return;  
  32.     }  
  33.     else if (e.KeyCode == Keys.Down)  
  34.     {  
  35.   
  36.         if (k == Keys.Left)  
  37.   
  38.         {  
  39.             Out32(zPort, 6);  
  40.             Thread.Sleep(100);  
  41.             return;  
  42.         }  
  43.         else if (k == Keys.Right)  
  44.         {  
  45.             Out32(zPort, 10);  
  46.             Thread.Sleep(100);  
  47.             return;  
  48.         }  
  49.         else { }  
  50.   
  51.         Out32(zPort, 2);  
  52.         k = Keys.Down;  
  53.   
  54.         return;  
  55.     }  
  56.     else if (e.KeyCode == Keys.Left)  
  57.     {  
  58.         if (k == Keys.Up)  
  59.         {                      
  60.             Out32(zPort, 5);  
  61.             Thread.Sleep(100);  
  62.             return;  
  63.         }  
  64.         if (k == Keys.Down)  
  65.         {                     
  66.   
  67.             Out32(zPort, 6);  
  68.             Thread.Sleep(100);  
  69.             return;  
  70.         }  
  71.         if (k == Keys.None)  
  72.   
  73.         {                      
  74.             Out32(zPort, 4);  
  75.             Thread.Sleep(100);  
  76.             k = Keys.Left;  
  77.             return;  
  78.         }  
  79.     }  
  80.   
  81.     else if (e.KeyCode == Keys.Right)  
  82.     {  
  83.         if (k == Keys.Up)  
  84.         {                     
  85.             Out32(zPort, 9);  
  86.   
  87.             Thread.Sleep(100);  
  88.             return;  
  89.         }  
  90.         if (k == Keys.Down)  
  91.         {                     
  92.             Out32(zPort, 10);  
  93.             Thread.Sleep(100);  
  94.             return;  
  95.         }  
  96.         if (k == Keys.None)  
  97.         {  
  98.             Out32(zPort, 8);  
  99.             Thread.Sleep(100);  
  100.             k = Keys.Right;  
  101.             return;  
  102.         }  
  103.     }  
  104.     else { }  
  105. }

 

Handler for the key up event of the user:

  1. private void RC_CAR_KeyUp(object sender, KeyEventArgs e)  
  2. {      
  3.     if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)  
  4.     {  
  5.         Out32(zPort, 0);  
  6.         Thread.Sleep(100);  
  7.         k = Keys.None;  
  8.         return;  
  9.     }  
  10.     if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)  
  11.     {  
  12.         if (k == Keys.Up)  
  13.         {  
  14.             Out32(zPort, 1);  
  15.             return;  
  16.         }  
  17.         if (k == Keys.Down)  
  18.         {  
  19.             Out32(zPort, 2);  
  20.             return;  
  21.         }  
  22.         Out32(zPort, 0);  
  23.         Thread.Sleep(100);  
  24.         k = Keys.None;  
  25.     }  
  26. }  

 

You can download the full source code, including executables, in the attached zip file.

Feel Free to contact me anytime!

Fun Coding
Cheers!


Recommended Free Ebook
Similar Articles