Motor Speed Control using Raspberry Pi PWM


L298 H-Bridge

To control the motors, I used the same PWM circuit described on this webpage, but the outputs are connected to an H-Bridge to control a stronger current. Motors need much more power than LEDs.

For the H-Bridge, I used an L298 Dual H-Bridge. I bought a pack of four on Amazon for $11.

L298 with I/O Labels

L298 to RPi interface

This is the wiring diagram for connecting the Raspberry Pi header to the H-Bridge. I made the connections with wire wrap.


12v to 5v Buck Converter

To convert the 12 volt power from the battery to the 5 volts needed by the Raspberry Pi and the encoder logic circuit, I used a 12v-to-5v buck converter. I bought a four pack of these buck converters on Amazon for $12. The 5 volt output is emitted on a USB port, which is very convenient for attaching to the Raspberry Pi. All I needed was a USB-A to USB-C cable.


Wiring the control board. My arms were sunburned when I made this video.

This is a video of the assembly and wiring of the robot control board. The Raspberry Pi is the green board in the lower right. The L298 H-Bridges are at the top of the board. The metal angle holds a small USB fan used to keep the Raspberry Pi cool during intensive computer vision processing.


640

This video shows testing of the motors using Wifi between the Raspberry Pi and a cell phone. The and speed and direction of the motors can be independently controlled. The next step is to mount the motors on the robot to drive the wheels. The independent control allows differential steering.


Burnt wires from an accidental short.

Just to show that it isn't all just fun and games, here are some burnt alligator clips. I accidently caused a short sending the full current of the 12 volt battery through the wires, causing a loud pop and plenty of smoke.