Driving motors

A supporting video is available for this article;

When you want some movement a motor is usually the first item you’ll turn to, yet they need some caution when working with micro-controllers or indeed any controlling electronics. If you’re looking at driving stepper-motors or servo motors then see these articles (steppers, servos) . This article and supporting video will look at driving analogue motors like the ones shown below;

9V Lego Technic motor and small toy motor

What you’ll need

  • Small motor
  • L9110 motor driver board
  • Arduino or other MCU (with PWM pins, virtually all have these)
  • Some wires

Don’t drive directly!
Motors cannot be connect directly to electronic components (in particular micro-controllers) due to a couple of reasons. Firstly they can draw a lot of current, especially when under load) which would be to much for MCU’s, small transistors etc. Secondly when power is removed and they come to a stop the inertia of the motor spinning round causes it to continue for a short while. This means the motor then acts a generator and a small voltage is sent back down it’s wires (called back EMF) , this can be a significant voltage spike and will fry un-protected equipment right away. For transistors a simple diode can protect your circuit, I won’t go into the details here as I won’t be covering this but a quick search on the internet will show you what to do if your driving motors simply using transistors.

As I want to be able to control both speed and direction of the motor the most convenient way is to pick up a motor driver board which will both handle the back EMF and the higher currents the motor will require. It will also allow us to easily reverse the motors direction. The board I’m going to use is the L9110, shown below,

L9110 H-Bridge Motor Driver Board

It’s known as a H_Bridge motor driver, named after the look of the circuit if it’s made up from discreet components. We won’t go into any more detail, suffice to say that using this little board will allow you to control up to 2 motors in any direction and at various speeds. Each motor would be connected to one of the two connections shown. The pins at the other end are for connection to power and the MCU/Arduino. Let’s take a closer look;

The connections to a standard L9110 H-Bridge board

The two middle connections are ground and Vcc. Ground goes to your common ground (i.e. the ground (Gnd) of the Arduino). The Vcc can goe to your Arduino 5V, however this would normally put a strain on you Arduino’s voltage regulator if you the motor has any sort of load. Running freely for testing would be fine. So the best thing to do is the connect the Vcc directly to your power source, or if using a 5V usb connection from a computer you should add in another battery pack. See this article here that connects a Lego Motor to an Arduino and uses a separate battery pack. Basically you connected the battery pack ground to the Arduino ground and the positive the the L9110 Vcc connection.

The two connections either side of these middle pins are for the 2 motors. The left side is for the left connected motor and the right for the right connected motor.

Connecting to the Arduino/MCU
So all you need to do is to run a pair of wires from the L9110’s control pins for a motor (as just mentioned) to two pins of your MCU. One connection must go to a PWM capable pin and the other can be any IO pin, it doesn’t matter. It also doesn’t matter which connection goes to the PWM or normal pin, the driver software will work just fine. On an Arduino Uno or Nano the PWM capable output pins are 3, 5, 6, 9, 10, and 11. In the library demos it uses pins 10 and 12, i.e. 10 as the PWM pin as 12 as a normal pin. In this way you could drive up to 6 motors at once.

The Library

Click above to download the library, installation is shown in the video. There are examples in the library also.

That’s it for this article, in the next one we’ll look at bringing all this together for a Lego merry-go-round project, with opening gates and automated ride system, till then, thanks for reading and watching videos 🙂