Go Down

Topic: (HELP) Step motor with Button (Read 520 times) previous topic - next topic

evankjw

   I'd like to control step motor with button

So I made a circuit like this.

I can handle LED, but Step motor doesn't move.

Here is Arduino CODE

#include<Stepper.h>

int ledPin = 5;
int buttonApin = 12;
int buttonBpin = 13;

int motorPin1 = 8;
int motorPin2 = 9;
int motorPin3 = 10;
int motorPin4 = 11;
int delayTime = 1;

Stepper motor(200, motorPin1, motorPin2, motorPin3, motorPin4);

 byte leds = 0;

 
 
void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);
  pinMode(buttonBpin, INPUT_PULLUP);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);

  motor.setSpeed(100);
}
 
void loop()
{
  if (digitalRead(buttonApin) == LOW)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(delayTime);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(delayTime);
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(delayTime);
  }
  if (digitalRead(buttonBpin) == LOW)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
  }
}

What is the problem?

Can you guys please help me?

evankjw

You can download circuit images!!!

Robin2

#2
Jul 28, 2015, 10:29 am Last Edit: Jul 28, 2015, 10:30 am by Robin2
You seem to have a lot of digitalWrite()s which (I presume) are intended to control the motor.

That is what the Stepper library is for. Read the documentation.

  • What stepper driver are you using ? I hope you are not connecting your motor directly to the Arduino - that would probably damage the Arduino.
  • Post a link to the datasheet for your stepper motor.
  • What power supply are you using for the motor (volts and amps)

...R
Stepper Motor Basics
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up