Skip main navigation

Connecting a motor to the motor controller

In this step you will start by connecting the motors to the motor controller board, before connecting the battery holder to the motor controller.
The first step to making your buggy is to connect the motors to the motor controller board. Since most DC motors don’t come with wires attached to them, you need to attach your own. To start with, we’re going to take one of the motors and attach two wires to the motor. Firstly, we’re going to strip the two jumper leads, using the scissors to cut the ends off and the wire strippers to remove the ends of the insulation. OK. Just near the end? Yep, near the end.
Both ends or just one? You can do both ends now. We’ll need both ends exposed. And how much do I need to take off about an inch. OK. So I’ll put it– A few centimetres. So I just put it through here and then press. Is that correct? Yep.
What do I do with this? If you twist the ends of the exposed wires together, then it should stay nice and tight. There it is. So now you’ve prepared the two jumper leads, you’re going to thread the two leads through the connectors in the motor. First thing we are going to need to do is take off the plastic clip on the motors.
So putting the cables through these small holes here in the connectors. Yep. The contacts. So you’re threading the wire through the metal contacts.
And then if you bend the wire towards you, that makes it easier to solder. OK. Now that you’ve threaded two of the wires through one of the motors, you’re going to solder the wires to the motors to make sure they’re securely attached. OK. So you want to apply the tip of the soldering iron to the metal contacts on the motor. If you heat up the contact and the wire before applying the solder, then it makes it easier for the solder to attach. How long do I need to keep– heat it up? If you heat the contact up for a couple of seconds, and then you can apply the solder to the tip of the soldering iron.
Once it starts to smoke and melt, then you can remove the soldering iron. If you don’t think you’ve added enough solder, just add a little bit more. OK. I think that feels secure. Excellent. If you’d like some soldering tips, be sure to check out the link in the article. Now that you’ve soldered your wires to your motor, we’re going to trim the ends of the wires– OK. –reattach the plastic clip– Right. –and tape up the wires securely. Great. The first thing you’re going to do is trim the ends of the wires. With scissors just like that. Yep. And you just want to– OK. You just want to trim the end of the exposed wire. Perfect. Is that short enough?
Yep, that’s great. And then the second one. Trying not to cut the wire. Excellent. The next thing you’re going to do is reattach the plastic clip to the motor.
And then you’re going to take a piece of tape and wrap it around the end of the motors. This way it keeps the wires nice and secure. OK. So how does that look? That looks great. So now we’re going to take both motors and we’re going to attach them to the motor controller board. OK. Fantastic. We need to attach each of these wires into one of the out terminals on the motor controller. OK. Is it helpful for me to twist them again? Yeah. If you twist the wires first, it will make it much easier trying to attach it into the terminals. The first thing is to loosen the screws on each of the out terminals.
So we have two out terminals on this side and two on that side. Just a little bit. Just a little bit. OK. On both of them. Yep. All right. OK. Now you need to place one of the wires into each of the out terminals, and then you can use the screwdriver to tighten the screws. And then you can pull on the wire just to make sure that it’s security attached to the terminal. Now we’re going to do exactly the same with the one I prepared earlier. OK. Did you have any issues connecting the motors to the motor controller? Do you need help with anything that isn’t working properly? If so let us know in the comments.
In the next step, you’ll connect your Raspberry Pi and battery pack to the motor board.

In this step you will start by connecting the motors to the motor controller board, before connecting the battery holder to the motor controller.

The instructions are for a L298N dual H-bridge DC stepper motor driver controller board, and they will be similar for most motor controller boards. Check the documentation for your board if you are using a different one.

What you will need

For this step you will need the following items:

  • Motor controller board
  • Two 3V-6V DC motors
  • Four jumper leads (male-to-male or female-to-male) or wire
  • Screwdriver

You may also need:

  • Soldering iron and solder
  • Wire strippers
  • Scissors
  • Tape

Using a soldering iron can be a bit daunting at first, but whether you are new to soldering or a veteran, this Getting started with soldering resource will give you some quick tips and tricks.

The robot buggy parts for this step - 2 x DC motors, Motor controller board, 4 x Jumper leads (male-to-male and female-to-male), Screwdriver, Soldering iron and solder, Wire strippers, Scissors, Tape

The DC motors

Most DC motors do not come with wires attached to them, which means you will need to attach your own, using solder.

Preparing the wires

You will need two wires for each DC motor, to connect it to the motor controller board. Alternatively, you can use wire strippers to strip both ends of the jumper leads, to expose the bare wire for attaching to each of the motors. A demonstration of how to strip a wire with wire strippers can be seen in this video.

4 stripped male-to-male jumper leads

Remove the soft plastic clip from the motors so that the wires can be attached. You can use a flathead screwdriver to help remove the clip.

Thread the bare wire through the contact on the motor. Top tip: It may be easier to solder the wire to the contact on the motor if you bend the wire once it has passed through the contact.

The wire bent through the contact on the motor

Soldering the wires

Turn on the soldering iron and wait for it to heat up. Clean the soldering iron tip before using it; you can use a damp sponge or damp cloth to remove any residue while the iron is hot.

Heat the contact on the motor with the soldering iron for a second or two. Keeping the soldering iron on the contact, touch the end of the solder to the soldering iron tip until the solder melts. Stop applying solder once the contact and wire are connected by the solder.

Video of a wire being soldered to one of the contacts on the DC motor

Wait for a minute or two for the solder to cool and then gently try to move the wire, to test whether it is securely attached to the contact. If the wire moves, you can either reheat the applied solder with the soldering iron and realign the wire, or apply more solder to the connection.

Try not to touch with the soldering iron the plastic coating of the wires or any plastic between the two contacts, or the plastic will melt and start to smoke. More tips and guidance can be found in this soldering tutorial.

Once the wires have been soldered to the motors securely, trim the end of the wires with scissors. If the wires accidentally touch the metal casing while power is running, this can short the circuit and stop the motor from receiving consistent power.

Reattach the plastic clips to the motors. It’s also a good idea to wrap the end of the motors where you attached the wire in tape, to protect the connection and help keep the solder in good condition.

Connect the motors to the motor controller board

A motor controller board will usually have screw terminals for connecting a motor to it. A DC motor needs two screw terminals for it to work, and a servo motor needs four terminals. The four OUT terminals on the board I am using are circled in green below.

A L298N motor controller board with four OUT screw terminals for connecting to an electric motor. The four OUT terminals are circled.

A DC motor needs to use two wires so that it can turn forwards and backwards. Sending a high signal to one wire and a low signal to the other wire will turn the motor in one direction, and swapping the signals around will turn the motor in the other direction.

Using a screwdriver, loosen the screws in the terminal blocks labelled OUT1, OUT2, OUT3, and OUT4. Have a look at the documentation for your board if your labels are different.

Strip the ends of the wires; you can snip off the ends if you need to. Insert the stripped ends of one motor into the OUT1 and OUT2 terminals and the stripped ends of the second motor into the OUT3 and OUT4 terminals. Tighten the screws so the wires are secured firmly in the terminal blocks.

A close up image of one or two motors connected to the OUT terminal blocks of a motor controller with the screws of the terminal blocks tightened.


Did you have any issues connecting the motors to the motor controller?

Do you need help with anything that isn’t working properly?

If so, let us know in the comments below.

This article is from the free online

Robotics With Raspberry Pi: Build and Program Your First Robot Buggy

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education