Raspberry Pi Motor Controller


An AVR, typically an ATMega168P, is controlled from the Pi via the 3.3V UART, and provides the PWM signals to the Motor Driver.


  • Controlled via the UART on the Pi GPIO Header.
  • Up to 2A bi-directional current per channel at up to 46V. (Limited by L298N)
  • Only the Motor Supply Voltage is required in addition to Voltages from the Pi GPIO Header
  • Motor Driver Channels are switched off when speed value is set to ‘000’

Raspberry Pi Motor Controller


The Motor Controller initialises to ‘0’ speed on both channels.

A fixed-length 10 character array is then used to instruct the controller.


  • xxx – Speed from ‘000’ to ‘255’
  • X – Direction, ‘F’ or ‘B’

The controller will then repeat back the character array, reconstructed from the internal parsed values. Any corruption or undesired effects should therefore be visible.

This should be sent at 9600 baud. Case is important, no null terminator should be used.

Note: No error-handling is currently used, any other input will cause undefined behaviour and may require an AVR reset to recover the state.

Raspberry Pi Motor Controller Schematic


The code is written using the Arduino libraries, and so should be compiled with the Arduino IDE.

To program the AVR, an ICSP should be used. This will work in-circuit as long although no power should be applied to the rest of the circuit.


Foir more detail: Raspberry Pi Motor Controller

About The Author

Scroll to Top
Read previous post:
Arduino Bike Speedometer

Monitor your road speed using the Arduino. This project uses a magnetic switch (also called a reed switch) to measure...