In this article, you will learn how to control DC, Stepper, and servo motors by Arduino and L293D.

In this article, you will learn how to control DC, Stepper, and servo motors by Arduino and L293D.

Story

In this article, you will learn how to control DC, Stepper, and servo motors by Arduino and L293D. At the end of this tutorial, you should be able to control spinning direction, acceleration, speed, power and shaft position.

If you do not know what L293D is, we suggest reading L293D: Theory, Diagram, Simulation & Pinout.

Why Driving Motors with L293D?

Driving electromotors needs a high current. In addition, spinning direction and speed are two important parameters to be controlled. These requirements can be handled by using a microcontroller (or a development board like Arduino). But there is a problem; Microcontrollers cannot provide enough current to run the motor and if you connect the motor to the microcontroller directly, you may damage the microcontroller. For example, Arduino UNO pins are limited to 40mA of current which is far less than the 100-200mA current necessary to control a small hobby motor. To solve this, we should use a motor driver. Motor drivers can be connected to the microcontroller to receive commands and run the motor with a high current.

L293D is one of the most popular motor drivers to run DC motors with up to 1A current load.L293D has 4 outputs which makes it suitable for 4-wire stepper motors. L293D can also be used to drive servo motors. In this project, you will learn how to drive motors with L293 and Arduino UNO as the controller. To learn more about L293D, do not miss this article: L293D: Theory, Diagram, Simulation & Pinout.

Controlling DC Motors

There are several types of DC motors, but here we will use a simple brushed DC motor. It has small plastic gears and is quite easy to drive. This motor is suitable for small robots and toys.

Circuit

In this circuit, the adjustable Power supply can be replaced with a 9V battery or power adapter. Make sure all wires and cables are connected correctly and then upload the code.

Code

Download the Controlling_DC_Motors.ino file. This is a very simple code. You can add more lines of code to improve motor performance.

Controlling a Stepper Motor

In this project we use a four-wire stepper motor. You can control stepper motors in three modes. Single step, half step, and power step. You should know the stepper motor wiring connections. If you don’t, use an ohm meter to find out.

Circuit

Sometimes, Stepper motors make some noise in the circuit. You can parallel a few capacitors to remove them.

Code

Download the Controlling_a_Stepper_Motor.ino file. This code is just for the first time running. To improve the performance of the motor, you can use the example code of Arduino libraries

Controlling a Servo Motor

Micro servo motors (also known as 9 grams servo) are very useful in small robotics projects like a robot arms. You should produce PWM signals to control servo motors. Servo motors can be very fast and powerful based on their type and size.

Code

Download the Controlling_a_Servo_Motor.ino file. This is a code from Arduino libraries.

ElectroPeak Inc
At ElectroPeak.com, we love electronics and robotics, we love what we do and like to share our expertise with you. Let's enjoy electronics more!