Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Interfacing stepper motor with 8051(89c51,89c52 ) microcontroller

By EG Projects February 14, 2021

Here is a simple tutorial on how to interface stepper motor with 89c51 microcontroller. Stepper motor as the name depicts takes steps to complete a full 360 degree circular rotation. We can rotate stepper in clock and anti clock wise direction. Stepper motor speed can also be varied. There are many types of steeper motors four step, eight step or eighteen step. Stepper motors are classified on steps taken my a particular motor to complete one full 360 degree rotation. Our focus is on four step motor. Once you are familiar with four step stepper motor you can drive any type of steeper motor. 

Stepper motor working

I am going to use four steep stepper motor in this project. There are generally 5 or 6 wires coming out of a four steep stepper motor. In 5 wires, one is our vcc(external voltage) and the 4 renaming are step wires. In 6 wired 2 are our vcc(external voltage) and the renaming four are step wires.

  • To learn about how stepper motor works? Here is a good tutorial.GOOD TUTORIAL FROM WIKIPEDIA.

​
Stepper motor works on 5 volts to 12 volts. Stepper motor which i am using in this tutorial is NEMA 17. Its a bipolar stepper motor. Each step taken by nema 17 stepper motor counts to 1.8 degree increase. So in 200 steps nema 17 complete one rotation 360(200*1.8= 360) degree. Our concern in this tutorial is only to rotate the stepper motor. 

Nema 17 stepper motor

Nema 17 stepper motor

Stepper motor power consumption

Stepper motor consumes 0.1 to 1 ampere of current during step rotation with load. Microcontrollers can not output this amount of power. So we can not directly interface the stepper motors with microcontrollers like 89c51 microcontroller whose pins can output max 0.045 amperes of current. 

ULN2003 driver use for stepper motor

In order to cover the above stepper motor power constraint we need an external power source which can drive heavy loads and supply sufficient amount of power for stepper motor operation. ULN2003 is an ic containing pairs of darlington configuration of transistors. ULN2003 takes low power input and outputs a signal with greater power. I decided to use this driver ic for driving the stepper motor.   

ULN2003 driver

ULN2003 driver

8051 microcontroller stepper motor – Project circuit

Connect 8051(89c51) microcontroller Port#1 lower four bits to ULN2003 driver ic. 89c51 microcontroller is unable to output sufficient voltage/current to drive a motor so a driver ic is needed to fullfil motor voltage/current requirements. The output of the ULN2003 is connected to our stepper motor. Make sure to input same wire to motor which you are specifying in your code step. Make pin 8 of ULN2003 ground. Apply same voltage on ULN2003 pin 9 which you are giving to your motor. 

Stepper motor interface with 89c51 microcontroller circuit diagram is given below. Note the steps taken by stepper motor in GIF image below. For each step we have to make each step pin high and follow the pattern shown in the GIF image. Stepper motor step pins/wires are colored yellow, brown, black and green etc. We first have to make sure the step wires pattern. Nema 17 stepper motor pattern is shown in the GIF image.

Note: The pattern must be in right order to rotate the stepper motor. Pay attention to the color code of steeper motor wires below.

stepper motor with 89c51 microcontroller and uln2003 driver

stepper motor with 89c51 microcontroller and uln2003 driver

Stepper motor interface with 8051 microcontroller – Project code

The code is very simple. It is written in c++ language using keil ide as software tool to write and compile the code. First the necessary file reg51.h is included. Then a delay function is created to give some delays in steps. This delay is very important use it to avoid back emf(electric motive force) generated by motor, other wise your controller will be damaged by this back emf produced by stepper motor. You can also speed up the motor rotation by reducing delay time. In the main function i used some commands to rotate stepper motor. The commands are explained below. The commands are in hexadecimal format.

P1=0x01 Making Port 1 bit 0 high for first step.              Binary equivalent=00000001
P1=0x00 Making port 1 all bits 0 for next step.               Binary equivalent=00000000
P1=0x02 Making port 1 bit 1 high for second step.         Binary equivalent=00000010
P1=0x00 Making port 1 all bits 0 for next step.               Binary equivalent=00000000
P1=0x04 Making port 1 bit 2 high for third step.              Binary equivalent=00000100
P1=0x00 Making port 1 all bits 0 for next step.               Binary equivalent=00000000
P1=0x08 Making port 1 bit 3 high for fourth step.           Binary equivalent=00001000

You can also individually declare the bits and make them high and low for sufficient steps. The while(1) loop is continuously running the motor in clock wise direction. You can also reverse the direction anticlock wise by just reversing the commands, place the last command(0x08) at first and reverse the
order in same way for rest of the commands.

With a slight modification in code you can vary the speed of stepper motor with 89c51 microcontroller. Just decrease the delay or remove it. To rotate to a certain angle calculate the steps required to reach the angle and place the steps in for loop. I hope it makes sense to you.

More projects involving stepper motors and different microcontrollers are listed below. Each project is unique and a dedicated microcontroller is controlling the stepper motor. All the projects are open source. You can modify them according to your needs.

Stepper motor controlled through web using nodemcu

Stepper motor controller over Bluetooth with android app

Stepper motor controlled with 32 bit stm32 microcontroller

Download the project files and code compiled in keil uvision 4. Code is written in c language. If you have any questions regarding the post just leave a comment below. Project video is also given below.

Watch 89c51 stepper motor interface project video

Stepper motor 8051 code

You may also like:


  • What are different types of industrial robots?

  • How to select drone motors

  • What types of motors are used in electric vehicles?

  • What are the components of robotic arms and industrial robots?

  • What drone parts you need to build a quadcopter?
  • battery selection low power design
    What are the battery-selection criteria for low-power design?

Filed Under: 8051 Microcontroller, Electronic Projects, Featured Contributions

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Power Efficiency
Discover proven strategies for power conversion, wide bandgap devices, and motor control — balancing performance, cost, and sustainability across industrial, automotive, and IoT systems.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions.

  • Help me understand comparators , AD8611 in particular
  • Methods for Calculating SNR and SFDR in a CUI for Use in Machine Learning
  • rechargeable battery and simple alkaline battery in one single product
  • Industrial Network Market Analysis and Introduction to Common Bus Protocols
  • Ensuring Reliable Backups in Azure

RSS Electro-Tech-Online.com Discussions

  • WTB: "The Theory Of Servicing AM, FM, And FM Receivers" by Clarence R. Green and Robert M. Bourque
  • Anyone In The US Ordered From AliExpress Recently?
  • Calculation of A Class amplifier
  • strange laptop problem
  • restarting this Christmas project

Featured Tutorials

Real Time Hardware Filter Design

  • Practical implementation of bandpass and band reject filters
    Practical implementation of bandpass and band reject filters
  • Practical application of hardware filters with real-life examples
    Practical application of hardware filters with real-life examples
  • A filter design example
    A filter design example
  • Types of filter responses
    Types of filter responses
  • What are the two types of hardware filters?
    What are the two types of hardware filters?
  • What are hardware filters and their types?
    What are hardware filters and their types?
More Tutorials >

Recent Articles

  • Stackpole introduces compact jumpers for high-current circuit routing
  • Ironwood Electronics launches near-device-footprint SMT elastomer socket for BGA264
  • Amphenol RF releases P67 FAKRA plugs for 6 GHz RF transmission
  • Microchip releases platform to deliver real-time specifications for AI assistants
  • GigaDevices introduces 32-bit MCUs with integrated DSP and FPU support

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe