# Building Robots using Arduino – DC Motors

This is part 2 of my “Building Robots using Arduino” tutorial series, explaining how you can create robots using Arduino.

In this article, I will introduce DC motors and how to use them.

## Types of Motors

If you look at the Wikipedia page of DC motors, you will realize that there are different types of DC motors. In this tutorial, I am going to be concentrate only on DC Brushed motors.

## Parameters for choosing DC Motors

There are three different parameters that you have to keep in mind while choosing a DC motor for your project. They are

• Voltage
• RPM
• Torque

### Voltage

This parameter specifies the voltage level at which the motor will run. Most hobby motors work in the voltage range of 5-12 V. You should make sure that you don’t run the motor outside its range.

### RPM

The next parameter to keep in mind is RPM (Rotations Per Minute). This basically specifies the number of rotations that will be made by the motor when the specified voltage is applied across its terminals. The higher the RPM, the faster the motor will run. Typical rpm’s for a hobby motor ranges from 200-2000 rpm.

### Torque

The torque of a DC motor, specifies the force at which the motor will run. If the torque of a motor is high, then it can pull more load. You should choose the torque of the motor, based on the load/weight it has to pull.

## Connecting a DC Motor

The DC motor will have two terminals.

If you connect the positive terminal of a battery/voltage source at one end and the Gnd at the other end, then the motor will rotate in one direction. If you reverse the connection, then the motor will run in the opposite direction.

## Testing a DC Motor

We can do the following small experiment to better understand the connections of a DC motor.

Take a DC motor and a battery which has the voltage equal to the voltage rating of the DC motor. If no wires are soldered in the DC Motor, then take two pieces of wires and solder them at the two terminals.

Connect the positive terminal of the battery, to one terminal and the Gnd terminal of the battery to the other. You should see the motor rotating. Make a note of the direction of rotation.

Next reverse the terminals. The motor should rotate again. Make a note of the direction of rotation. If you have connected it properly, then you will notice that the direction of rotation has changed.

## Connecting the motor to Arduino

Now let’s try to do the same thing using Arduino. To do that we have to simulate the positive and Gnd connections of a battery in Arduino.

Note: Don’t use a high voltage motor for this. This might spoil the Arduino board.

If you set a pin to output mode, and then put it in `high` state, then it is equal to the positive terminal of a battery, since it will be at +5V. Similarly, if you set a pin to output mode, and then put it inΒ `low` state, then it is equal to the Gnd terminal of a battery.

Let’s write a small Arduino sketch to test the motor.

In the above program, I set two pins (12 and 13) to be in output mode. After that, for the first 5 seconds I set pin 13 to be high and pin 12 to be low. So pin 13 will act as +ve terminal and pin 12 will act as ground. The motor will rotate in one direction.Β For the next 5 seconds, I set pin 13 to be low and pin 12 to be high. When I do that, the terminals are interchanged and the motor will rotate in the other direction.

You can see this in action in the following YouTube video.

This sketch is very similar to the led blink sketch. Remember what I said last week – if you can blink a led, you can build a robot as well π

## What’s next

As you might have already figured out, this method is not very efficient. Also you can’t supply full voltage to the motors. We will correct all that next week.

In the next post of the series, we will use an IC called L293D which will make our life a lot easier π We will also see how we can change the speed of the motor, in addition to the direction.

See you all next week then. Till then happy roboting π

## 7 thoughts on “Building Robots using Arduino – DC Motors”

1. Abhijeet Kasurde

Very nice tutorial for novice people. Waiting for next tutorial π
What is specification of motor in video ?
Can you please also cover some tutorial using L298 IC with L293D ?

1. Sudar Post author

Very nice tutorial for novice people. Waiting for next tutorial

Nice to know that you like the tutorial π

What is specification of motor in video ?

The one which is there in the video is a 12V 1000 RPM motor.

Can you please also cover some tutorial using L298 IC with L293D ?

The main difference between those to IC’s is that L298 can handle more current. Are you looking for anything specific?

1. Abhijeet Kasurde

Somewhere in blog, I read that L298 is better than L293D, I am planning for building basic obstacle avoiding robot which will have pretty good configuration so that parts of that can be reused in my further projects. It will be also great if you mention estimated cost of parts you use in your tutorial. Thanks for quick replying. π

1. Sudar Post author

I read that L298 is better than L293D

If possible find a link to that article. Even I want to know what is the difference. As far I know the only difference is higher current handling π

It will be also great if you mention estimated cost of parts you use in your tutorial.

Sure, will do that as well.

2. Tony Hall

I tried to get a motor going that draws 170-180mA.
It will not work.
never mind V, RPM or torque, you’ll POP the Arsduino !! it is only rated at 45mA !!