I'm new with arduino, I'm having difficulties

I'm having trouble with a code or possibly the motor control. I have a stepper 11, I've tried on a dm542t and a tb6600. So I found a code in a previous topic but there weren't any real answers there. I will post the code. Can someone please point me in the right direction. I've watched videos after videos and read so much, I'm just at a point of I need help or just quit. Thank you for any time spent helping me.
All the motor does is tick, seems like the pots are kind of working but I don't know. I would just like the motor to go back and forth, being able to control the speed with pot, distance of travel with pot and delay at the end of travel with the last pot. Use code tags to format code for the forum

// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
void setup() {

// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(A0, INPUT);
pinMode(A2, INPUT);
pinMode(A4, INPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);

}
void loop() {

int range = analogRead (A4);
int speed= analogRead (A2);
int wait= analogRead (A0);

digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction

for(int x = 0; x < range; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
{ delay(wait);

{ digitalWrite(dirPin,LOW); //Changes the rotations direction

for(int x = 0; x < range; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
{ delay(wait);
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

Does that even compile?

It won't. There's at least three misplaced curly brackets {

These don't get starting curly brackets before them.

Ticking motor is likely power issue. Do NOT use your standard rectangular 9V battery for power. They only last minutes!
Use AA X 6 for 9V or use a wall wart or usb, but NOT a 9V transistor radio battery!

That's 1000 steps per second. I know a NEMA 11 is a small motor but it may not be able to jump from 0 to 1000 SPS instantly, try a slower speed, say 5000 instead of 500. Have you set the current control on your drivers to suit the motor?

For help with motors, please post links to the motor product page or data sheet, to the motor driver you are using, and describe the motor power supply. 9V batteries will not work.

Also post a photo of a hand drawn wiring diagram, with pins and connections clearly labeled. A photo of the setup would help too.

Please explain what is connected to these inputs and include that in the wiring diagram:

int range = analogRead (A4);
int speed= analogRead (A2);
int wait= analogRead (A0);

1
2 ‡include <AccelStepper.h>;
3 const int stepPin = 3;
4 const int directionPin = 2;
5 const int enPin = 8:
6 ‡define step (range);
7 void setup () {
8
/ put your setup code here, to run once:
9
pinMode (stepPin, OUTPUT) ;
10
11
pinMode (directionPin, OUTPUT); digitalWrite (enPin, LOW);
12
pinMode (A0, INPUT) :
13
pinMode (A2, INPUT);
14
pinMode (A4, INPUT);
15
16 };
17
18 void loop () {
19
put your main code here, to run repeatedly:
20
int range = analogRead (A4);
21
int speed = analogRead (A2);
22
int wait = analogRead (A0);
23
digitalWrite (directionPin, HIGH);
24
for (int x = 0; x < 6400; *++);
25
digitalWrite (stepPin, HIGH).
26
delayMicroseconds (500);
27
digitalWrite (stepPin, LOW);
28
delayMicroseconds (500 + (4 * speed)) ;

delay (1000) ;
digitalWrite (directionPin, LOW);
for (int x = 0; x < 6400; x++);
digitalWrite (stepPin, HIGH);
delayMicroseconds (500);
digitalWrite (stepPin, LOW);
delayMicroseconds (500 + (4 * speed));
This is the code I got to compile but nothing happens

Still not formatted properly, and it is not complete.

Please read and follow the instructions in the "How to get the best out of this forum" post, and answer the questions above.

I am plugged into laptop. I am using a 24v power supply for the tb6600

I'm sorry for being so vague. A potentiometer on the analog. I will post what you asked in just a few. I need to get it together.

Atmeg256 board

Your code needs to be properly presented to the forum. Use code tags. On my screen, it's a little icon at the top of the window I'm typing this in, and actually says "code" . Now, how to do this gracefully:
Go to the Arduino IDE. Press ctrl-t to format the code properly. Press shift-ctrl-c to copy the code for the forum, then go back to a new message window on the forum, start a reply, and within that reply, simply press ctrl-v. The code tags are applied automagically by the forum software, and your code will appear in the window properly formatted, when you finish your reply.

Absolutely didn't happen

1 Like

#include <AccelStepper.h>;
const int stepPin = 3;
const int directionPin = 2;
const int enPin = 8;
#define step(range);
void setup() {
// put your setup code here, to run once:
pinMode(stepPin, OUTPUT);
pinMode(directionPin, OUTPUT);
digitalWrite(enPin, LOW);
pinMode(A0, INPUT);
pinMode(A2, INPUT);
pinMode(A4, INPUT);

};

void loop() {
// put your main code here, to run repeatedly:
int range = analogRead (A4);
int speed = analogRead (A2);
int wait = analogRead (A0);
digitalWrite(directionPin, HIGH);
for (int x = 0; x < 6400; x++);
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500 + (4 * speed));

delay(1000);
digitalWrite(directionPin, LOW);
for (int x = 0; x < 6400; x++);
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500 + (4 * speed));
};

If you do it as I suggested, this is what it should look like. Perhaps you didn't do a shift-ctrl-c?

#include <AccelStepper.h>;
const int stepPin = 3;
const int directionPin = 2;
const int enPin = 8;
#define step(range);
void setup() {
  // put your setup code here, to run once:
  pinMode(stepPin, OUTPUT);
  pinMode(directionPin, OUTPUT);
  digitalWrite(enPin, LOW);
  pinMode(A0, INPUT);
  pinMode(A2, INPUT);
  pinMode(A4, INPUT);

};

void loop() {
  // put your main code here, to run repeatedly:
  int range = analogRead (A4);
  int speed = analogRead (A2);
  int wait = analogRead (A0);
  digitalWrite(directionPin, HIGH);
  for (int x = 0; x < 6400; x++);
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(500 + (4 * speed));

  delay(1000);
  digitalWrite(directionPin, LOW);
  for (int x = 0; x < 6400; x++);
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(500 + (4 * speed));
};

I recommend to start with the simplest program that just steps the motor once per second, and go from there.

That's what it looks like in the IDE, what you just posted