Follow me




MovingRaspi - Part 03: Final assembly

MovingRaspi is a project I had some times ago, and I've just decided to start. Project's goal is to motorize a Raspberry Pi and control it with an iPhone (or iPad, or iPod Touch). This third part is about the final assembly.



H-Bridge is a basic assembly to control motors rotation direction. You can see below how it looks:


  • Q1 to Q4 transistors will be used as switches. If you apply current to the pin named “base” (the one linked to the resistor), current will flow from the pin named “collector” (the one with no particular sign) to the one named “emitter” (the one with the outgoing arrow). An other use for the transistor is their current amplifying feature. This feature, named “gain” (or hFE), is the multiplicator between the current applied to the base, and the one flowing between the collector and emitter. For instance, the BCU81 transistor used in the assembly provides a minimal gain of 140. This means that if we apply a 10 mA to the base, the minimal current which can flow between the collector and emitter is 10x140, equals 1400 mA ou 1.4 A. Motors may need a lot of current (between 70 mA to 800 mA depending of the load for the chosen model), you have to choose the right transistor depending of the current applied to the base and the gain.
  • D1 to D4 diods are here to protect the transistors. When a motor stops rotating, it sends a peak of current in the reverse direction than the one which was applied. This peak of current, which will flow from the emitter to the collector of the transistor can destroy it if too important. The diod is here to provide a return path bypassing the transistor.
  • C1 capacitor is here to filter electrical noise (voltages drops and peaks) generated by motor rotation. Even with a capacitor, voltage won't be perfectly regular, but it's better than nothing. You can see below filtered result, and see irregular ripples. You just have to imagine amplified ripples without the capacitor.

Filtered noise

To rotate the motor in one particular direction, you just have to activate two diagonally opposite transistors (i.a. Q1 and Q2, or Q3 and Q4). The reverse rotation direction, activate the two others. And to stop the motor, activate none of them. You can see below the two possibilities.

Motor turns left Motor turns right


MCP23008 is a port expander chip. To drive two motors, each with its own H-Bridge, you need a total of height GPIO pins. As Raspberry Pi only have height of them, unless you disable some special features, you will be quickly blocked in the future. And tada !! here is the MCP23008 chip. It use none of the GPIO pins (it is connected to the Raspberry Pi with I2C pins, +3.3V or +5V pins, and ground pin) and gives you eight new GPIO pins, for a total of 16 GPIO pins. And for more important needs, you can add more MCP23008 chips, or MCP23017 chips, which provide sixteen GPIO pins for these latter.

To power MCP23008, you can choose between +3.3V line or +5V line. I choose the second one mainly because +3.3V power line is limited to a total of 51 mA, shared with all GPIO pins of the Raspberry Pi. +5V power line is limited to 700 mA minus Raspberry Pi power usage. With an headless Raspberry Pi (which needs about 400 mA), you get 300 mA for USB and +5V power line.

Final assembly

Electronic schema and breadboard assembly are shown below:

Electronic schema
Breadboard assembly

About breadboard assembly, it's made for BCU81 transistor, which is a ECB one (in front view, pins from left to right are Emitter, Collector, Base). For EBC transistors, a breadboard assembly is available on GitHub project page.

See it in action


All sources and schemas for the project are available on GitHub.

Download on GitHub

comments powered by Disqus