2. Joystick Controller Schematics

(article continued from previous page)

The simplest solution for implementing joystick control for a robot would be to program the actions in software in a microcontroller. But, since many readers prefer off-the-shelf parts, this circuit is going to be made with diodes, resistors, transistors, and one FAN8200 motor driver chip. The downside is that the circuit is more complex.

Don’t panic. It’s not as bad as it looks.

Click to see a larger size schematic.

(Click to see a larger size schematic.)

Let’s break down the circuit by eliminating the common electrical parts first.

SW1: The power switch.

D10: A Schottky (low voltage drop) 1N5817 diode to prevent the FAN8200 chip from being damaged if the batteries are installed backwards. Other types of diodes may be acceptable substitutes, but a Schottky diode will consume the least amount of power.

A diode is a one-way valve that blocks electricity from going the “wrong” direction. Electricity is allowed to go in the direction of the arrow, but not the other way. Thus, battery power is blocked if the batteries are installed backwards, but is permitted if installed correctly.

C1 and C2: Capacitors store and release electricity locally to smooth out power glitches. This prevents errors in the FAN8200 motor driver chip due to spikes when switching the motors off and on.

IC1: Fairchild FAN8200 dual motor driver chip from Jameco Electronics or WrightHobbies.net. The chip can control two motors (hence the term “dual”). It can operate from 2.5V to 7V, which is why this circuit is specified for that range. The chip takes power, ground, and inputs and then outputs the power to the motors. You could build your own H-bridge, but that would make this circuit more complex.

Ground=GND=a symbol with three stacked lines that looks like a shaded pyramid (see pin 14 and the bottom of the capacitors). All ground lines should be connected to the negative (-) side of the battery. It makes the circuit look less busy to use a symbol than to draw wires back to a battery.

The advantages of the FAN 8200 chip are that it includes all of the parts to safely drive two small motors in coast, forward, and reverse mode. The chip has built-in diodes and pull-down resistors. The chip is cheap (about $1).

However, FAN 8200 motor driver chip is not very powerful or efficient. A home built h-bridge would likely deliver more power to the motors, but it would be more expensive, time consuming, and would require a lot more parts.

Great! We’ve already identified many of the parts and their purposes. Let’s concentrate on the remaining parts: the diodes, resistors, and transistors on the left side of the circuit.

Fire Button Schematic

Recall that the Atari joystick contains a bunch of buttons that can switch to ground. The fire button is nothing more than a simple switch.

I’ve redrawn the fire button portion of the schematic in a couple of ways to explain it better.

Two schematics for spinning a weapon motor when the joystick fire button is pressed.

Two schematics for spinning a weapon motor when the joystick fire button is pressed.

The easiest approach to running a motor when a switch is connected is shown on the left side of the above schematic. Power comes from the positive side of the battery, goes through the motor, through the fire button, to the negative side (ground) of the battery. If the fire button is released, the switch is disconnected, and the power can’t go through the motor to reach the other side of the battery, so the motor won’t turn.

If you’re trying to reduce parts, the left side of the above schematic is acceptable. However, it means that motor power has to go all the way through the joystick cable and back out to reach the battery. The joystick wires and switch may not be rated for the amount of current your weapon motor needs. Also, the fire button may arc internally when released, reducing the lifespan of the button.

Furthermore, if you decide to switch to a wireless setup (yes, they have wireless Atari joysticks!), it is unlikely that the left-side of the above schematic will work since the wireless joystick buttons will actually be emulated by a low-power chip.

A technically better way to drive a motor is with a transistor. That’s the circuit on the right-side of the above schematic.

Q1: A PNP bipolar transistor such as a 2N2907A. When the base is connected to ground (because the fire button switch is pressed), the transistor turns on and supplies power to the motor. When the base is disconnected (because the fire button is released), the transistor turns off and the motor stops turning. Motor power doesn’t go all the way through the joystick wires. It only goes through the transistor.

R1: 1000 ohm resistor. A resistor is required at the base of a bipolar transistor to prevent too much current from flowing through the base. A higher value resistor (like 10000 ohms) might not allow the transistor to turn on enough to power a motor. A lower value resistor (like 100 ohms) would waste power through the base without providing any benefit.

D1: A diode provides a path for the remaining current in the motor to recirculate and get safely consumed when the transistor turns off the motor. Without the diode, an induced voltage spike might come out of the motor and force its way through the transistor -- damaging the transistor.

Up-Left Joystick Button Schematic

The circuit for controlling the joystick directional buttons is very similar to the fire button circuit. The two differences are: multiple buttons need to be combined, and the buttons control directional inputs to the motor driver chip rather than drive a motor themselves.

On the previous page, we came up with three conditional statements that could control the robot through joystick button presses. The first conditional statement was “1. If the up or left button is pressed, then the right motor should go forward. Otherwise, the right motor should reverse.” The following circuit performs that statement.

Up and left joystick buttons are combined to turn on a transistor which outputs to a motor driver pin to control the direction of the right motor.

Up and left joystick buttons are combined to turn on a transistor which outputs to a motor driver pin to control the direction of the right motor.

If the up button is pressed, then the base of transistor is grounded and it turns on power to one of the chip inputs that controls the direction of the right motor. Or, if the left button is pressed, the same thing happens. Or, if both the up and left buttons are pressed, the same thing happens.

If both the up and left buttons are released (disconnected), then the base of the transistor is also disconnected, which disconnects power to the directional input on the right motor driver. The motor driver chip datasheet says that if the pin is disconnected, that’s the same as receiving a ground signal.

So, as you can see, this circuit successfully implements the statement that the up and left buttons control the direction of the right motor.

Q2: A PNP transistor. But, because this transistor only controls a chip input (rather than a weapon motor), you can use a less powerful and less expensive transistor, such as the 2N3906. Of course, if you’re buying in bulk, you can use the same transistor as Q1 (2N2907A).

R2 A 10000 ohm resistor. This uses less power than a 1000 ohm resistor, which is fine, since the transistor only needs to provide a little power to the chip input.

D2 and D3 Inexpensive small-signal low-power diodes such 1N914. These are one-way routes that allow the joystick buttons to have combined control over Q2, without having their signals combined in other cases. We'll examine how that works in a little bit.

Looking back to the first schematic on this page, notice that the left-down-up-right portion of the circuit (connected to diodes D3-D7) is the same pattern as the up-left circuit (D1-D2). The only differences are that it combines four buttons and controls the “Enable” pins for both motors. So, you can see, if any of the directional buttons are pressed, the motors are enabled (supplied power).

The right-down portion of the circuit (D8-D9) is the same as the up-left portion of the circuit (D1-D2) except that it controls the direction of the left motor.

The first group of buttons and diodes performs the first conditional statement, the second group performs the second conditional statement, and the third group performs the third conditional statement. We have a complete circuit to implement all desired states in the simplified table from the first page of this article.

But what’s with the diodes?

Using Diodes to Create OR Circuits

Well, I cheated a bit when I drew the schematic at the top of this page. There aren’t three Up buttons, two Left buttons, and two Right buttons on an Atari joystick.

Let me show you the first two groups again, but this time I'll eliminate the second left button because it doesn’t really exist. (I’ve hidden the rest of the circuitry such as the resistors and transistors because they aren’t important.)

Diodes prevent signals from being able to weave through one part of the circuit to another.

Diodes prevent signals from being able to weave through one part of the circuit to another.

Notice there is only one left button. The two left buttons originally connected to D3 and D4 have been combined.

If the player pushes the joystick down, only the down button switch (see D5) is connected and only the enable pin on the motor driver chip should turn on.

If diode D4 didn’t exist, then right-motor control current could go down through D3, through the wire where D4 was, down through D5, and through the down button. That would cause the right motor direction control to turn on and the right motor would drive forward. But, the player wants it to drive in reverse.

Instead, by installing diode D4, the electricity from the first group is blocked from going up into the second group. One-way only please! As such, the down switch will only affect the second group.

Put another way, the diodes create one-way paths so that groups can share buttons without co-mingling their signals.

Extra Credit: There are two improvements that can be made to this circuit. First, because the down button is only used once, diode D5 is unnecessary. The diode was only included to mimic the rest of the circuit. Second, 100 kilohm pull-up resistors could be placed on each of the joystick switches to prevent errant electrical currents (like from fingers) from randomly tripping the transistors.

Now let’s implement the joystick control circuit on a solderless breadboard...