Want to keep learning?

This content is taken from the Raspberry Pi Foundation & National Centre for Computing Education's online course, Robotics With Raspberry Pi: Build and Program Your First Robot Buggy. Join the course to learn more.

Skip to 0 minutes and 3 seconds 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.

Skip to 0 minutes and 38 seconds 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.

Skip to 0 minutes and 59 seconds 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.

Skip to 1 minute and 23 seconds 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.

Skip to 1 minute and 39 seconds 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.

Skip to 2 minutes and 21 seconds 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?

Skip to 3 minutes and 6 seconds 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.

Skip to 3 minutes and 23 seconds 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.

Skip to 3 minutes and 58 seconds 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.

Skip to 4 minutes and 39 seconds In the next step, you’ll connect your Raspberry Pi and battery pack to the motor board.

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 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.

Discussion

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.

Share this video:

This video is from the free online course:

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

Raspberry Pi Foundation