Use Arduino to Control a Motor Part 1 – Motor Basics

Control a motor with Arduino

Control a motor with Arduino

As we have just finished our series on how to make a Stevenson screen using Arduino, you should have a good understanding of how things are working with Arduino. Now things will really get going! I’d like to start working with a motor!

I assume that many products will immediately come to mind when you hear the word “motor,” but most electronic products that move or rotate use a motor.

A motor is simply something that turns, but by using gears, we can realize complicated actions. Over the next few lessons, we’ll learn about the use of motors.

Today Electronic’s Recipe

Expected time to complete: 60 minutes

Parts needed:

Arduino unit (Arduino Uno R3)
DC motor (FA-130RA-227
Transistor (PNP-type BC327-025G
Diode (1N4148
AA battery box
AA battery

DC motor

DC Motor

I believe that this is what people imagine when they hear the word “motor.” Many people have probably come across them while playing with radio-controlled cars.

This motor is called a DC motor, with the “DC” standing for “direct current.” Because it is DC, it can be made to move by simply attaching it to a battery.

The internal mechanism of the motor contains enameled wire coiled many times around a magnet, and by passing an electric current through the coil the motor rotates, being repelled by the magnetism. When using a battery, by reversing the positive and negative sides, the magnetism can be reversed and make the motor turn in the opposite direction.

DC Motors

There are many different sizes of motors.

Servo motor

Servo motors are commonly used in electronics. A servo motor contains an integrated control circuit to allow for the control of the revolution angle of the motor. A variety of angles are set upon, and there is a notation for an angle of operation of 120 degrees.

Servo Motor

Servo motor

Motor basics

First, let’s use a DC motor. Before using a motor with Arduino, let’s understand the basics of motor operation using only an AA battery.

We attach an AA battery to the plus/minus (red/blue line). As expected, the motor turns, right? If it doesn’t, then either the motor is broken or the battery is drained. In that case, we should first try replacing the battery. If it still doesn’t work, then it’s possible that the motor is broken.

Servo Motor

Make the motor move with an AA battery

Servo Motor and Battery

Let’s look at the voltage and current required to rotate a motor.

Looking at the data sheet of our DC motor, it states that the proper voltage is 1.5V and it draws 0.2A with no load. AA batteries have a voltage of 1.5V (dry cell/lithium) or 1.2V (Nickel-metal hydride batteries / Ni-Cd batteries). So, from the data sheet, we see that we can operate the motor with one battery.

Motor rotation speed

What can be done to make the motor rotate faster?

We can make the motor rotate faster by increasing the voltage going to the motor. We can accomplish this by placing the batteries in a series.

Servo motor and batteries

Motor rotation time

How long will the motor rotate?

The amount of time that a motor will rotate is related to the capacity of the battery. The capacity can be calculated by multiplying the current and the time. For example, if the capacity of your AA battery is 400mAh, then 400mA of current will flow for one hour. Taking the example above, a current of 1.5V, with 0.2A = 200mA, 400 divided by 200 = 2 hours, so we can operate the motor for about 2 hours.

Rotate the motor using Arduino

Now, that we understand the basics of motors, how can we use one with Arduino? Let’s compare the operation of motors and Arduino.

Comparing the voltages, we know that the Arduino’s digital pins operate between 0 and 5V, so we understand that we will be able to provide the 1.5V necessary to rotate a motor.

Next, let’s consider the current. When a motor operates at 1.5V it requires 200mA of current.
Looking at the Arduino specs, we see that the digital pins offer a current of 40mA, so we don’t have the required 200mA to make the motor rotate.

In other words, if we connect the motor directly to the Arduino digital pins, the motor will try to draw 200mA from Arduino, causing Arduino to break under the load. Therefore, unlike LEDs, we cannot simply connect a motor directly to Arduino to operate it.

Arduino output current output voltage

So, what can we do to operate a motor with Arduino? This time, let’s try using a transistor.

Transistors and diodes

Before talking about how transistors work, let’s explain the use of diodes.

Diodes prevent a normal current from going in the opposite direction and play a role in rectification. What is the mechanism that allows them to operate in this way?



Diode Mechanism


A Diode is a component made from P-type semiconductors and N-type semiconductors.
A simple explanation is that P-type semiconductors lack electrons and N-type semiconductors have excess electrons.


By connecting the negative side of a battery to the A (anode) of a diode and the positive side of a battery to the K (cathode), we can draw a charge from the semiconductor to create a depletion layer in the diode, preventing the flow of current.


On the contrary, by connecting the A(anode) to the positive side and the K(cathode) to the negative side, the charges in the diode will try to cancel each other out continually and a constant flow of current can be maintained in the diode.

In this way, the diode prevents current from flowing in the opposite direction.

Transistor mechanism


Next, I’ll explain transistor.

A transistor allows one to control the flow of electricity. Basically, it plays the role of a switch in a circuit, and it is used to amplify current.

The diodes are made up of N-type and P-type semiconductors, but transistors are composed of three parts, such as “NPN-type” and “PNP-type.” The special feature is that the semiconductor sandwiched in the middle is much narrower than the outer semiconductors, and they put that characteristic to use.

Transistor emitter collector base


Taking an NPN-type as an example, there are N-type semiconductors on both ends, a P-type semiconductor in the middle, and it is connected directly to three lines: E(emitter), K(collector), and B(base).


To understand how transistors operate,  let’s first connect E (the emitter) and C (the collector) to the battery. The load at this point is shown on the chart, and as explained in the section on diodes, a depletion layer is created between the P-type semiconductor in the base and the N-type semiconductor in the collector, preventing the flow of electricity.


Next, let’s connect the orange battery, which is significantly weaker than the gray battery, to the base. By doing this, current flows between the base and the emitter, and a positive load is maintained in the P-style semiconductor. The current flows in the void that was created in the previous step between the base and the collector. In this state, electrical current flows from the emitter to the collector.

As explained in the beginning, the semiconductor used in the base of the transistor is very narrow and only a weak current can pass, so the electricity flows from the fully loaded emitter through to the collector. This is why a weak current (the orange battery) can control a strong current (the gray battery).

Create a relay circuit using transistors

Now, let’s use a use a transistor as a switch. In electronic construction, this switch is called a relay circuit. According to the transistor specs, if the motor can handle current of 800mA to 1A. So, that should be acceptable.

Arduino breadboard servo motor batteries

Arduino breadboard servo motor batteries

This program causes the motor to start and stop with 1 second intervals. When the output of pin 11 goes through a transistor, it causes electricity to run from the AA battery to the motor to make it move.

In this circuit, a diode has been placed before the motor. A diode regulates the flow of current, and allow to maintain a constant voltage. A diode only allows current to flow in one direction, so it is possible to use this to prevent a current from flowing in the wrong direction. By using this diode, we can protect the flow from reversing when the motor is under load, thus destroying circuits of the Arduino.

Motor Summary

This time, we have learned how to operate a motor using a transistor relay circuit. However, we only used Arduino as an ON/OFF switch. Since we’re using Arduino, we’d like to be able to adjust the motor’s angle of rotation and operate multiple motors. Next time, we’ll delve deeper into motor operations.