Electrical – 12V Stepper Motor not working – vibrates but doesnt spin

codedcmotorraspberry pistepper motor

I'm working on a project and unfortunately my DC motor is not working. I wired it like this, am using a brand-new motor (SP BN2A in this document, I scavenged it from a bidet I had at home), powering the whole system with a DC power supply so I can control the voltage exactly, using Raspberry Pi as the controller and using the following code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

enable_pin = 5
coil_A_1_pin = 26
coil_A_2_pin = 19
coil_B_1_pin = 6
coil_B_2_pin = 13

GPIO.setup(enable_pin, GPIO.OUT)
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)

GPIO.output(enable_pin, 1)

def forward(delay, steps):  
  for i in range(0, steps):
    setStep(1, 0, 1, 0)
    time.sleep(delay)
    setStep(0, 1, 1, 0)
    time.sleep(delay)
    setStep(0, 1, 0, 1)
    time.sleep(delay)
    setStep(1, 0, 0, 1)
    time.sleep(delay)

def backwards(delay, steps):  
  for i in range(0, steps):
    setStep(1, 0, 0, 1)
    time.sleep(delay)
    setStep(0, 1, 0, 1)
    time.sleep(delay)
    setStep(0, 1, 1, 0)
    time.sleep(delay)
    setStep(1, 0, 1, 0)
    time.sleep(delay)


def setStep(w1, w2, w3, w4):
  GPIO.output(coil_A_1_pin, w1)
  GPIO.output(coil_A_2_pin, w2)
  GPIO.output(coil_B_1_pin, w3)
  GPIO.output(coil_B_2_pin, w4)

while True:
  delay = raw_input("Delay between steps (milliseconds)?")
  steps = raw_input("How many steps forward? ")
  forward(int(delay) / 1000.0, int(steps))
  steps = raw_input("How many steps backwards? ")
  backwards(int(delay) / 1000.0, int(steps))

The motor vibrates and heats up when I power the system and run the code, but doesn't spin. What part of my system is wrong? Is it the hardware of the motor, the wiring, the code, the power supply, or something else?

Thanks, all help is appreciated.

Best Answer

Finally figured it out! I substituted the unipolar motor for a bipolar one, and the whole system worked perfectly as is! To use the unipolar motor, it is necessary to use a motor-driving IC specifically for the unipolar motor, and the L293D does not accomplish the task.