User Tools

Site Tools


steppernxt

This is an old revision of the document!


How To Control an Unipolar Stepper Motor with LEGO NXT Using Only Transistors

Author: Xinke (Rebecca) Cao
Email: [email protected]
Date: Last modified on 08/04/2017
Keywords: unipolar stepper motor, LEGO NXT, transistors, IRF510

Motivation and Audience

In many instances in engineering, precise rotary movement is necessary to produce accurate results. The stepper motor, a motor that rotates a certain amount of degree per step; therefore, allow the user to track the total amount rotated. In addition, the rotation speed can be controlled through programming.
The stepper motors resembles the dynamixels used in Darwin-OP; therefore, learning to operate the stepper motors allows more possibilities on the types of mechanisms can be built that can be controlled by the LEGO NXT Brick. Furthermore, the ability to track the amount of rotation that the stepper motor has made allow for more accurate determination of the state (position, velocity, acceleration) of any mechanism that is attached to the stepper motor.

Parts List and Sources

  • (1) 9V battery
  • (1) 9V battery snaps
  • (1) 28BYJ-48 5V unipolar stepper motor
  • (1) ULN2003A
  • (4) 3.3k Ohms resistors
  • (1) PCF8574A
  • (1) NXT to breadboard adaptor
  • (1) NXT Brick
  • (various quantities) gauge wires


Here is the demo of the motor turning with the following schematics and coding.




Circuit Schematics

The circuit is based on the extreme NXT site. Below is a picture of the circuit schematics.


D0 controls blue.
D1 controls pink.
D2 controls yellow.
D3 controls orange.



Construction



Step 1

Insert a PCF8574A.


Insert the clock line from PCF8574A to the NXT adaptor.


Insert the data line.


Insert the voltage source to the PCF8574A.


Insert the ground lines, which will also be the ground to the NXT Brick.


Step 2

Insert four IRF510 resistors.


Step 3

Gather an NXT adaptor.


Insert the NXT adaptor.


Step 4

Gather four 100k Ohms resistors.


Connect the resistors to the “Gate” pins of all of the transistors.








Step 5

Connect the source of all transistors to the ground.











Step 6

Insert data lines from the correct output pins from the PCF8574A to the corresponding transistor's “drain” pin.





Step 7

Connect the center line (red) of the stepper motor to a 9V source and the other four lines to the corresponding “drain” pin of the transistors.





Step 8

Connect the battery.






Programming

First, I defined where the input port and the address for the PCF8574 will be.

#define I2Cport S1 // Port number
#define I2CAddr8574 0x70 // I2C address

Then, in the main task, the variables for the function I2CBytes() will be initialized.

byte WriteBuf[2]; 
byte ReadBuf[]; 
int RdCnt = 1; 

Next, since the PCF8574A is connected to the NXT on input port S1; therefore, PCF8574A will be initialized and set up for writing to the PCF8574.

SetSensorLowspeed (I2Cport); // PCF8574A connect to NXT on S1
WriteBuf[1] = 0x00; // i.e. write zeros to port sets up PCF8574A for writing
WriteBuf[0] = I2CAddr8574; // i.e. address is 0x70
I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);

To allow the motor to turn, a sequence of data has to be send to the motor in order for the motor to turn in a certain direction. In this case, the motor will be turning in clockwise direction.
The sequence that the PCF8574A will be sending to allow the transistors to open or close is as follows:

  WriteBuf[1] = 12;  //1100
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10);
  WriteBuf[1] = 9;  //1001
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10);
  WriteBuf[1] = 3;   //0011
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10);
  WriteBuf[1] = 6;   //0110
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10); 

Final Words

Circuit Schematics

Basic: Coding To simplify what I'm doing, I will put it in layman terms. Basically, in order to drive the unipolar stepper motor that we have, we send currents to the stepper motor in a correct sequence in order to turn the stepper motor, say in clockwise direction. This means, to drive the stepper motor in the opposite direction, we reverse the sequence.

Sample Video

steppernxt.1501896324.txt.gz · Last modified: 2017/08/04 18:25 by rebeccacao