Home > Driving Motors, Launchpad and Energia > LaunchPad Energia and Stepper Motor

LaunchPad Energia and Stepper Motor

Using the MSP430 LaunchpPad and Energia to control a stepper motor.
For this project a former Arduino’s project was used.


First thing was to make the stepper and driving board as a single assembly, this make it easier to experiment with it in the future.


Some wiring to connect the Launchpad (3.6 Volts) was done.
The stepper motor can be powered from the USB Voltage (5 volts at TP1) or
an external power supply. In this case I used both for testing purposes, the USB power and a Power adapter.



The connections are shown as an image to make it easier for all.


And now the code:

Arduining.com 13 APRIL 2013

A stepper motor follows a potentiometer on analog input 5.
A software low-pass filter is used to reduce the noise in the analog reading.
After 3 seconds of inactivity the motor coils are turned OFF to save energy.
The RED_LED is used to signal when the stepper is powered.

LaunchPad with MSP430G2553.
Driver: ULN2003A
Stepper Motor:  28BYJ48, 5VDC, step pangle 5.625 °
                Gear reduction 64:1
                No-load starting frequency:> = 500PPS (4 rpm)
                Coil resistance 60 Ohms.               

#include <Stepper.h>

// change this to the number of steps on your motor
#define  STEPSREV    4096    // 64(fullsteps) * 64 (reduction ratio)
#define  COIL1       14
#define  COIL2       12
#define  COIL3       13
#define  COIL4       11
#define  POT         A5
#define  ENER        RED_LED
#define  TIMEOUT     3000    //Turns off after 3 secs of inactivity.

// create an instance of the stepper class, specifying
// the number of steps per revolution and pins atached to motor coils.
Stepper myStepper(STEPSREV, COIL1, COIL2, COIL3, COIL4);
int PotVal;
int LastPotVal= 0 ;          // To implement a software Low-Pass-Filter
int pos = 0;              // stepper position(0-4096)->(0-360°)
unsigned long stamp = 0;  // last move time stamped.

void setup()
  myStepper.setSpeed(4);  // set the motor speed to 4 RPM
  pinMode(ENER, OUTPUT);  // status led (coils energized).
//  Serial.begin(9600);   //for debuging.

void loop(){

  PotVal = analogRead(POT);       // Potentiometer value range 0-1023

  PotVal= map(PotVal,0,1023,0,2047);      // Map pot range in the stepper range.
  PotVal= PotVal * 0.1 + LastPotVal * 0.9 ;  // Filtering to reduce noise.
  LastPotVal= PotVal;

//  Serial.print(Val);              // For debuging.
//  Serial.print("   ");            //    "
//  Serial.println(pos);            //    "
//  delay(500);                     //    "  

  if(abs(PotVal - pos)> 4){              //if diference is greater than 4 steps.
      if((PotVal - pos)> 0){
          digitalWrite(ENER, HIGH);   //Motor energized.     
          myStepper.step(1);           // move one step to the right.
      if((PotVal - pos)< 0){
          digitalWrite(ENER, HIGH);   //Motor energized.
          myStepper.step(-1);            // move one step to the left.
      stamp = millis();               // stamp actual time.
  else {      
      if((millis() - stamp) > TIMEOUT){   //Turn Off coils after TIMEOUT.
          digitalWrite(COIL1, LOW);
          digitalWrite(COIL2, LOW);
          digitalWrite(COIL3, LOW);
          digitalWrite(COIL4, LOW);
          digitalWrite(ENER, LOW);    //Motor de-energized.


See in YouTube this experiment:

  1. Trygve
    July 31, 2013 at 5:12 PM

    Thanks for posting this, it is good to find a project with such detail and clarity. I have not yet been able to make it run yet. I am pretty sure that I am doing everything correctly. I have selected the correct board in Energia but no luck yet. Any suggestions? Thanks again for a good project.

  2. Azzy
    January 19, 2014 at 6:41 AM

    than you for posting this , it is very useful for me. but can you please provide me the schematic for unl2003. and i have to use CCS for programming so can you suggest any thing cos i am totally new to embedded systems

  3. Igor
    November 21, 2014 at 4:53 PM

    Dear Friends. Thank for shring.

    Is it possible to creare such project but with reaction stepper motor like servo?

    What parts are needed?

    Thank you!

  4. müslüm
    February 14, 2015 at 5:09 PM

    How do I, tiva c series mux 74HC595 60 out relay.

  5. March 11, 2015 at 11:43 AM

    U have the same code using arduino ? Ty dude

  6. Imi
    June 5, 2015 at 8:02 AM

    That is really good!
    I would like to do too this project. Can you send me the CCS project file?
    Thank you very much!

    • June 5, 2015 at 1:35 PM

      Sorry, Energia (Arduino-like environment) was used instead of CCS.

      • Imi
        June 6, 2015 at 5:08 AM

        Thank you for your answer! It was too big support for me.

  7. umz
    July 30, 2015 at 2:01 PM

    How would i do this with an arduino uno?

  8. Veerashetty
    March 30, 2016 at 7:22 AM

    I need this kit ….where it will available can u provide me the address..

  9. bhargav
    April 12, 2016 at 11:25 AM

    motor is rotating only in one direction after rotating potentiometer.

  10. Krzysztof
    May 4, 2016 at 1:55 PM

    Hallo, what I have to change in this code to use it with arduino uno ?

  11. Krzysztof
    May 5, 2016 at 2:51 AM

    Hallo, What I have to change in this code to use it with Arduino ? Thank You very much in advance !!

  12. December 17, 2016 at 3:15 AM

    Dear sir.
    assume you set a point and lost the power. after that when power On what happens to the set point.

    • December 17, 2016 at 3:18 AM

      OK. find it.
      Set to zero.
      int pos = 0; // stepper position(0-4096)->(0-360°)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: