My six wire unipolar motor vibrates, but does not respond, not matter which sketch is uploaded. I have switched wires and played with the sketch pin numbers in every way imaginable. Is this a software problem? I am using a 5v mini pro board powered by an 8 amp, 7 volt supply.
#include <Stepper.h>
//stepper
#define STEPS1 200
#define STOP 0
Stepper stepper1(STEPS1, 6,7,8,9);//bipolar
int sonarPin = A0;
int sonarVal =0;
void setup()
{
stepper1.setSpeed(30);
Serial.begin(9600);
pinMode(sonarPin,INPUT);
}
void loop()
{
sonarVal = analogRead (sonarPin);
Serial.println(sonarVal);
{
if (sonarVal < 900)
{
stepper1.step(STOP); ////not responding to analog input
}
if (sonarVal > 900)
{
stepper1.step(300);
stepper1.step(-300);
}
}
}
You don't tell us what motor, what voltage or current, what the winding resistance is, nor
how you have wired up your circuit. We have no useful information yet...
However the big clue seems to be that you don't mention a motor driver - are you trying to
drive a stepper motor direct from Arduino pins? If so you may already have fried your Arduino,
there is no way the Arduino can power a motor like this by itself.
Two reasons: Arduino absolute maximum output current 40mA. Typical motor current: 300 to 2000mA
Also motors are inductive loads - inductive loads destroy semiconductors unless flyback diodes are
present in the right places to prevent inductive high-voltage spikes.
Also if you are trying to use the 5V rail from the Mini Pro as power source you cannot draw large current
since the on-board regular is tiny. 100 to 200mA is probably the limit.
In general powering motors from a separate supply to its control electronics is a wise choice.