Menu Close

Arduino – Stepper Motor with ULN2803 IC

This tutorial of Robo India explains how to drive Stepper Motor Using ULN2803 with Arduino UNO.

1. Introduction 

Stepper motors are like DC motors, which is used to move in steps. These motors have multiple coils that are organised in group which is known as phase. In this tutorial, we have explained how to interface Step Motor 28BYJ-48 with Arduino UNO using ULN2803.

Stepper motors fall somewhere in between a regular DC motor and a servo motor. Servo motors are usually limited to 0-180 degree rotation, while a stepper motor can rotate continously like dc motors. They have the advantage that they can be positioned accurately and you can control over the movement. The only drawback of step motor is, they are little bit harder to control than other motors and servo motors.

1.1 Stepper Motor Working: 

There are two types of Stepper motors: Unipolar and Bipolar. The difference between the two types is the voltage levels.

A unipolar stepper motor only operates with positive voltage, so the high and low voltages applied to the electromagnetic coils would be something like 5V and 0V.

And a bipolar stepper motor has two polarities, positive and negative, so its high and low voltages would be something like 2.5V and -2.5V.

Different types of Stepper Motors have different numbers of wires like 4,5,6,8. In bipolar stepper motors, there are arrangements of 4 wires. Central wire is not available

The stepper motor, which we have used has 5 wires, implying that it is to be run as a unipolar stepper motor. This 5th wire is to allow current on coils to flow in two directions

1.2 ULN2803 IC:

ULN2803 is a high current, high voltage IC, used to drive high power loads upto 500mA/50V such as relays, motors etc.

 2. Hardware required

S.No.ItemQuantity
1Arduino UNO 1
2Breadboard 1
328BYJ-48 Stepper Motor 2
4ULN2803 IC 7
5Male to male Jumper 11

3. Connection:

Use the colors of the leads to identify them, not the position from which they emerge from the motor.

4. Programming:

You may download this code (Arduino Sketch) from here.



#define IN1  5
#define IN2  6
#define IN3  7
#define IN4  8
int Steps = 0;
boolean Direction = true;// gre
unsigned long last_time;
unsigned long currentMillis ;
int steps_left=4095;
long time;
void setup()
{
Serial.begin(115200);
pinMode(IN1, OUTPUT); 
pinMode(IN2, OUTPUT); 
pinMode(IN3, OUTPUT); 
pinMode(IN4, OUTPUT); 
// delay(1000);


}
void loop()
{
  while(steps_left>0){
  currentMillis = micros();
  if(currentMillis-last_time>=1000){
  stepper(1); 
  time=time+micros()-last_time;
  last_time=micros();
  steps_left--;
  }
  }
   Serial.println(time);
  Serial.println("Wait...!");
  //delay(2000);
  //Direction=!Direction;
  Direction =  -1;
  steps_left=4095;
}

void stepper(int xw){
  for (int x=0;x<xw;x++){
switch(Steps){
   case 0:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, HIGH);
   break; 
   case 1:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, HIGH);
   break; 
   case 2:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, LOW);
   break; 
   case 3:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, LOW);
   break; 
   case 4:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
   case 5:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
     case 6:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
   case 7:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, HIGH);
   break; 
   default:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
}
SetDirection();
}
} 
void SetDirection(){
  Steps--;
//if(Direction==1){ Steps++;}
//if(Direction==0){ Steps--; }
//if(Steps>7){Steps=0;}
if(Steps<0){Steps=7; }
}

 5. Output

After uploading the above code, the stepper motor will start rotating continously.

There are many usage of stepper motors, which includes medical scanners, 3D printers, in cameras, auomated blinds and more.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply