Table of Contents

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

Author: Xinke (Rebecca) Cao
Email: caox1@unlv.nevada.edu
Date: Last modified on 08/04/2017
Keywords: unipolar stepper motor, LEGO NXT, transistors, IRF510

Motivation and Audience

This is a continuation of the first option, but this tutorial is specifically for the audiences who doesn't have the access to ULN2003A Darlington transistor array.
In this tutorial, the focus will be on using the IRF510 N-channel MOSFET to control the stepper motor, where the IRF510 acts as a switch to sending the signal into the stepper motor for the motor to turn.



Parts List and Sources

Here is the demo of the motor turning with the following schematics and coding.
All the codes can be found here, titled “Stepper_IRF510_Basic.nxc”.



Circuit Schematics

Below is a picture of the circuit schematics.
D7 controls yellow.
D6 controls orange.
D1 controls pink.
D0 controls blue.



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] = 192;  //1100 0000
I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
Wait(10);

WriteBuf[1] = 130;  //1000 0010
I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
Wait(10);

WriteBuf[1] = 3;   //0000 0011
I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
Wait(10);

WriteBuf[1] = 65;   //0100 0001
I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
Wait(10);





Final Words

Comparing version one and version two of the stepper motor control, the only difference is the circuit diagram, which resulted in different numbers sent out of the PCF8574A from the LEGO Brick.
If you have any questions, please contact me at caox1@unlv.nevada.edu.