Home / Projects / PIC Projects / PIC16F877A Stepper Motor Controller

PIC16F877A Stepper Motor Controller

This project is a stepper motor controller featuring the PIC16F877A microcontroller and coded using XC8. The controller has three control buttons: start, stop, forward and reverse. The project was created with a six-wire unipolar stepper motor in mind but may work with other stepper motors with some modifications.


A stepper motor requires pulses in specific pattern to move or “step”. Generally, there are three ways to move a stepper motor.

  • Half-step – a single wire is set high while the others are set low. The pulsed wires are alternated to make a full revolution
  • Full-step – two wires are set high simultaneously while the others are set low. The paired wires are alternated to make a full revolution.
  • Microstepping – half-step and full-step patterns are combined to make finer movements.

This project uses microstepping as it is the most commonly used stepping method.

[the_ad id=”3059″]

Materials Needed

  • PIC16F877A
  • Unipolar 6-wire Stepper Motor
  • 5 x SPST pushbuttons
  • 4 x BC547 NPN transistor
  • 5 x 10k 1/4 W resistor
  • 4 MHz crystal
  • 2 x 22pF ceramic capacitor

Schematic Diagram

The schematic diagram for the stepper motor controller is shown below:

PIC16F877A Stepper Motor Controller Schematic

[the_ad id=”3059″]

Basically, each of the wires of the stepper motor is connected to a transistor switch to allow more current through the motor. A pulse from the microcontroller turns on a transistor and effectively shorts the connected wire to ground. Since the common pin is tied to the positive supply (which is separate from the microcontroller supply), the microcontroller pin must be low to make a stepper motor wire high.

I’ve included LEDs to have a visual representation of the stepping patterns. Obviously, omitting them will not have any adverse effect on the project’s performance.

Lastly, the choice of transistor depends on the current draw of your chosen stepper motor. For larger stepper motors, I suggest using darlington pairs.


The four buttons are purposely tied to RB4, RB5, RB6 and RB7 because I wanted to use RB change interrupt. This allows me to change the stepper motor behavior even if the motor is currently turning. Using an interrupt with buttons also diminishes debounce problems. If you’re having problems understanding the code, kindly refer to my interrupt tutorial.

Project Files

You can use Proteus ISIS to simulate the code above. I’ve included the design files here for you to use.

[wpdm_package id=’1963′] [the_ad id=”3059″]

If you have any questions, kindly drop a comment below. Have fun building!

Check Also

Adjustable Timer with Relay

Adjustable Timer with Relay

Project Overview This adjustable timer displays seconds, minutes and hours and is powered by a …

One comment

  1. Almir Gonçalves Pereira

    How to make broad speed control through a potentiometer?

    What would the circuit and program for controlling a bipolar stepper motor via L298 look like, including speed control via potentiometer?

Leave a Reply

Your email address will not be published.