I have a problem, I connected the M42SP-6NKA MITSOMI stepper motor. I connected it to the arduino via the L9110 motor driver on pins 8, 9, 10, 11. I connected buttons to pins 2 and 4. the code should work when one button is pressed the motor rotates 180° clockwise, and when the second button is pressed counterclockwise 180° counterclockwise. I took the already made code with the Arduino IDE from the example and added 2 buttons to it. When I test it, I press the button, the engine does not spin, but there is a buzzing sound in the engine while the button is pressed. The stepper and the driver are powered by 12v, as it says is allowed in the datasheet.
The code I tried
const int stepsPerRevolution = 48; // Change this according to the number of steps per revolution of your motor
// Definition of button pins
const int buttonPinClockwise = 2;
const int buttonPinCounterClockwise = 3;
// Initialize Stepper object
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// Set button pins as inputs with pull-up resistors
pinMode(buttonPinClockwise, INPUT_PULLUP);
pinMode(buttonPinCounterClockwise, INPUT_PULLUP);
// Initialize serial communication
Serial.begin(9600);
// Set motor speed
myStepper.setSpeed(60);
}
void loop() {
// Read button states
int clockwiseButtonState = digitalRead(buttonPinClockwise);
int counterClockwiseButtonState = digitalRead(buttonPinCounterClockwise);
// If the clockwise button is pressed, rotate the motor clockwise
if (clockwiseButtonState == LOW) {
Serial.println("Rotating clockwise");
myStepper.step(stepsPerRevolution);
delay(500); // Optional delay
}
// If the counter-clockwise button is pressed, rotate the motor counter-clockwise
if (counterClockwiseButtonState == LOW) {
Serial.println("Rotating counter-clockwise");
myStepper.step(-stepsPerRevolution);
delay(500); // Optional delay
}
}
```
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 48; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
The datasheet claims the peak phase current is 400mA and resistance is 5Ω, if you put 12V across 5Ω, the current would be 2400mA. 400mA * 5Ω = 2V.
You probably need a "chopper" driver with adjustable current control like a DRV8825. https://www.pololu.com/product/2133
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
Yes, I connected gnd from arduino and gnd from l9110.
I think it's not a connection problem but a code problem. The code that does not use buttons works perfectly fine, but the one with buttons does not.
Why does the stepper not work on 12 volts but only on 9 volts? In the data sheet, both the stepper and the driver say that they can work on 12 volts. M42SP-6NK_MITSUMI.pdf (105.9 KB) L9110.PDF (319.4 KB)