Stepper motor+LCDA86H driver ,code and function if().

Hi, I'm a beginner with arduino and I'm trying my best! Today I started to move a stepper motor with a driver on it, I finally succeeded, I didn't find tutorials on the net, so I'll try to get involved! Now I'm trying to move a 4118S-08P-01RO-LP stepper motor with an LCDA86H driver and of course, an arduino uno. I managed to connect it, move it a little, but I'd like it to stop when I touch the magnetic sensor, it's it's a Panasonic GH-H6B sensor. I can't understand how to adjust the engine speed and how to make it stop when it reaches the end of the stroke.

I came here after many attempts:

<const int senzor=7;
void setup(){
Serial.begin(9600);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(endPin, OUTPUT);
digitalWrite(endPin, LOW);
}

void loop(){

int senzor1stare=digitalRead(senzor);
if(senzor1stare==HIGH){
delay(5);
}

if(senzor1stare==LOW){
for(int x=0;x<800;x++){
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
}
}>
With this sensor,how if works?it's something like ==0/1 or ==HIGH/LOW?

Regards,Alex.

 int senzor1stare=digitalRead(senzor);

What, exactly, is connected to that pin?

 if(senzor1stare==HIGH){
    digitalWrite(stepPin,LOW);
    delay(5);
  } else {
    digitalWrite(stepPin,LOW);
  }

If the pin is HIGH, set the step pin low and wait 5 milliseconds. Otherwise, just set the step pin low. How does that make sense?

Dear Paul,senzor it's the sensor.I forgot to specify that it is not an shield for arduino

I change the code:

const int dirPin = 10;
const int stepPin= 11;
const int endPin = 5;
const int senzor=7;
void setup(){
Serial.begin(9600);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(endPin, OUTPUT);
digitalWrite(endPin, LOW);
}

void loop(){

int senzor1stare=digitalRead(senzor);
if(senzor1stare==HIGH){
digitalWrite(dirPin,LOW);
delay(5);
} else {
digitalWrite(dirPin,LOW);
}

if(senzor1stare==LOW){
for(int x=0;x<800;x++){
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
}
}

But,it just rotates.
Can i ask you for an email or something?Thanks!

He is talking about "code factoring", removing redundancy from a program to make it clearer and more efficient.

if(senzor1stare==HIGH){
    digitalWrite(stepPin,LOW);
    delay(5);
  } else {
    digitalWrite(stepPin,LOW);
  }

If in both cases you do the same thing, it makes no sense to include it in the conditional statement. Instead treat it separately:

if(senzor1stare==HIGH){
    delay(5); }
digitalWrite(stepPin,LOW);

Please read these two posts:

General Guidance and How to use the Forum
and
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials

It is important to provide as much of the information that is needed to solve your problem as you can, in your first posts. The forum link above has guidelines for posting in a standard way that makes it easiest for people to provide you with useful answers. Making an effort to do this will greatly increase the number and quality of helpful responses that you get. Explaining that a "senzor" is a sensor, is not really answering the question, which is, "what kind of sensor?".

In this case, the problem is that you have posted code twice without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing or review.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Please don't PM me with technical questions, as requested in my signature. Post them in the forum.