Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

DC Motor Lab

In this lab, you'll learn how to control a DC motor's direction using an H-bridge. To reverse a DC motor,
you need to be able to reverse the direction of the current in the motor. The easiest way to do this is
using an H-bridge circuit.

Table of Contents
Table of Contents
1

Objective
1.1

The Experiment

1.2

Reference Documents

How it Works
2.1

DC Motors

2.2

How an H-bridge works

2.3

Pulse Width Modulation

Prepare the Rover


3.1

Program the Microcontroller


4.1

Connecting a Power Supply to Your Rover


DC control of Forward and Reverse

Objective

1.1 The Experiment


Program your rover to travel in approximately a straight line. I would recommend
starting with the scripts available from AdaFruit. The duty cycle should be programmed
to be between the maximum value (255) and the stall speed (Lab 1). This will simulate
the average speed of your rover during the mission. Tweak the motor duty cycles as
required so the rover travels in an approximate straight line. Have your rover travel half
the distance of the maximum plaque distance. This will simulate the rover traveling to
a plaque. Once it reaches one end of the line have the stepper motor rotate the scan
platform 180 degrees clockwise and then 360 degrees counterclockwise, and finally 180
degrees clockwise back to the home position. Have the rover then rotate 180 degrees and
return to the starting point. Spin the scan platform as previously defined and then rotate
the rover 180 degrees. The rover should now roughly be at its starting position. Count this
as one round trip. Have your rover repeat this motion keeping track of (1) elapsed time,
(2) the number of round trips, and (3) the number of times you needed to manually adjust
its course. Record this in a Google document or your lab notebook. Note when your battery
can no longer power the rover.
Reminder:

Make sure your battery is fully charged.

1.2 Reference Documents


Here is the motor shield schematic http://www.ladyada.net/make/mshield/download.html
and here is the pdf documenting the shield (how to build, labs, etc.)
http://www.robotshop.ca/content/PDF/adafruit-motor-shield-arduino-user-guide.pdf
If you want to turn a motor on and off, and don't need to reverse it, for example if you're
controlling a fan, try the tutorial on controlling high current loads with transistors.
5. Here is the datasheet on the most common H-Bridge Texas Instruments SN754410.
6. Brushed DC electric motor
7. DC Motor Control Using an H-Bridge (original source for this lab)
8. Using an Arduino to control the speed and direction of a DC Motor
9. Motor Shield
10. hardware tutorial class 11 - sensors, solenoids, DC motors
11. Atmel application notes doc8138.pdf (Brushless DC Motor Control)
12. Chuck's Robotics - H Bridge Theory
13. Wikipedia- H Bridge Theory
14. Jaycar Electronics - Optoisolators
15. Vishay Semiconductors - Optoisolators
1.
2.
3.
4.

How it Works

2.1 DC Motors
by solarbotics
Let's start by looking at the overall parts of a simple DC electric motor.
Every DC motor has six basic parts -- axle, rotor or armature, stator, commutator, field magnet(s), and
brushes.
Armature or rotor is an electromagnet made by coiling thin wire around two or more poles of a
metal core. The armature has an axle, and the commutator is attached to the axle.
Commutator commutator is a common feature of direct current rotating machines. By reversing
the current direction in the moving coil of a motor's armature, a steady rotating force, torque, is
produced.
Brushes transfers power from the battery to the commutator as the motor spins.
Axle holds the armature and the commutator.
Field magnet is formed by the can itself plus two curved permanent magnets.
Stator is the stationary part of a rotor system

Link source: DC Motor


