Introduction to Motors

Intro 

Motors are everywhere - from toothbrushes to hard drives. Their ability to convert electrical energy to mechanical energy has revolutionized technology. Take a look at the motors used by your robot. How is it possible that supplying power through two wires can cause the tires to rotate? It all has to do with electromagnetism.

What is electromagnetism? 

If you've read the Infrared section from Robotics Kit 1, then you'll know that there is an electromagnetic spectrum made up of radiation of different wavelengths (some of which are visible to humans). Electromagnetism is a branch of physics revolving around the interaction between electrically charged particles. Visible light is electromagnetic radiation (radiation being the transmission of energy) and what allows motors to turn is called electromagnetic force.

So how is this applied inside the motor? Well if you take a piece of iron, wrap it a couple hundred times in wire, and apply a voltage between the two ends of the wire you'll get whats called an electromagnet which is essentially a homemade magnet! If you increase the voltage, the magnet gets stronger. If you reverse the direction of current by swapping the terminals, the north and south ends of the magnet will switch.

This is exactly what happens inside of a DC, or direct current, motor like you use in your robot. If you were to crack open one of your motors you'd see two magnets, a big winding of copper wire, two brushes (not like your hairbrush) and a commutator. The coil of wire is the electromagnet, and when you connect the two wires from your motors to an external power source (your battery holder) you're creating a magnetic field. This coil is wrapped around the axle of the motor. The magnets on the outside of the coil of wire create a magnetic field around the coil with one side being south and the other being north. When the motors are supplied with power, the electromagnet creates a magnetic field within this outer magnetic field. As the saying goes, "opposites attract and sames repel". This means that torque (a twisting force that causes rotation) is applied to the electromagnet by the outer magnets as the south ends of both magnets align and therefore repel causing the coil to spin, leading to the north ends of both magnets lining up and repelling one another, on and on. This causes the motor axle to turn, thus turning your tires.

What are the commutator and brushes for? The commutator is a rotary electrical switch that prevents the current from reversing direction because this would cause the motor to slow down and spin in the opposite direction. The brushes are devices that allow the motor to spin while still allowing current to be conducted between the stationary parts of motor (the commutator) and the moving ones (the axle). Without the brushes the electromagnet would lose contact with the external power source and no longer be an electromagnet.

Conceptual Question: From what you now know about motors can you figure out why reversing the terminals your motor wires are connected to also changes the direction the motor turns in?

Servos 

Another application of DC motors is inside of a servo. A servo is a rotary actuator that allows for precise control of its position. Basically, its a motor that you can control the rotation of instead of having it continuously spin like the motors on your robot. Servos are controlled with three wires: a black one for ground, a red one for power, and a third wire with which the servo's position is controlled with. Inside of the servo there is a DC motor, some gears, and a control circuit that monitors the position of the servo. The gears give the servo more torque than a regular motor because they take the force of the motor turning and spread it out over a longer distance. This increases the torque as seen in the formula Work = Force * Distance. This also slows down the motor, but allows the servo to hold its position even if you try and twist it's axle.

The exact position of the servo is set through PWM or Pulse Width Modulation. Each servo has a minimum pulse width and a maximum pulse width; these values (plus every value between them) correspond to a specific degree. The minimum pulse width corresponds to 0 degrees while the maximum pulse width corresponds to 180 degrees.

PWM Corresponding to Servo Degree ChangesPWM Corresponding to Servo Degree Changes

So how do we set the width of these pulses? Well the pulses correspond to duty cycle. Duty cycle is represented in percentages with the percentage representing how long something is "on" versus how long it is "off". If you have a constant 5 volts flowing through a wire for 10 seconds it has a 100% duty cycle. If you then decide to to only supply 5 volts for 2.5 seconds then you're only turning the power on for 1/4th of the time and it now has a 25% duty cycle. This is how a servo is told how far to turn. If the minimum pulse width for a servo is 1 ms and the microcontroller supplies power to the servo in pulses of 1 ms then the servo turns to its 0 degree position. If that same servo has a maximum pulse width of 2 ms and it is supplied that, then it rotates to its 180 degree position. Any pulse width in between causes the servo to turn to the degree corresponding to that width.

25%, 50%, and 75% Duty Cycles25%, 50%, and 75% Duty Cycles

H Bridges 

An important electrical component that allows for the control of motor is an H bridge. An H bridge is a component with an internal circuit consisting of four switches that allows for the control of the direction and flow of current to a load. On your motor driver you'll see an H bridge - it's the largest black component. The switches inside of a H bridge are in the shape of an H, hence the name.

H BridgeH Bridge

In the diagram below you'll see an H bridge and its configurations. The top end of the H bridge is connected to a power supply while the bottom is connected to ground. Diodes and transistors control whether an element is open or closed. When side 1 and 4 are on, then side 1 is connected to the power supply and side 4 is connected to ground. This completes the circuit and causes the motor to turn, for example, forward.

If, on the other hand, side 2 and 3 are on then side 2 is connected to power and side 3 is connected to ground. This reverses the current going through the motor and it turns backwards.

H BridgeH Bridge

The H bridge used in your motor driver actually consists of two H bridges! This allows two motors can be controlled at once, each one being controlled by a different H bridge. When you make your robot drive forward and then backwards you are utilizing the H bridge by changing the direction of current and changing the status of the switches within the H bridge.

The Different Switches in H BridgesThe Different Switches in H Bridges

Continuing Onward!

Now that you have an idea of how your motors work to move your robot, let's continue onto the main tutorial for this kit. If you'd like to learn more about H bridges or motors check out this link and this link.