Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

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

December 1, 2020 By EG Projects

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

Related Articles Read More >

Wireless distance measurement using ultrasonic sensor
Computerized wireless Pick and Place Robot
Designing an Arduino-based ECG monitor using an AD8232 ECG sensor
Controlling Appliances Wirelessly using RF Technology

Featured Tutorials

  • Screenshot of Raspbian OS on Raspberry Pi RPi Python Programming 03: Raspberry Pi as Linux System
  • Raspberry Pi Models RPI Python Programming 02: Raspberry Pi Models
  • Raspberry Pi 4 RPi Python Programming 01: Introduction to Raspberry Pi 4
  • RPi Python Programming 05: Introduction to Python
  • RPi Python programming 04 RPi Python programming 04: Setting up Raspberry Pi Linux computer
  • Python Basics RPi Python Programming 06: Python basics

Stay Up To Date

Newsletter Signup

EE Training Center Classrooms

“ee

“ee

“ee

“ee

Recent Articles

  • Arduino’s L293D motor driver shield guide
  • NXP launches its first Wi-Fi 6E Tri-Band system-on-chip
  • Nexperia launches industry’s first 80 V RETs for high-voltage bus circuits
  • TDK releases low-profile medical sensors
  • Getting started with Raspberry Pi
...

RSS EDABOARD.com Discussions

  • hysteresis variation mc sim
  • Need help with Audio intercom design circuit?
  • complex bjt transfer function amplifier
  • Creepage distance from primary to secondary of offline SMPS
  • FT232 > Package

RSS Electro-Tech-Online.com Discussions

  • new to Ardunio but trying to compile
  • Engine Temperature using an AD590 on the Oil Pressure Wire to the engine
  • Dead Battery circuits.
  • electrolytic capacitor depolarizes
  • Symphonic TV/VCR problems (potentially loose yoke)...
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2021 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 | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering