0% found this document useful (0 votes)
102 views3 pages

Bipolar Stepper Motor

This document provides two examples of code to control a bipolar stepper motor. The first example is a simple code to spin the motor in one direction. The second example allows controlling the motor speed and direction using a potentiometer. It uses an ULN2003A driver chip connected to an Arduino board to provide higher current than the board alone. The motor has five wires for power and two coils that are controlled by toggling the voltage to move the motor forward or backward in half-step increments.

Uploaded by

dirty_harry1992
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views3 pages

Bipolar Stepper Motor

This document provides two examples of code to control a bipolar stepper motor. The first example is a simple code to spin the motor in one direction. The second example allows controlling the motor speed and direction using a potentiometer. It uses an ULN2003A driver chip connected to an Arduino board to provide higher current than the board alone. The motor has five wires for power and two coils that are controlled by toggling the voltage to move the motor forward or backward in half-step increments.

Uploaded by

dirty_harry1992
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Bipolar Stepper Motor

This page shows two examples on how to drive a bipolar stepper motor. These motors can be found in old floppy drives and are easy to control. The one we use has 6 connectors of which one is power (VCC) and the other four are used to drive the motor sending synchronous signals. The first example is the basic code to make the motor spin in one direction. It is aiming those that have no knowledge in how to control stepper motors. The second example is coded in a more complex way, but allows to make the motor spin at different speeds, in both directions, and controlling both from a potentiometer. The prototyping board has been populated with a 10K potentiomenter that we connect to an analog input, and a ULN2003A driver. This chip has a bunch of transistors embedded in a single housing. It allows the connection of devices and components that need much higher current than the ones that the ATMEGA8 from our Arduino board can offer.

Example 1: Simple example


/* Stepper Copal * ------------* * Program to drive a stepper motor coming from a 5'25 disk drive * according to the documentation I found, this stepper: "[...] motor * made by Copal Electronics, with 1.8 degrees per step and 96 ohms * per winding, with center taps brought out to separate leads [...]" * [http://www.cs.uiowa.edu/~jones/step/example.html] * * It is a bipolar stepper motor with 5 wires: * * - red: power connector, I have it at 5V and works fine * - orange and black: coil 1 * - brown and yellow: coil 2 * * (cleft) 2005 DojoDave for K3 * http://www.0j0.org | http://arduino.berlios.de * * @author: David Cuartielles * @date: 20 Oct. 2005 */ int int int int int motorPin1 motorPin2 motorPin3 motorPin4 delayTime = = = = = 8; 9; 10; 11; 500; OUTPUT); OUTPUT); OUTPUT); OUTPUT);

void setup() { pinMode(motorPin1, pinMode(motorPin2, pinMode(motorPin3, pinMode(motorPin4,

} void loop() { digitalWrite(motorPin1, digitalWrite(motorPin2, digitalWrite(motorPin3, digitalWrite(motorPin4, delay(delayTime); digitalWrite(motorPin1, digitalWrite(motorPin2, digitalWrite(motorPin3, digitalWrite(motorPin4, delay(delayTime); digitalWrite(motorPin1, digitalWrite(motorPin2, digitalWrite(motorPin3, digitalWrite(motorPin4, delay(delayTime); digitalWrite(motorPin1, digitalWrite(motorPin2, digitalWrite(motorPin3, digitalWrite(motorPin4, delay(delayTime); } HIGH); LOW); LOW); LOW); LOW); HIGH); LOW); LOW); LOW); LOW); HIGH); LOW); LOW); LOW); LOW); HIGH);

Example 2: Stepper Bipolar Advanced


/* Stepper Bipolar Advanced * -----------------------* * Program to drive a stepper motor coming from a 5'25 disk drive * according to the documentation I found, this stepper: "[...] motor * made by Copal Electronics, with 1.8 degrees per step and 96 ohms * per winding, with center taps brought out to separate leads [...]" * [http://www.cs.uiowa.edu/~jones/step/example.html] * * It is a bipolar stepper motor with 5 wires: * * - red: power connector, I have it at 5V and works fine * - orange and black: coil 1 * - brown and yellow: coil 2 * * (cleft) 2005 DojoDave for K3 * http://www.0j0.org | http://arduino.berlios.de * * @author: David Cuartielles * @date: 20 Oct. 2005 */ int int int int motorPins[] = {8, 9, 10, 11}; count = 0; count2 = 0; delayTime = 500;

int val = 0; void setup() { pinMode(ledPin, OUTPUT); for (count = 0; count < 4; count++) { pinMode(motorPins[count], OUTPUT); } } void moveForward() { if ((count2 == 0) || (count2 == 1)) { count2 = 16; } count2>>=1; for (count = 3; count >= 0; count--) { digitalWrite(motorPins[count], count2>>count&0x01); } delay(delayTime); } void moveBackward() { if ((count2 == 0) || (count2 == 1)) { count2 = 16; } count2>>=1; for (count = 3; count >= 0; count--) { digitalWrite(motorPins[3 - count], count2>>count&0x01); } delay(delayTime); } void loop() { val = analogRead(0); if (val > 540) { // move faster the higher the value from the potentiometer delayTime = 2048 - 1024 * val / 512 + 1; moveForward(); } else if (val < 480) { // move faster the lower the value from the potentiometer delayTime = 1024 * val / 512 + 1; moveBackward(); } else { delayTime = 1024; } }

You might also like