Steper direction control help

Until just recently this sketch ran fine. Now I have no direction control;

#include <AccelStepper.h>
#include <IRremote.h>
#define One_button 0xFFA25D // code received from one button
#define Two_button 0xFF629D // code received from two button
#define Three_button 0xFFE21D // code received from four button
#define Stop_button 0xFF02FD //code received from 5 button
// Define sensor pin
const int RECV_PIN = 11; //output pin of IR receiver to pin 11 of arduino
AccelStepper stepper(1, 3, 6); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
IRrecv irrecv(RECV_PIN); //Arduino will take output of IR receiver from pin 11
decode_results output;
void setup()
{
// Serial Monitor @ 9600 baud
Serial.begin(9600);
// Enable the IR Receiver
irrecv.enableIRIn();

}
void loop()
{
if (irrecv.decode(&output))
{
unsigned long value = output.value; // **** change to unsigned long
Serial.println(value, HEX);
switch (value)
{
case One_button:
stepper.setMaxSpeed(1000);
stepper.setSpeed(-1000);
break;
case Two_button:
stepper.setMaxSpeed(1000);
stepper.setSpeed(800);
break;
case Three_button:
stepper.setMaxSpeed(1000);
stepper.setSpeed(6.202119556);
//stepper.setMaxSpeed(1000);
break;
case Stop_button:
stepper.setSpeed(0);
break;
}
irrecv.resume();
}
stepper.runSpeed();
}

Now I get just one direction from my motor, clockwise

It would be best when you post code to use code tags and properly format it so it's more readable. But in this case I suspect that you don't have a software problem but a poor connection to the direction pin on the stepper driver. Usually if there isn't a connection an internal pullup or pulldown will make it default to just one direction. This can be very puzzling!

what did you recently change?

Hi, @mtnclmbr

To add code please click this link;

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

Sorry about that, this looks better, I didn't consciously change anything. The faulty connection makes the most sense. I will explore that possibility. Thanks all!

#include <AccelStepper.h>
#include <IRremote.h>
#define One_button  0xFFA25D // code received from one button
#define Two_button  0xFF629D     // code received from two button
#define Three_button  0xFFE21D    // code received from four button
#define Stop_button 0xFF02FD //code received from 5 button
// Define sensor pin
const int RECV_PIN = 11;               //output pin of IR receiver to pin 11 of arduino
AccelStepper stepper(1, 3, 6); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
IRrecv irrecv(RECV_PIN);  //Arduino will take output of IR receiver from pin 11
decode_results output;
void setup()
{
  // Serial Monitor @ 9600 baud
  Serial.begin(9600);
  // Enable the IR Receiver
  irrecv.enableIRIn();
 
}
void loop()
{
  if (irrecv.decode(&output))
 {
    unsigned long value = output.value; // **** change to unsigned long
    Serial.println(value, HEX);
    switch (value)
    {
      case One_button:
        stepper.setMaxSpeed(-1000);
        stepper.setSpeed(-1000);
        break;
      case Two_button:
        stepper.setMaxSpeed(1000);
        stepper.setSpeed(800);
        break;
      case Three_button:
        stepper.setMaxSpeed(1000);
        stepper.setSpeed(6.202119556);
        break;
      case Stop_button:
        stepper.setMaxSpeed(1000);
        stepper.setSpeed(0);
        break;
    }
    irrecv.resume();
  }
  stepper.runSpeed();
}

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