User Tools

Site Tools


steppernxt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
steppernxt [2017/08/04 17:59] rebeccacaosteppernxt [2017/08/15 20:11] (current) – [Circuit Schematics] rebeccacao
Line 1: Line 1:
 +====== How To Control an Unipolar Stepper Motor with LEGO NXT Using ULN2003A ======
 +
 +**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.  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. 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 [[https://youtu.be/ueQvVYQ1Udo |demo]] of the motor turning with the following schematics and coding.
 +\\
 +All the codes can be found [[https://github.com/XKRC/NXT_Stepper_Motor|here]], titled "Stepper_ULN2003A_Basic.nxc".
  
- +\\ 
- +\\ 
- +\\ 
-**Circuit Schematics**+==== Circuit Schematics ====
 // //
-The circuit is based on http://www.extremenxt.com/stepper.html+The circuit is based on [[http://www.extremenxt.com/stepper.html| the extreme NXT site]].
 // //
 +Below is a picture of the circuit schematics.
  
-**BasicCoding** +{{ :xinke:circuit_ver_1.png?600 |}} 
-To simplify what I'm doing, I will put it in layman termsBasically, in order to drive the unipolar stepper motor that we have, we send currents to the stepper motor in correct sequence in order to turn the stepper motor, say in clockwise directionThis means, to drive the stepper motor in the opposite direction, we reverse the sequence.  +D0 controls blue. 
-  // FILEtestingStepper.nxc+\\ 
 +D1 controls pink. 
 +\\ 
 +D2 controls yellow. 
 +\\ 
 +D3 controls orange. 
 +\\ 
 +The integrated circuit that is connected to the PCF8574A is the ULN2003A. The ULN2003A is an array of seven Darlington transistors that amplifies current from the PCF8574A and outputs the voltage supplied to its common port to drive the stepper motor. This is similar to how the IRF510 amplifies the current and acts as switch to allow specific wires on the stepper motor to obtain enough voltage and currentHoweverwhen you input a LOW signal to the ULN2003A, it will output a HIGH signal. Therefore, in the code, we need to adjust the bit values output by the PCF8574A to account for this change
 +\\ 
 +\\ 
 +\\ 
 +==== Construction ==== 
 +**Step 1** 
 +\\ 
 +\\ 
 +Insert a PCF8574A. 
 +\\ 
 +{{:xinke:img_7496.jpg?300|}} 
 +\\ 
 +\\ 
 +Insert the clock line from PCF8574A to the NXT adaptor. 
 +\\ 
 +{{:xinke:img_7495.jpg?300|}} 
 +\\ 
 +\\ 
 +Insert the data line. 
 +\\ 
 +{{:xinke:img_7494.jpg?300|}} 
 +\\ 
 +\\ 
 +Insert the voltage source to the PCF8574A. 
 +\\ 
 +{{:xinke:img_7493.jpg?300|}} 
 +\\ 
 +\\ 
 +Insert the ground lines to the NXT Brick. 
 +\\ 
 +{{:xinke:img_7492.jpg?300|}} 
 +\\ 
 +\\ 
 +Ground the pins on PCF8574A. 
 +\\ 
 +{{:xinke:img_7491.jpg?300|}} 
 +\\ 
 +\\ 
 +**Step 2** 
 +\\ 
 +\\ 
 +Insert a ULN2003A. 
 +\\ 
 +{{:xinke:img_7490.jpg?300|}} 
 +\\ 
 +\\ 
 +Add the ground to the ULN2003A and the 9V source to the ULN2003A. 
 +\\ 
 +{{:xinke:img_7489.jpg?300|}} 
 +\\ 
 +\\ 
 +\\ 
 +{{:xinke:img_7488.jpg?300|}} 
 +\\ 
 +\\ 
 +Add the data lines from the PCF8574A to the ULN2003A's input ports. 
 +\\ 
 +{{:xinke:img_7487.jpg?300|}} 
 +\\ 
 +\\ 
 +Add resistors to the digital output pins of PCF8574A that are in use to provide enough currents. 
 +\\ 
 +{{:xinke:img_7486.jpg?300|}} 
 +\\ 
 +\\ 
 +\\ 
 +{{:xinke:img_7485.jpg?300|}} 
 +\\ 
 +\\ 
 +**Step 3** 
 +\\ 
 +\\ 
 +Insert the NXT adaptor. 
 +\\ 
 +{{:xinke:img_7483.jpg?300|}} 
 +\\ 
 +\\ 
 +\\ 
 +{{:xinke:img_7484.jpg?300|}} 
 +\\ 
 +\\ 
 +**Step 4** 
 +\\ 
 +\\ 
 +Insert the stepper motor to the output pins of the ULN2003A. 
 +\\ 
 +{{:xinke:img_7482.jpg?300|}} 
 +\\ 
 +\\ 
 +Connect the red wire from the stepper motor to a 9V voltage source. 
 +\\ 
 +{{:xinke:img_7481.jpg?300|}} 
 +\\ 
 +\\ 
 +\\ 
 +{{:xinke:img_7480.jpg?300|}} 
 +\\ 
 +\\ 
 +**Step 6** 
 +\\ 
 +Connect the battery. 
 +\\ 
 +{{:xinke:img_74800.jpg?300|}} 
 +\\ 
 +\\ 
 +\\ 
 +\\ 
 +\\ 
 +\\ 
 +==== Programming ==== 
 +First, I defined where the input port and the address for the PCF8574 will be.
   #define I2Cport S1 // Port number   #define I2Cport S1 // Port number
-  #define I2CAddr8574 0x70 // I2C address when PCF8574A A2-A1-A0 are set to 0-0-0 +  #define I2CAddr8574 0x70 // I2C address 
-  task main() { + 
-   // array variables (since NXC's I2C functions take array variables +Then, in the main task, the variables for the function I2CBytes() will be initialized. 
-   byte WriteBuf[2]; // data written to PCF8574A.  Declares a two one-byte variables +  byte WriteBuf[2];  
-   byte ReadBuf[]; // data received from PCF8574A.  We won't be reading any data but we need this for I2CBytes +  byte ReadBuf[];  
-   int RdCnt = 1; +  int RdCnt = 1;  
-   bool rightArrowButtonPushed+Next, since the PCF8574A is connected to the NXT on input port S1therefore, PCF8574A will be initialized and set up for writing to the PCF8574. 
-   SetSensorLowspeed (I2Cport);  +  SetSensorLowspeed (I2Cport); // PCF8574A connect to NXT on S1 
-   WriteBuf[1] = 0x00;  +  WriteBuf[1] = 0x00; // i.e. write zeros to port sets up PCF8574A for writing 
-   WriteBuf[0] = I2CAddr8574; +  WriteBuf[0] = I2CAddr8574; // i.e. address is 0x70 
-   I2CBytes(S1, WriteBuf, RdCnt, ReadBuf); +  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf); 
-   TextOut (0LCD_LINE1"Right Btn starts"); + 
-   do { +To allow the motor to turna sequence of data has to be send to the motor in order for the motor to turn in a certain direction. In this casethe motor will be turning in clockwise direction. 
-      rightArrowButtonPushed = ButtonPressed(BTNRIGHT, FALSE); +\\ 
-   } while(!rightArrowButtonPushed); +The sequence that the PCF8574A will be sending to allow the transistors to open or close is as follows:
-   ClearScreen(); +
-   TextOut (0, LCD_LINE1, "Looping"); +
-   for (int i=0; i<=300; i++) {+
     WriteBuf[1] = 12;  //1100     WriteBuf[1] = 12;  //1100
     I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);     I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
Line 45: Line 189:
     I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);     I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
     Wait(10);      Wait(10); 
-   } //end for loop 
-  TextOut(0, LCD_LINE5, "Finished!"); 
-  PlaySound(SOUND_DOUBLE_BEEP); 
-  } // end main 
  
-//+\\ 
 +To reverse the direction that the stepper motor is turning, the sequence can be reversed.  
 +\\ 
 +\\ 
 +\\ 
 +==== Final Words ==== 
 +The purpose of this tutorial is to allow the users of the NXT Brick learn how to control a stepper motor through an NXT interface. 
 +\\ 
 +Building from this tutorial, one can control the speed of the stepper motor and the direction of the stepper motor by altering the wait time between each signal and the sequence of the signal. 
 +\\ 
 +If you have any questions, please email me at [email protected]
 + 
 + 
 + 
 + 
  
-**Sample Video** 
-// 
  
-// 
-Here is the [[https://youtu.be/VVnshFiYg2U |demo]] of the motor turning with the following schematics and coding. 
  
  
  
  
steppernxt.1501894755.txt.gz · Last modified: 2017/08/04 17:59 by rebeccacao