fbpx

Establishing a connection between a DC motor and a microcontroller (8051)

Establishing a connection between a DC motor and a microcontroller (8051)

INTRODUCTION

The first aspect that comes to mind in the context of robot control is the regulation of DC motors. The integration of a DC motor with a microcontroller is a fundamental concept in the field of robotics. Connecting a DC motor to a microcontroller enables various functionalities, such as regulating the motor’s direction and adjusting its speed. This piece of writing explains the method for operating a DC motor utilizing the AT89C51 controller.

In basic terms, a DC motor is a machine that changes electrical energy from a direct current system into mechanical energy. It is essential for the industry at present to recognize the importance of this matter.

At a voltage of 5V, the maximum current output for a microcontroller pin is 15mA. Most DC motors have power requirements that surpass what a microcontroller can handle, and the back electromotive force produced by these motors may pose a risk of damaging the microcontroller. Therefore, directly connecting the DC motor to the controller is not advisable. Ensure that a motor driver circuit is placed between the DC motor and the controller for optimal performance.

In this context, we are utilizing the L293D motor driver integrated circuit to control DC motors. With this IC, it is possible to control two DC motors concurrently. L293D is working on the principle of H-bridge circuit as follows.

H-Bridge Configuration

The designation “H-Bridge” originates from the layout of the switching circuit responsible for managing the motor’s motion. It is often identified as the “Full Bridge.” There are four switching elements present in this circuit.  The construction of H-bridges is achievable through the utilization of transistors, MOSFETs, and similar devices. Although it will be economical, there is a proposal to increase the dimensions of the design and the circuit board, which is often not preferred. Consequently, we can consider using a small 16-pin IC for this purpose.

Operation of H-bridge Circuit

The figure illustrates four switching elements identified as follows:

  • High side left
  • High side right
  • Low side right
  • Low side left

Operation of H-bridge Circuit

Activating these switches in pairs results in a corresponding change in the motor’s direction. When we enable “High side left” and “Low side right,” the motor will turn in a forward direction. This occurs because the current from the power supply flows through the motor coil and is directed to ground through the switch located on the low side (right). The figure below demonstrates this.

Operation of H-bridge Circuit

Likewise, when we engage the low side (left) and the high side (right), the current reverses its flow, leading to the motor turning in the opposite direction. This describes the essential functioning of an H-Bridge. A brief truth table can also be created based on the H-Bridge switching mechanism described earlier.

High Left

High Right

Low Left

Low Right

Description

On

Off

Off

On

Motor runs clockwise

Off

On

On

Off

Motor runs anti-clockwise

On

On

Off

Off

Motor stops or decelerates

Off

Off

On

On

Motor stops or decelerates

Table : Working of H-bridge circuit

Connecting a DC Motor to the 8051 Microcontroller

Schematic Representation of the Circuit

  • Input 1 – Port 2.0
  • Input 2 – Port 2.1
  • Enable 1 – Port 2.2
  • Enable 2 – Port 2.3
  • Input 3 – Port 2.4
  • Input 4 – Port 2.5

Schematic Representation of the Circuit

Procedure

Forward

  • EN Pin High  (En1 = 1 or En2 = 1)
  • Input 1 or Input 3 Pin High (In1 = 1 or In3=1)
  • Input 2 or Input 4 Pin Low (In2 = 0 or In4 = 0)

Reverse

  • EN Pin High  (En1 = 1 or En2 = 1)
  • Input 1 or Input 3 Pin Low (In1 = 0 or In3=0)
  • Input 2 or Input 4 Pin Low (In2 = 1 or In4 = 1)

Code

This code instructs the first motor to move forward, whereas the second motor is designated to move in the reverse direction.

Code