Vehicle lane assist with stepper motor

I need help with my code, I am using a Unipolar 8 lead stepper motor,Arduino Uno and a DM860H motor drive. My aim is to crate a code that will turn the motor when I receive a signal from the truck's camera system. The signal must tell me how much the truck is off the lane of the road and I have to convert that into steps the motor will turn. The problem is the motor is not turning. Also need advice on how should connect between the arduino and motor driver . Can you please kindly assist on what I should do. Below is the code I used

#include <Stepper.h>
int LeftSpeaker;
int RightSPeaker;
int LaneSensorInput;
int LaneDifference;
int WheelAngle;
int NWheelAngle;
int WheelAngleChange;
int Speed;
int StepsPerRevolution ;
int Motorangle;

const int stepsPerRevolution = 500;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(StepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 100 rpm:
  myStepper.setSpeed(100);
  // initialize the serial port:
  Serial.begin(115200);
}

void loop() {
    // put your main code here, to run repeatedly:
  
  // based on the truck speed you can attain the blue line.

  //based on the steering angle you can attain the orange line.

  // read the input on analog pin 0:
  int RightSpeaker = analogRead(A0);

    // read the input on analog pin 4:
  int LeftSpeaker = analogRead(A4);


   //read the pwm on AO
   analogWrite(3, RightSpeaker/4);

   //read the pwm on A1
   analogWrite(5, LeftSpeaker/4);

  Serial.println("RS,LS:");
  
  Serial.print(RightSpeaker);
    Serial.print(",");
  Serial.print(LeftSpeaker);
  
  LaneDifference = LeftSpeaker - RightSpeaker; //calculate the orange line
  LaneDifference = LaneDifference * 1.5/1023; //convert to meters

if (LaneDifference > 0)
{
  LaneSensorInput == 1; // too far left
if (Speed >= 55 && Speed <65){
    WheelAngleChange = tan (8/LaneDifference);
  NWheelAngle=WheelAngle - WheelAngleChange; // new steering angle 
  }
  if (Speed >= 65 && Speed < 75){
    WheelAngleChange = tan (16/LaneDifference);
  NWheelAngle = WheelAngle -WheelAngleChange; //new steering angle
  }

if (Speed >= 75 && Speed <=85){
    WheelAngleChange = tan (18/LaneDifference);
  NWheelAngle = WheelAngle - WheelAngleChange; //new steering angle
  }
Motorangle = NWheelAngle * 12/60 ;
StepsPerRevolution = Motorangle * 200/360;
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(StepsPerRevolution);
  delay(100);
}
if (LaneDifference < 0) {

  LaneSensorInput == 0; // too far right
  
   if (Speed >= 55 && Speed <65){
    WheelAngleChange = tan (8/LaneDifference);
  NWheelAngle=WheelAngle + WheelAngleChange; // new steering angle 
  }
  
  if (Speed >= 65 && Speed < 75){
    WheelAngleChange = tan (16/LaneDifference);
  NWheelAngle = WheelAngle + WheelAngleChange; // new steering angle
  }

  if (Speed >= 75 && Speed <=85){
    WheelAngleChange = tan (18/LaneDifference);
  NWheelAngle = WheelAngle + WheelAngleChange; // new steering angle
  }
Motorangle = NWheelAngle * 12/60;

StepsPerRevolution = Motorangle * 200/360;

 // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(StepsPerRevolution);
  delay(100);
}
}

Please enclose the whole code inside code tags (edit the post, select all the code lines, and press the "</>" button) to make it more readable for us and easier to copy. Thanks.

I see that you tried to post in code tags, thank you for the consideration of readers. However, it didn't work. So please go back and edit it to make the code tags work.

Also, you haven't provided nearly enough information about your hardware, to allow readers to answer your request. For example, you ask how to connect the motor and its driver, but you didn't provide any information about either one.

We don't even know what your "truck" is. Is it a model, or a real truck? Autonomous, or under manual control? You have a lot to explain.

Did you write this code? What is your software and hardware experience level?

Because of the potential liability I will not answer your question. A mistook could kill somebody.

I think it’s ok, the motor slaps a fish across the driver’s face to get their attention,

2 Likes

I think you mean a bipolar stepper? If you're asking how to connect the uno to the driver it's not surprising the motor won't turn! Look at the driver documentation. Is this a student project? If so then ask your teacher first.

Post a data sheet for that motor.

The Stepper library is the wrong library for step/dir type of stepper drivers like the DM860H driver. The Stepper library is written for drivers like the ULN3003 (unipolar) or the L29x drivers (bipolar). The DM860H driver will not work with the Stepper library.

You should be using a library that is written for the step/dir drivers like the AccelStepper library or the MobaTools stepper library . I think MobaTools is easier to learn. There is documentation and examples to help to learn it.

Here is the manual for the DM860H stepper driver. See page 4 for how to wire to a microcontroller. I would wire all of the - terminals to ground and the step, dir and enable terminals to outputs of the Arduino board. Wiring motors to the driver is covered on pages 4,5 and 6.

Member @ghufi seems to have the same type of problem as you do. You may want to watch his thread as it is similar to yours.

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