My DC Motor 24v do not works using L293D IC

Hello everyone ,
I am using to control a sliding door with a 24v DC motor with double way , as a solution i am using an L293D IC , the door must be controlled manually with buttons and like a supplement i wanna add a hc-06 bluetooth module , the motor is attached to a pinion that control a chain which let the door moving forward or backward , and the door must stop when the door is totally opened or closed , its means the door must keep his state if opned and don't close only when we control it to close and vice versa...
i tried to use "for" loop , and define a counter but it doesn't work
so i declared a button just to try how i can control it when the button change's it state
here is my code :

int avPin = 7;    
int arPin = 8;
int motor1Pin = 13;    
int motor2Pin = 12;    
int enablePin = 11;   
int a=100;
     int pos=0;
     int i;
void setup() {
pinMode(avPin, INPUT); 
pinMode(arPin , INPUT);
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
    pinMode(enablePin, OUTPUT);
  void loop() {
     if ((digitalRead(avPin) == HIGH))
             do {
                  digitalWrite(motor1Pin, HIGH);   // set leg 1 of the H-bridge low
                   digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge high
                    } while (digitalRead(arPin) == HIGH) ;
      else if ((digitalRead(arPin) == HIGH))
                do {
                     digitalWrite(motor1Pin, LOW);  
                      digitalWrite(motor2Pin, HIGH);   
                       } while (digitalRead(arPin) == LOW);}
     else if ((digitalRead(avPin) == LOW) && (digitalRead(arPin) == LOW) && (pos=0))
              for (i=0; i<=a; i++) {
                  analogWrite(enablePin, HIGH);
                    digitalWrite(motor1Pin, HIGH);
                       digitalWrite(motor2Pin, LOW);
      else if ((digitalRead(avPin) == LOW) && (digitalRead(arPin) == LOW && (pos=a)))
      {           for (i=a; i>=0; i--) {
                    analogWrite(enablePin, HIGH);
                      digitalWrite(motor2Pin, HIGH);
                         digitalWrite(motor1Pin, LOW);

The compilation shows no errors but the simulation on isis do not works
Can you please help me with my code "I attached a copy below"
Thank you in advance

motorDC_Forloop.ino (1.49 KB)

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Post modified , i am sorry about the first post and thank you very much for your reply
Friendly Zirus109

i want to control the door like that,
First step:
button forward pushed , motor sens1=on , till its totally closed then state memorisation and it must work again only when backward button is pushed,
Second step:
button backward pushed , motor sens2=on till its totally opened then state memorisation and it must work again only when forward button pushed again
i am thinking to add 2 limit switch (buttons for examples) in the both sides
then it will be like that
button forward=on and back limit switch are both activated then sens 1=on till it reachs the front limit switch and sames for the sens2
Thank you for your respond anyway
Friendly Zirus109