Motor Circuit Diagrams

Stepper Motor Control using 8051 Microcontroller

A stepper motor is a synchronous and brushless motor that divides a complete revolution into discrete steps. Each stepper motor is characterized by a specific fixed step angle at which it rotates. In this tutorial, I will guide you through the process of connecting a stepper motor to an 8051 microcontroller using two different drivers: the L293D and the ULN2003. Additionally, I will explain how to control a stepper motor with an 8051 microcontroller.

Outline

  • Stepper Motor Control using 8051 Microcontroller Principle
  • Circuit 1: Stepper Motor Control using 8051 Microcontroller & L293D
    • Circuit Diagram
    • Components Required 
    • Circuit Design 
    • CODE 
    • Working 
  • Circuit 2: Stepper Motor Control using 8051 Microcontroller & ULN2003
    • Circuit Diagram
    • Circuit Components
    • Circuit Design
    • Circuit Simulation Video of Interfacing Stepper Motor with 8051 & ULN2003
    • How to Operate this Stepper Motor Driver Circuit?
  • Stepper Motor Controller Circuit Advantages
  • Stepper Motor Control Applications

Stepper Motor Control using 8051 Microcontroller Principle

The fundamental concept behind these circuits is to incrementally rotate the stepper motor at a specific step angle. To achieve this, the ULN2003 IC and the L293D Motor Driver are employed to actuate the stepper motor, as the microcontroller alone cannot deliver the necessary current for motor operation.

Circuit 1: Stepper Motor Control using 8051 Microcontroller & L293D

The first circuit in this project is implemented using an L293D Motor Driver IC. Since the L293D Motor Driver has option for four output pins, only a Bipolar Stepper Motor can be driven using it. 

Circuit Diagram

The circuit diagram of interfacing a Bipolar Stepper Motor with 8051 Microcontroller and L293D Motor Driver is shown in the image below. 

Components Required 

  • AT89C51 (8051 Microcontroller) 
  • L293D Motor Driver 
  • 5V Bipolar Stepper Motor 
  • 16X2 LCD Diaplay 
  • 11.0592 MHz Quartz Crystal 
  • 10KΩ Resistors X 2 
  • 10KΩ POT 
  • 8x 1KΩ Resistor Pack 
  • 33pF Ceramic Capacitors X 2  
  • 10μF/16V Capacitor 
  • Push Buttons X 4 
  • 330Ω Resistor 
  • 5V Power Supply

Circuit Design 

To begin, the data pins of the LCD are connected to the PORT0 pins of the 8051 microcontroller. Since PORT0 lacks built-in pull-ups, a resistor pack is used to provide pull-up resistors. The RS and E pins of the LCD are linked to P2.0 and P2.1 of the 8051.

To control the RST Pin, a 10K resistor is employed for pull-down. The microcontroller’s reset function is facilitated by a Push Button in conjunction with a 10F Capacitor. Additionally, a 10K resistor is used to enable the EA Pin.

Next in the setup is the oscillator, consisting of two 33pF capacitors and an 11.0592 MHz crystal, which is connected to the XTAL1 and XTAL2 pins of the 8051.

For the Motor Driver, both enable pins and supply pins are linked to the +5V power source. The four inputs, P1.0, P1.1, P1.2, and P1.3, are connected to the PORT1 pins of the 8051 microcontroller. The four pins of the Bipolar Stepper Motor are connected to the four output pins of the L293D.

To control the direction of the Stepper Motor, three buttons, P3.0, P3.1, and P3.2, are connected to the PORT3 pins.

CODE 

  #include<reg51.h>
  #define lcd P0
  sbit rs=P2^0;
  sbit e=P2^1;
   
  sbit sw1=P1^2;
  sbit sw2=P1^1;
  sbit sw3=P1^3;
  sbit sw4=P1^0;
   
  sbit forward = P3^0;
  sbit backward = P3^1;
  sbit stop = P3^2;
   
   
  void delay (int);
  void cmd (unsigned char);
  void display (unsigned char);
  void string (char *);
  void init (void);
   
   
  void delay (int d)
  {
  unsigned char i;
  for(;d>0;d–)
  {
  for(i=250;i>0;i–);
  for(i=248;i>0;i–);
  }
  }
  void cmd (unsigned char c)
  {
  lcd=c;
  rs=0;
  e=1;
  delay(10);
  e=0;
  }
  void display (unsigned char c)
  {
  lcd=c;
  rs=1;
  e=1;
  delay(10);
  e=0;
  }
  void string (char *p)
  {
  while(*p)
  {
  display(*p++);
  }
  }
  void init (void)
  {
  cmd(0x38);
  cmd(0x0c);
  cmd(0x01);
  cmd(0x80);
  }
   
  void main()i
  {
  int z=0;
  init();
  P3=0xff;
  P1=0x00;
  abc:
  cmd(0x80);
  while(stop==0);
  string(“Press Forward Or”);
  cmd(0xc0);
  string(“Backward To Run”);
  forward=1;
  backward=1;
  while(1)
  {
  if(forward==0)
  {
  cmd(0x01);
  cmd(0x80);
  string(“Running Forward”);
  while(forward==0);
  while(1)
  {
  z++;
  if(z==1)
  {
  sw1=1;sw2=0;sw3=0;sw4=0;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  else if(z==2)
  {
  sw1=1;sw2=1;sw3=0;sw4=0;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  else if(z==3)
  {
  sw1=0;sw2=1;sw3=0;sw4=0;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  else if(z==4)
  {
  sw1=0;sw2=1;sw3=1;sw4=0;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  else if(z==5)
  {
  sw1=0;sw2=0;sw3=1;sw4=0;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  else if(z==6)
  {
  sw1=0;sw2=0;sw3=1;sw4=1;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  else if(z==7)
  {
  sw1=0;sw2=0;sw3=0;sw4=1;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  else if(z==8)
  {
  z=0;
  sw1=1;sw2=0;sw3=0;sw4=1;delay(30);
  if(backward==0 || stop==0)
  break;
  }
  }
  }
   
  if(backward==0)
  {
  cmd(0x01);
  cmd(0x80);
  string(“Running Backward”);
  while(backward==0);
  while(1)
  {
  z++;
  if(z==1)
  {
  sw1=1;sw2=0;sw3=0;sw4=1;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  else if(z==2)
  {
  sw1=0;sw2=0;sw3=0;sw4=1;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  else if(z==3)
  {
  sw1=0;sw2=0;sw3=1;sw4=1;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  else if(z==4)
  {
  sw1=0;sw2=0;sw3=1;sw4=0;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  else if(z==5)
  {
  sw1=0;sw2=1;sw3=1;sw4=0;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  else if(z==6)
  {
  sw1=0;sw2=1;sw3=0;sw4=0;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  else if(z==7)
  {
  sw1=1;sw2=1;sw3=0;sw4=0;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  else if(z==8)
  {
  z=0;
  sw1=1;sw2=0;sw3=0;sw4=0;delay(30);
  if(forward==0 || stop==0)
  break;
  }
  }
  }
  if(stop==0)
  goto abc;
  }
  }

Working 

The functioning of this circuit is quite straightforward. It utilizes a technique called half-stepping to drive the Stepper Motor. When the forward button is pressed, the stepper motor rotates in a clockwise direction.

Stepper Motor

Similarly, when the backward button is pushed, it starts rotating in anti-clockwise direction. To stop the rotation completely, you can press the stop button. 

Circuit 2: Stepper Motor Control using 8051 Microcontroller & ULN2003

In the second part of the project, we employ an 8051 microcontroller and a ULN2003 to control a stepper motor. The ULN2003 Transistor Array provides 7 outputs, allowing you to manage both Unipolar and Bipolar Stepper Motors.

In this project, I will guide you through the process of driving a 5-Wire Unipolar Stepper Motor using an 8051 Microcontroller and a ULN2003 Transistor Array.

Circuit Diagram

Following image shows the circuit diagram of interfacing a Stepper Motor with 8051 Microcontroller and ULN2003. 

Circuit Components

  • AT89C51 Microcontroller
  • ULN2003A
  • Stepper Motor
  • Crystal
  • Resistor
  • Capacitor

Circuit Design

The circuit comprises the AT89C51 microprocessor, ULN2003A, and a motor. The AT89C51 belongs to the low-power, high-performance CMOS 8-bit microcontroller family known as 8051. It boasts 32 programmable I/O lines and is equipped with 4K bytes of programmable and erasable Flash memory. The microcontroller’s pins 18 and 19 are externally connected to a crystal oscillator, while a driver IC links the motor to port 2 of the microcontroller.

The ULN2003A serves as a current driver integrated circuit and is instrumental in driving the stepper motor due to its demand for currents exceeding 60mA. It consists of a collection of Darlington pairings, encompassing seven Darlington arrays with a common emitter. The IC features 16 pins, with 7 serving as input pins, 7 as output pins, and the remaining pins for VCC and Ground. The microcontroller connects to the initial four input pins, while four output pins are routed to the stepper motor.

A stepper motor has six pins, with two of them linked to a 12V supply, while the rest connect to the motor’s outputs. The stepper motor rotates in discrete increments, with each step representing a fraction of a complete cycle. The specifics of these steps are contingent upon the mechanical components and the chosen driving method.

Similar to other motors, a stepper motor comprises a stator with coils and a rotor with a permanent magnet. The fundamental stepper motor configuration includes four coils that rotate at 90-degree intervals. These coils are activated in a sequential pattern, determining the shaft’s rotation direction, as depicted in the diagram below. Various driving methods for stepper motors are explored further in the discussion below.

Full Step Drive:

In this method two coils are energized at a time. Thus, here two opposite coils are excited at a time. 

Half Step Drive:

In this approach, coils receive energy in an alternating manner, resulting in rotation at a half-step angle. Within this method, either two coils or a single coil can be energized simultaneously, effectively increasing the number of rotations per cycle. This configuration is visually depicted in the illustration below.

Circuit Simulation Video of Interfacing Stepper Motor with 8051 & ULN2003

How to Operate this Stepper Motor Driver Circuit?

  • Initially, switch on the circuit.
  • Microcontroller  starts driving the stepper motor.
  • One can observe the rotation of the stepper motor
  • The stepper motor has four wires. They are yellow, blue, red and white. These are energized alternatively as given below.
  • In full step driving, use the following sequence:
  • To drive the motor in half step angle, use the following sequence:

Stepper Motor Controller Circuit Advantages

  • It consumes less power.
  • It requires low operating voltage.

Stepper Motor Control Applications

  • This circuit can be used in the robotic applications.
  •  This can also be used in mechantronics applications.
  • The stepper motors can be used in disk drives, matrix printers, etc.
Tags

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button
Close
Close