In any electric motor, operation is based on simple electromagnetism. A current-carrying conductor
generates a magnetic field; when this is then placed in an external magnetic field, it will experience a
force proportional to the current in the conductor, and to the strength of the external magnetic field.
As you are well aware of from playing with magnets as opposite (North and South) polarities attract,
while like polarities (North and North, South and South) repel. The internal configuration of a DC motor
is designed to harness the magnetic interaction between a current-carrying conductor and an external
magnetic field to generate rotational motion.
The "flipping the electric field" part of an electric motor is accomplished by two parts: the commutator
and the brushes.
A motor uses magnets to create motion, and the commutator and brushes work together to let current
flow to the electromagnet, and also to flip the direction that the electrons are flowing at just the right
moment.
The contacts of the commutator are attached to the axle of the electromagnet, so they spin with the
magnet. The brushes are just two pieces of springy metal or carbon that make contact with the contacts
of the commutator.
In this figure, the armature winding has been left out so that it is easier to see the commutator in action.
The key thing to notice is that as the armature passes through the horizontal position, the poles of the
electromagnet flip. Because of the flip, the north pole of the electromagnet is always above the axle so it
can repel the field magnet's north pole and attract the field magnet's south pole.
DC motors will always have more than two poles (three is a very common number). In particular, this
avoids "dead spots" in the commutator. You can imagine how with our example two-pole motor, if the
rotor is exactly at the middle of its rotation (perfectly aligned with the field magnets), it will get "stuck"
there. Meanwhile, with a two-pole motor, there is a moment where the commutator shorts out the
power supply (i.e., both brushes touch both commutator contacts simultaneously). This would be bad
for the power supply, waste energy, and damage motor components as well. Yet another disadvantage
of such a simple motor is that it would exhibit a high amount of torque (the amount of torque it could
produce is cyclic with the position of the rotor).

3-pole ananimation link


You'll notice a few things from this picture above: one pole is fully energized at a time (but two others
are "partially" energized). As each brush transitions from one commutator contact to the next, one
coil's field will rapidly collapse, as the next coil's field will rapidly charge up (this occurs within a few
microsecond).
The rotor will have three poles rather than the two poles because there are two good reasons for a
motor to have three poles:
It causes the motor to have better dynamics. In a two-pole motor, if the electromagnet is at the balance
point, perfectly horizontal between the two poles of the field magnet when the motor starts, you can
imagine the armature getting "stuck" there. That never happens in a three-pole motor.
Each time the commutator hits the point where it flips the field in a two-pole motor, the commutator
shorts out the battery (directly connects the positive and negative terminals) for a moment. This
shorting wastes energy and drains the battery needlessly. A three-pole motor solves this problem as
well.
It is possible to have any number of poles, depending on the size of the motor and the specific
application it is being used it

2.2 How an H-bridge works


An H-bridge is an electronic circuit that is very commonly used to control the direction of a DC motor.
The H-bridge is named so because the way the circuit is typically drawn looks like an "H". If one pair
of switches are closed then the motor will turn in one direction. If the second pair are closed then
the motor will turn in the other direction. Darlington pair transistors act like switches and close the
connection when a small current is supplied to the transistor's base.

The SN754410 H-Bridge you are using has 4 half-H bridges (i.e., two bridges), and can therefore control
2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The motor that you
selected operates well within this range (5-15 volts) so will work well with this H-bridge. The SN754410
is a very basic H-bridge. This one in particular has two bridges, one on the left side of the chip and one
on the right.

Above is a diagram of the H-bridge IC that you are using and which pins do what in our example.
Included with the diagram is a truth table indicating how the motor will function according to the state
of the logic pins (which are set by our Arduino).
For this lab, the enable pin connects to a digital pin on your Arduino so you can send it either HIGH or
LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on
your Arduino so you can send it HIGH and LOW to have the motor turn in one direction, or LOW and
HIGH to have it turn in the other direction. The motor supply voltage (VMOTOR) connects to the voltage
source for the motor, which is, in our case, an external power supply.
These circuits are often used in robotics and other applications to allow DC motors to run in the
clockwise and counterclockwise directions. H-bridges are available as integrated circuits, or can be built
from discrete components. The Texas Instruments SN754410 is a very popular H bridge IC used in many
hobby and robotic applications.

Basically, there are four switching elements in the H-Bridge as shown in the figure below.
As you can see in the figure above there are four switching elements named as "High side left", "High
side right", "Low side right", "Low side left". When these switches are turned on in pairs motor changes
its direction accordingly. Like, if we switch on High side left and Low side right then motor rotate in
forward direction, as current flows from Power supply through the motor coil goes to ground via switch
low side right. This is shown in the figure below.
Similarly, when you switch on low side left and high side right, the current flows in opposite direction
and motor rotates in backward direction. This is the basic working of H-Bridge. We can also make a small
truth table according to the switching of H-Bridge explained above.
Truth Table
High Left
On

