Arduino PS2 Mouse controlled RC car

Demo Video


This is my first Arduino based project, which I built during @tinkernick's beginners Arduino course.  Here's how you can build your own:

Choose your car and mouse

 

Find a radio controlled car to hack.  I bought the cheapest RC car I could find, it cost about £10.  You also need a PS/2 mouse - any PS/2 mouse will be fine.  Note that most modern mice use USB (which you don't want), but PS/2 ones are still very easy to buy for as little as £1.

The hack is pretty simple - we'll modify the radio control unit (car stays unmodified) so that instead of a human pressing the buttons, the arduino board will press them for us when the mouse is moved.

Figure out how the RC controller works

Take the RC controller apart and figure out how it works.  Expensive radio controlled cars have servo motors for steering and variable speed control on their main motor, but a cheap car like this just has on/off switches for each of forward / backward / left and right.  You can follow the tracks from each side of each switch to the nearest solder joint on the original board.  Find the pads for each switch and confirm with a multimeter that the solder joints are the correct ones - when the switch is pressed, the resistance between the two relevant joints will be zero.


Once you've identified the joints that matter, attach patch wires to each point with a soldering iron.


The controller I used had a common ground (blue wire in the photo above) which the pads for up/down left/right were being connected to when the relevant switch was pressed.  In the photo above, you can see that I have traced these connections back to the point where solder joints already existed and attached wires (orange, yellow, white, red).  It is a good idea to use different coloured wire for each of the directions so you can keep track of which one is which when working on a breadboard.

To switch the connections from software running on the Arduino board, we need to build a simple circuit on a breadboard to allow an Arduino pin to drive each 'button' without being physically connected in a circuit - we can use optical isolators for this - the opto-isolator part I used was a 4N35.


You need to build the above circuit four times (once for each direction).  The common ground from the RC controller will be connected to pin 4 of the 4N35 and the direction switch lead you soldered on will be connected to pin 5.  Note that the Arduino connections are completely isolated from the RC controller connections - the Arduino pin for turning on the controller switch for the given direction will be connected to pin 1 on the 4N35.

This produces a layout on the breadboard like the diagram below:


My slight less neat version :-) :

Right now you could write a program for the Arduino which drives the car all by itself, go forwards, backwards and turn left and right - cool!  But let's make it a bit more exciting by adding the mouse.

For this, we'll use the PS2 Mouse Interface library available on the Arduino webpage.  Install the library by unzipping the ps2.zip file in your libraries folder (on Mac Documents -> Arduino -> libraries; Linux ~/sketchbook/libraries).

There are good and detailed instructions on that page about how to connect the mouse itself to your board, though there is some confusion over which pins are which - because the pin out diagrams for PS2 connector on that page is for the female version of the connector - the PORT - i.e. the thing the mouse plugs into, whereas the end of your mouse cable has a male connector which is the mirror image of the pinout diagram.  Don't worry - there is a photo of the pinout at end of a male mouse connector on that page which is correct, follow that.

I cut the connector off the end of my mouse and soldered new leads directly to the wires in the cable.  If you don't want to destroy your mouse, you could get a PS/2 connector to add to your breadboard and connect to that instead.

With the hardware setup complete, let's put some software on the board to
  • read data from the mouse
  • on any forward movement, tell the RC controller to press the forward button
  • on any backwards movement, press back
  • on left movement, press left
  • on right movement, press right

That can be accomplished with the attached car_mouse sketch, which is a very lightly modified version of the mouse example code (download).

That's it!  You can now drive your RC car with the mouse - it's good fun, eh?










ą
bg.jpg
(34k)
David Singleton,
Jan 2, 2012, 11:27 AM
ċ
car_mouse.txt
(3k)
David Singleton,
Feb 27, 2011, 3:34 PM
Comments