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