Home > Driving Motors, Exploring Ideas > Arduino Driving a Micro Stepper Motor

Arduino Driving a Micro Stepper Motor

Small stepper motors are used to control pointer gauges in motor vehicles.

These motors are  small and can be driven directly by the Arduino due to low operation current (15-25mA per coil). They have  gearboxes to increase torque and reduce the mechanical step.

You can find them in Amazon searching for: stepper motor gauge

See it working in Youtube…

Here is the code:

/*------------------------------------------------------
Gauge_Pot01
Arduining.com 10 July 2011
Direct driving of Miniature Stepper Motor used as an indicator
drive for dashboard instrumentation.
Hardware:
-Arduino UNO.
-Potentiometer.
-Stepper Motor VID29-05P (Can be directly driven by MCU):
    -Low current consumption: <20mA 
    -Rotation Angle:Max 315°
    -0.5°/full step    
    -Coil resistance: 280 +/- 20Ω                           
 -----------------------------------------------------*/
#include <Stepper.h>
#define  STEPS  720    // steps per revolution (limited to 315°)
#define  COIL1  8
#define  COIL2  9
#define  COIL3  10
#define  COIL4  11

#define PotIn  0

// create an instance of the stepper class:
Stepper stepper(STEPS, COIL1, COIL2, COIL3, COIL4);

void setup(){
  stepper.setSpeed(30);    // set the motor speed to 30 RPM (360 PPS aprox.).
  stepper.step(630);       //Reset Position(630 steps counter-clockwise). 
//  Serial.begin(9600);    //for debuging.
}
int pos=0;                 //Position in steps(0-630)= (0°-315°)

void loop(){
  int val = analogRead(PotIn);   //get the potentiometer value (range 0-1023)
  val= map(val,0,1023,0,630);    // map pot range in the stepper range.

  if(abs(val - pos)> 2){         //if diference is greater than 2 steps.
      if((val - pos)> 0){
          stepper.step(-1);      // move one step to the left.
          pos++;
          }
      if((val - pos)< 0){
          stepper.step(1);       // move one step to the right.
          pos--;
          }
      }
//  Serial.println(pos);      //for debuging...
//  Serial.println(val);
//  delay(100);
}
Advertisements
  1. Flavio
    October 23, 2012 at 9:30 PM

    I think your circuit need diode protection. (clamp diode across the inductive component)

  2. bernard
    November 16, 2012 at 2:14 PM

    clamp diodes are included in the chip

  3. Rhon
    November 24, 2012 at 4:03 PM

    I do not understand where it would be the diodes? could explain better?

    • Marcel
      September 6, 2014 at 6:07 PM

      I’m thinking the same as Flavio and Rhon… shouldn’t there be diodes between the motor coils and the Arduino to stop the back-emf from frying the Arduino?

      Bernard — what chip? The Arduino doesn’t have diodes on the IO pins as far as I know and I don’t see another chip (like an L293D) in the circuit.

      Ardunaut — could you clarify for us please?

    • September 6, 2014 at 7:18 PM

      I agree with Flavio and Marcel about the use of protecting diodes.
      A professional approach will be to connect diodes to protect microcontroller from inductive kickback.
      Two diodes must be attached in each pin (1N4001 rectifier diodes can be used).
      Here I found a breadboard with the protecting diodes:
      https://www.tindie.com/products/TheRengineer/analog-gauge-stepper-breakout-board/

      In several experiments the bare motor was used with Arduino UNO, Arduino NANO and the Trinket from Adafruit (ATMEGA328 and ATTINY85 microcontrollers) with good results, not recommended for a commercial application.

    • Mikeg
      August 20, 2015 at 4:43 PM

      There are ESD protection diodes on the chip that will withstand the back-emf of the motor.

    • Gengis
      March 22, 2017 at 5:33 PM

      I think “protection diodes are on the chip” refers to to the fact that in ATmega328/P chips “All I/O pins have protection diodes to both VCC and Ground”; this is a quotation from the Atmel’s ATmega328/P complete datasheet available online at http://www.atmel.com/Images/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf.

  4. November 26, 2012 at 3:34 AM

    Your step calculations for number of steps seem to be based on 1/2 degree per step, but the VID29 data sheet (http://guy.carpenter.id.au/gaugette/resources/vid/20091026113525_VID29_manual_EN-080606.pdf) shows 1/3 of a degree per step. Seems to me full-scale should be 945 steps rather than 630.

    • Gérald Charbonier
      August 6, 2015 at 6:21 PM

      GuyCarpenter, How to calculate number of steps please ?

  5. December 17, 2012 at 11:55 PM

    I need more thorough explanation for these, ah still not absorbing in my mind. But thanks anyway for the step-by-step video process, it’s make it more easier.

  6. Claudio
    March 23, 2013 at 5:56 PM

    Hi, please potentiometer characteristics?

    • March 23, 2013 at 7:57 PM

      I used a linear type of 10 Kohms, but any value from 5K to 100K will work.

      • Neil
        December 29, 2015 at 9:05 AM

        Hi, I am very new to this… I cannot find much information on the limits of what can be used as analogue inputs, I have just ordered my fist Arduino UNO, I have an application that i would like to monitor a resistance between 3.5 and 70 ohms, do you know if this is possible ?

        Many thanks

  7. Michael kemper
    May 6, 2013 at 4:22 PM

    Hi ! I Need this Sketch for arduino Motor Shield r3 ! Can you help me please ?

  8. June 29, 2013 at 1:32 AM

    A wonderful guide to start working with Arduino Uno. As you can see I add a link in my article http://www.intorobotics.com/arduino-uno-setup-and-programming-tutorials/ where is an impressive collection of guides and tutorials to start working with Uno.

  9. December 7, 2015 at 10:34 AM

    Ok, thanks. Don’t understand your answer to one of the comments – clamp diodes are included in the chip…?? You you clearify this one?

  10. jasim khan
    March 7, 2016 at 1:28 PM

    can i used this code for all types of stepper motor ?

  1. April 25, 2012 at 12:33 PM
  2. June 28, 2013 at 1:19 PM
  3. June 7, 2014 at 10:08 AM
  4. June 7, 2014 at 10:12 AM
  5. March 3, 2016 at 2:01 AM

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: