STEPPER MOTOR USING PIC MICROCONTROLLER,In this tutorial, you will learn to interface a stepper motor with PIC16F877A microcontroller. A stepper motor is a kind of a motor that converts electrical pulses into mechanical movement. Unlike all conventional motors, a stepper motor advances in steps. These steps of the motor are measured in degrees and can vary as per its application. It takes one step at the time and the size of each step is equal to the other.

There are three excitation modes of a stepper motor;wave drive, full driveand half drive. In wave drive mode, only one winding is energized at a given time, whereas in full drive mode, two phases are energized at the same time. The number of steps, however, are same in both wave and full drive modes. Half drive mode combines both wave drive and full drive i.e. it energizes one and two phase alternatively.  TASK

To drive a stepper motor using PIC microcontroller


Circuit diagram of stepper motor interfacing with pic16f877a microcontroller is given below:

Stepper Motor interfacing with PC16F877A microcontroller
Stepper Motor interfacing with PC16F877A microcontroller

The easiest way of interfacing a stepper motor with a microcontroller is via ULN2003 transistor array chip. This IC has seven Darlington transistor drivers and is used for high current torque motors. In the circuit diagram, the four input pins (1B, 2B, 3B, 4B) of ULN2003 are connected to the lower significant bits of PORTD of the microcontroller and the output pins (1C, 2C, 3C, 4C) are connected to the ‘live’ pins of the stepper motor as shown above.

The ‘common’ pins of the stepper motor, together with ‘COM’ pin of ULN2003 are hooked up to a 12V battery supply.

Stepper motor speed

The speed of the stepper motor can be increased or decreased via Proteus as well. For this purpose, right click on the stepper motor and select ‘Edit Properties. The window on the right will appear on the screen.

For a 200 step motor, a complete rotation (360°) is divided into 200 steps. This gives the size of a single step which is equal to 1.8°. You can vary the number ofsteps as well as the step angle using Proteus, the effects of which will be visible during simulation.

Parameters settings in proteus of stepper motor
Parameters settings in proteus of stepper motor



Write the following code in the mikroC code editor window:

  1. void main()
  2. {
  3. TRISD = 0b0000000; // PORT D as output port
  4. PORTD = 0b1111111;
  5. do
  6. {
  7. PORTD = 0b00000011;              // energizing two phases at a time
  8. Delay_ms(500); // delay of 0.5s
  9. PORTD = 0b00000110;
  10. Delay_ms(500);
  11. PORTD = 0b00001100;
  12. Delay_ms(500);
  13. PORTD = 0b00001001;
  14. Delay_ms(500);
  15. }while(1); // loop executed infinite times
  16. }

The above code represents the working of a stepper motor in full drive mode. For wave drive and half drive modes, slight changes will be required in the above code. The circuit diagram, however, remains the same. The PORTD of the controller has been declared as an output port which is fed to the driver IC ULN2003. The combination of bits from PORTD of the controller is transferred to the input pins of the IC, which enables it to switch the different coils of the motor on and off.


Stepper motors are used immensely in our daily life. They are used in automobiles, digital photocopiers, computer printers, to move the print head carriage, and other home appliances. Stepper motors are also used in industrial machines, security and medical equipments.

To dowload circuit diagram and code of stepper motor control using pic microcontroller click on following link :

Stepper motor code and simulation.

you can help us and others by sharing this article with your friends. Thanks 🙂

You may also like to read:


  1. sir, i wanna ask you something relevant to stepper motor interfacing with pic16f877a microcontroller to rotate it through step angle of 0 and 90. so sir i nedd your help. than you for your cooperation!


Leave a Comment