High Right
Off

Low Left
Off

Low Right
On

Off

On

On

Off

On

On

Off

Off

Off

Off

On

On

Description
Motor runs
clockwise
Motor runs anticlockwise
Motor stops or
decelerates
Motor stops or
decelerates

As already said, H-bridge can be made with the help of trasistors as well as MOSFETs, the only thing
is the power handling capacity of the circuit. If motors are needed to run with high current then lot of
dissipation is there. So head sinks are needed to cool the circuit.
Now you might be thinking why i did not discuss the cases like High side left on and Low side left on or
high side right on and low side right on. Clearly seen in the diagram, you don't want to burn your power
supply by shorting them. So that is why those combinations are not discussed in the truth table.
Truth table
A
0
0

B
0
1

Motor
Stop
Run one
direction
Run on the
other direction
Stop

source: DC Motor Interfacing with Microcontroller


For more information regarding H-bridges, click here
Other Items

This example uses an H-bridge integrated circuit, the Texas Instruments SN754410. The H-bridge is
available for purchase online at many distributors such as: Digikey, SparkFun, Mouser, Futurlec, and
Jameco.

2.3 Pulse Width Modulation

Control the motor speed by driving the motor with short pulse
Making a square wave with on-to-off ratio, the average on time varies from 0 to 100 percent
These pulses vary in duration to change the speed of the motor, the longer the pulses, the
faster the motor turns, and vice versa

Pulse-width Modulation is achieved with the help of a square wave whose duty cycle is changed to get a
varying voltage output as a result of average value of waveform.
A mathematical explanation of this is given below:

Consider a square wave shown in the figure above.


Ton is the time for which the output is high and Toff is time for which output is low. Let Ttotal be time
period of the wave such that,
Duty cycle of a square wave is defined as

The output voltage varies with duty cycle as...

So you can see from the final equation the output voltage can be directly varied by varying the Ton value.
If Ton is 0, Vout is also 0.

If Ton is Ttotal , then Vout is Vin or say maximum.


source: Pulse Width Modulation

Prepare the Rover

3.1 Connecting a Power Supply to Your Rover


For this lab, you will need two power supplies, one to power your Arduino and another to power the
DC motors. You may use the USB connection to power the Arduino and ICs that are being sourced by
the Arduino board. You may also choose to use a separate power supply that plugs into the power port
of the Arduino board. If you choose to power your Arduino externally, and it has a power jumper to
control where the power is sourced. Change the power jumper from USB to EXT so that your Arduino
runs off the external supply. If your Arduino does not have a power jumper then don't be alarmed, your
Arduino's power supply is automatically selected. You may still leave your USB cable plugged in for quick
and easy reprogramming.
Note 1: the capacitor connecting the motor supply to ground. It smooths out the voltage spikes and
dips that occur as the motor turns on and off.
Note 2: Do not connect the Adafruit Motor Shield Power Jumper

Program the Microcontroller

4.1 DC control of Forward and Reverse


//Program the microcontroller to run the motor through the H-bridge
#define
#define
#define
#define
#define

switchPin
motor1Pin
motor2Pin
enablePin
ledPin 13

2 // switch input
3 // H-bridge leg 1 (pin 2, 1A)
4 // H-bridge leg 2 (pin 7, 2A)
9 // H-bridge enable pin
// LED

void setup() {
// set the switch as an input:
pinMode(switchPin, INPUT);
// set all the other pins you're using as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(ledPin, OUTPUT);
// set enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);

// blink the LED 3 times. This should happen only once.


// if you see the LED blink three times, it means that the module
// reset itself,. probably because the motor caused a brownout
// or a short.
blink(ledPin, 3, 100);
}
void loop() {
// if the switch is high, motor will turn on one direction:
if (digitalRead(switchPin) == HIGH) {
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
}
// if the switch is low, motor will turn in the other direction:
else {
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
}
}
/*
blinks an LED
*/
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2)

You might also like