Hi all, I'm trying to drive this small 6V DC stepper motor with a magnetic encoder and a motor driver through Arduino. However, it seems like the motor is just vibrating and not turning at all, I can see the end shaft of the motor is trying to move but it just vibrates. I have attached the wiring (excuse the hand-drawn diagrams...) configurations that I have tried.
The encoder is soldered onto the motor and the encoder plugs into the motor driver, then that goes to Arduino. I have tried to power the motor/driver by using the 5V pin on the Arduino and I have tried to power it with 9V through a DC power supply. Doesn't seem like it made much of a change.
The code I'm using is just the example code for stepper motor (one revolution) in the Arduino library. I have played around with the rpm, the steps per revolution, and the delay but nothing worked. Any help would be much appreciated. Thanks in advance.
That is not a stepper motor. It is just a DC motor.
You need to post your program.
I don't think the encoder outputs should be connected to the driver - I think they should go directly to the Arduino - probably to pins 2 and 3 on an Uno. And IN1 and In2 on the driver should come from the Arduino PWM pins,
Ok thank you all for the reply. You are right, this is just a DC motor, not a stepper motor. Now I have a new question, so I have connected one of the motor pins (M1) to pin 2 on the Arduino M2 to GND. IN1 and IN2 to pin 8&9. However, the motor is spinning really slow. Which I plug M1 directly to the 5V pin, it can spin really fast. Not sure what to do here, the attached is my code. Thanks for your help.
const int pwm = 2 ; //initializing pin 2 as pwm
const int in_1 = 8 ;
const int in_2 = 9 ;
//For providing logic to L298 IC to choose the direction of the DC motor
void setup() {
pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output
pinMode(in_1,OUTPUT) ; //Logic pins are also set as output
pinMode(in_2,OUTPUT) ;
}
void loop() {
//For Clock wise motion , in_1 = High , in_2 = Low
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,LOW) ;
analogWrite(pwm,255) ;
/* setting pwm of the motor to 255 we can change the speed of rotation
by changing pwm input but we are only using arduino so we are using highest
value to driver the motor */
//Clockwise for 3 secs
delay(3000) ;
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
//For Anti Clock-wise motion - IN_1 = LOW , IN_2 = HIGH
digitalWrite(in_1,LOW) ;
digitalWrite(in_2,HIGH) ;
delay(3000) ;
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
}
I did look at the diagrams on Pololu for the motor and the encoder, but the motor driver that I bought does not have a datasheet, unfortunately. Also the M1 and M2 pins are the positive and negative terminals are what powers the motor, wouldn't that be too low of a voltage/current for a motor? The In1 and In2 pins are what controls the directions of the motor right? That's how I was understanding it?
electricboogaloo777:
but the motor driver that I bought does not have a datasheet,
Pololu also sells a board with the DRV8833 driver (I have some of them) and they have lots of info about them.
Also the M1 and M2 pins are the positive and negative terminals are what powers the motor,
Sorry, I was getting confused between pins on the motor driver and pins on the encoder socket.
The M1 and M2 pins are what deliver power to the motor - the power will come from the driver's pins Out1 and Out2. And the Arduino PWM pins should connect to the IN1 and IN2 pins on the driver.