Stepper motor not moving with rc remote

Hi everyone

I'm new to programming and I want to control a stepper motor using rc transmitter. This is the code I modified from but the motor does not turn. Any help would be highly appriciated. These are the products I'm using

motor driver
[arduino uno]
NEMA 34 Stepper Motor
[Detrum 2.4G Gavin-6C 6CH Transmitter ]

#include <Stepper.h>

int ch2 = 0;
int rotationCW = 0;
int rotationCCW = 0;
int location = 1;
const int stepsPerRevolution = 2000;

// initialize the stepper library:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
  pinMode(2, INPUT); //from RC reciever ch2 SC switch on Transmitter
  myStepper.setSpeed(50);
  digitalWrite(8, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(11, LOW);
  Serial.begin(9600);
}


void loop() {
 //get current values of RC receiver
  ch2 = pulseIn(2, HIGH, 25000);

  if (ch2 < 1200 && location == 1)
  {
  rotationCW = (.90 * stepsPerRevolution);
  Serial.println("clockwise");
  myStepper.step(rotationCW);
  location = (2);
  delay(100);
  Serial.println("At Location 1");
  }
else if (ch2 > 1700 && location == 1)
  {
  rotationCCW = (.90 * -stepsPerRevolution);  
  Serial.println("counterclockwise");
  myStepper.step(rotationCW);
  location = (3);
  delay(100);
  Serial.println("At Location 1");
}
  }

Welcome to the forum

Do you see the correct messages printed on the Serial monitor ?

How is the motor powered ?

it show only 'clockwise' and 'At Location 1'.
the motor is powered by the driver (25V).
thank you for fast reply

Try printing the value of rotationCW after you calculate it

How are you wiring the step/dir type stepper to the Arduino using the Stepper library. Please post a schematic. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

The Stepper library is not appropriate for your driver. You should use a library like AccelStepper or the MobaTools stepper library (from among many). Personally, I find the MobaTools library easier to learn. Both are available through the IDE library manager.

I left the ena wires

Sorry, but that is not the way to wire that driver to an Uno. It will not work that way, no way.

There are 2 ways to go. Wire all of the - terminals to ground and each + terminal to an output pin or wire all of the + terminals to Vcc and the - terminals to output pins. I would go with the former. That is shown in Figures 3 and 4 of page 4 of the manual that you linked.

Then to control the stepper you can write your own code. See Robin2's simple stepper code. Or use a library that is written for that type of driver. The Stepper library is not. Like I posted, the AccelStepper library or the MobaTools stepper library are written for that type of driver.

You may be able to leave the enable disconnected and the motor will run, but check the manual.

The stepper basics tutorial may be of interest.

Suggested wiring. Use the pins of your choice.

I did it like this but the problem is that it only turned once and after that doesn't do anything.

Post the code that you used, please.

I used the connection that you gave me.

#include <AccelStepper.h>
#include <Stepper.h>

int ch2 = 0;
int rotationCW = 0;
int rotationCCW = 0;
int location = 1;
const int stepsPerRevolution = 3000;

// initialize the stepper library:
Stepper myStepper(stepsPerRevolution, 9, 10);

void setup() {
  pinMode(2, INPUT); //from RC reciever ch2 SC switch on Transmitter
  myStepper.setSpeed(50);
  digitalWrite(8, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  Serial.begin(9600);
}


void loop() {
 //get current values of RC receiver
  ch2 = pulseIn(2, HIGH, 25000);

  if (ch2 < 1200 && location == 1)
  {
  rotationCW = (.90 * stepsPerRevolution);
  Serial.println("clockwise");
  myStepper.step(rotationCW);
  location = (2);
  delay(100);
  Serial.println("At Location 1");
  }
else if (ch2 > 1700 && location == 1)
  {
  rotationCCW = (.90 * -stepsPerRevolution);  
  Serial.println("counterclockwise");
  myStepper.step(rotationCW);
  location = (3);
  delay(100);
  Serial.println("At Location 1");
}
  }

The schematic that I posted shows step (pulse) to pin 7 and dir to pin 8. Your code has step to pin 9 and dir to pin 10. So how is the driver wired?

That code is mixing Accelstepper and Stepper codes. Still not right.

Put aside the reading the remote for now and focus on getting the stepper to work and understanding how it works. One thing at a time.

Install the MobaTools library using the IDE library manager.

Then load and run this simple test code. Check to make sure that the pins in the code match how you have it wired.

#include <MobaTools.h>

// Adjust pins, steps and time as needed
const byte stepPin = 9;
const byte dirPin  = 10;
const int stepsPerRev = 200;   // Steps per Revolution 

MoToStepper myStepper ( stepsPerRev, STEPDIR );

void setup()
{
   Serial.begin(9600);
   myStepper.attach( stepPin, dirPin );
   myStepper.setSpeed( 600 );  // 60.0 Rev/Min ( if stepsPerRev is set correctly )
   myStepper.setRampLen( 20 );
}

void loop()
{
    myStepper.rotate(1);
    Serial.println("clockwise");
    delay(2000);
    myStepper.rotate(-1);
     Serial.println("counter clockwise");
    delay(2000);
}

The motor should spin one way for 2 seconds then reverse for 2 seconds and so on. Does it do that?

No it doesn't, at this point I'm not sure if the problem is with the motor or the driver

I tested the code on my setup with an Uno, NEMA17 stepper and DRV8825 driver, so I know that the code works.

What is your power supply?

What is the coil current limit on the stepper driver set to?

Can you post photos showing your setup and wiring, please?

This code works good even though it is vibrating, the problem starts when I put angles. I'm not sure if its the way I add angles to this code or maybe the stepper can't turn to an angle when using this transmitter.

#include <Stepper.h>
int ch2 = 0;


const int stepsPerRevolution = 200;

// initialize the stepper library:
Stepper myStepper(stepsPerRevolution, 9, 10);

void setup() {
  pinMode(2, INPUT); //from RC reciever ch2 SC switch on Transmitter
  myStepper.setSpeed(600);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  Serial.begin(9600);
}


void loop() {
 //get current values of RC receiver
  ch2 = pulseIn(2, HIGH, 25000);

  if (ch2 < 1200)
  {
  Serial.println("clockwise");
  myStepper.step(100);
  }
else if (ch2 > 1700)
  {
  Serial.println("counterclockwise");
  myStepper.step(-100);
}
  }

I give up.

Thank you bro, god bless you

I will try to explain why the Stepper library will not work. Here is the output from the Arduino to the driver from the Stepper library turning the stepper. Note that there are nice step pulses, but the dir output is also pulsed. Each time that that dir pin changes state, the stepper motor reverses. So it is just oscillating back and forth. Thus the vibrating.

image

Now here is the output from the AccelStepper library (MobaTools would be much the same). This is set up to output 10 steps pulses, reverse the motor and 10 more steps. See how the dir remains in one state while the motor runs in that direction? That is what the step/dir driver, like yours, wants to see.

image

Hi,
Can you please post some images of your project?
So we can see your component layout.

Do you have a DMM?

Thanks... Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.