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); }
I think your circuit need diode protection. (clamp diode across the inductive component)
clamp diodes are included in the chip
I do not understand where it would be the diodes? could explain better?
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?
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.
There are ESD protection diodes on the chip that will withstand the back-emf of the motor.
ESD protection diodes are NOT suitable for protecting a circuit from a coil flyback. You need to use flyback diodes on all coils.
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.
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.
GuyCarpenter, How to calculate number of steps please ?
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.
Hi, please potentiometer characteristics?
I used a linear type of 10 Kohms, but any value from 5K to 100K will work.
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
Hi ! I Need this Sketch for arduino Motor Shield r3 ! Can you help me please ?
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.
Ok, thanks. Don’t understand your answer to one of the comments – clamp diodes are included in the chip…?? You you clearify this one?
can i used this code for all types of stepper motor ?
how to change input for control stepping motor from POT to Dc 0-5Vdc? Thanks.
You need stepper motor drivers “drv8834” to drive them with 100uf 16v caps in series. currently building a audi a4 controlling the steppers directly you cant control the steppers with the arduino directly will fry it.