Switching a circuit from a 2 wire dc motor to 3 wire motor
The standard motor they use, and a standard Futaba servo, work in different ways.

A standard permanent magnet DC motor just turns continuously when you apply power to it, speed more or less proportional to voltage, or in the case of PWM, to duty cycle. It's just dumb physics-obeying hardware. The L293 is a power switch, a full H-bridge, which takes the low power logic levels from the Pi, and switches higher currents capable of turning the motor. It can drive +/-, or -/+ to the motor to make it turn in either direction, those wires to the motor are not power supplies or always +ve or -ve. U2 and 3 are opto isolators, for bomb-proof isolation between the Pi and the motor and its power supplies, but not absolutely necessary for function.

A standard servo contains a motor in it somewhere, but has a very different function. It is intended to go to a specific shaft angle within an angular range of about half a turn. It is used for controlling rudder and throttle position on radio controlled models. It contains a gearbox, position sensor, and some comparator and drive electronics. The desired angle of the shaft is encoded in the length of logic pulses sent into the white wire. A 1.5mS pulse is central, 1mS full left, 2mS full right. Typically, pulses are delivered every 20mS or so. In the absence of a pulse, it will hold the last position.

If you want to drive it directly from your Pi, connect red and black supply wires to +5 and gnd respectively. Connect the white wire directly to the one of the GPIOs, or to the output of either U2 or U3 if you want the opto-isolation for safety, or via the 1k resistor (some protection) that your first project uses.  Use your software skills to generate a stream of pulses on the GPIO, length 1mS to 2mS, 20mS apart.

I've not looked myself, but I would not be surprised at all if you googled 'pi servo open source', and found stuff ready to run that would put the right sort of pulses onto the GPIO.

The author of the first project was misleading slightly when he said 'the servo spins for a few seconds', because it doesn't, it just changes position (noisily, over a second or so) to push the button.

If you connected red and black from your servo to the output of the 293, I hope it didn't go bang when you applied reverse voltage to it. I would hope that as servos are designed to be supplied by batteries (which can be reversed) and used by youngsters, they would be designed to survive supply reversal.

In software terms, what you're trying to do is plug a USB lead into a 3.5mm audio jack! Both have their standards and levels of complexity, but you're lacking the experience at the moment to anticipate how different.

If you have got your existing L293 drive working, then this is the way to modify it to use your new servo, with full bomb-proof opto-isolation of any spikes from the motor to the Pi.



A number of things to note. The 5v servo supply is totally isolated from the Pi's. All the GND symbols are for this 5v supply. There is no ground connection between the Pi's supply and the servo's 5v supply. I've taken the servo 5v supply to the output of the optos. The +3.3v supply to the input of the optos is still the Pi +3.3v supply.

I've replaced the functionality of the L293 with that of the servo, note that it only needs one logic input, where the L293 used 3. I've coloured the 3 servo connections appropriately.