Arduino DC motor

The DC motor is considered as the simplest motor, which has various applications ranging from households to industries. Example includes an electric window in cars, electric vehicles, elevators, etc.

The principle of the DC motors is based on Electromagnetic Induction. It means that the rotation of the motor depends on the force generated by the magnetic fields. It converts electrical energy into mechanical energy. Such motors can be powered from the direct current.

Let's discuss how the DC motor works.

Working of DC Motor

The DC motor consists of a stator, rotor, armature, and a commutator. The commutator comes with brushes. There are two stationary magnets in the stator that are responsible for producing the magnetic field.

The armature present in the DC motor carries the alternating current. Electrical energy is converted into mechanical energy in the form of torque by the armature. It further transfers this mechanical energy via shaft.

The commutator is defined as the electrical switch. It can also reverse the direction of the current between the external circuit and the motor. The brushes act as an intermediate between the external power supply and the rotating coils.

The iron core at the center is wrapped with insulated wires concentrating on the magnetic field when current passes through the wires. The windings of insulated wire have many turns around the core of the motor.

The wire ends are connected to the commutator. The commutator further energizes the armature coils and connects the power supply and the rotating coils through brushes.

Advantages of DC motors

The advantages of using DC motors are listed below:

  • Low cost
  • Easy motor speed control
  • High reliability
  • Minimal Maintenance
  • High starting torque
  • Quick starting
  • Variable speeds
  • Harmonics free

The DC motor looks like the image shown below:

Arduino DC motor

Let's start with the project.

We will discuss two projects of the DC motor.

Project 1:

Here, we will discuss the simple connection of a DC motor with the Arduino board using diode, transistor, and resistor.

Hardware Required

The components required in the project are listed below:

  • Arduino UNO R3 board
  • Breadboard
  • A Resistor of 2.2K Ohm
  • Transistor (NPN)
  • Diode
  • DC Motor
  • Jump wires

Structure of the project

The structure of the project is shown below:

Arduino DC motor

Sketch

Consider the below code:

Steps to upload the code to the board

The steps are listed below:

  • Open the Arduino IDE.
  • Select the type of board from Tools -> Board -> Arduino UNO.
  • Select the port from Tools -> Port -> COM.
  • Upload the above sketch to the connection diagram.

Connection

The steps to set up the connection are listed below:

  • Connect one end of the resistor to pin 10 (PWM) of the Arduino board.
  • Connect the other end of the resistor to the middle pin of the transistor.
  • Connect one end terminal of the transistor to the GND pin of the Arduino and another end terminal to the diode.
  • Connect the band facing terminal of the diode to the 5V pin of the Arduino board.
  • Connect one end terminal of the DC motor to band facing terminal of the diode.
  • Connect another end terminal of the DC motor to the other end of the diode.

Connection Diagram

We will show the connection using the Simulator so that the connections become clearer and more precise.

We can make the same connection using the hardware devices.

Arduino DC motor

After making connections, the motor will rotate.

Project 2:

Here, we will discuss the connection of a DC Gear motor with the Arduino board using the L293D H-Bridge motor driver.

Let's discuss the need to use the L293D H-Bridge motor driver with the DC motor.

L293 is defined as the motor driver IC that permits the DC motor to drive in any direction. It can also simultaneously control two DC motors. It is a 16-pin Integrated Circuit (IC).

It receives signals from the microprocessor present on the Arduino board and transmits this signal to the motor. It has two VCC or voltage pins, where one pin draws current for its working and another is used to provide voltage to the DC motor.

The motor usually requires high current for its operation. We can use the microcontroller present on the Arduino, but high current might damage the microcontroller. To overcome this, the motor driver is used.

L293D is one of the most popular motor drivers used to drive the DC motors. It can run DC motors up to 1 Ampere current load.

The four outputs present on the L293D driver makes it suitable for driving the 4-wire stepper motor as well. We can also drive servo motors using the L293D driver.

L293D Pinout

The pinout of L293D is shown below:

Arduino DC motor

Hardware Required

The components required in the project are listed below:

  • Arduino UNO R3 board
  • Breadboard
  • DC Gear Motor
  • Adjustable 30V supply
  • Jump wires
  • L293D H-Bridge motor driver

Sketch

Consider the below code:

Connection

The steps to set up the connection are listed below:

  • Connect the red terminal of the power supply to the VCC of L293D.
  • Connect the black terminal of the power supply to the GND of the L293D.
  • Connect both terminals of the motor to Output pin 1 and 2 of the L293D driver.
  • Connect input pin 2 of L293D to the digital pin 8 of the Arduino board.
  • Connect the enable pin 1 and input 1 to the PWM pin 10 and 11 of the Arduino board.
  • Connect VCC of the L293D driver to the 5V pin of the Arduino board.
  • Connect GND of the L293D driver to the GND pin of the Arduino board.

Connection Diagram

We will show the connection using the Simulator so that the connections become clearer and more precise.

We can make the same connection using the hardware devices.

Arduino DC motor

The 'Slow' mode of speed will cause the motor to rotate at a slow speed. We can also change the mode to fast or normal, as explained in the code.

We can also add more speed parameters to the code as per our requirements.


Next TopicArduino Nano