my motor don't work on my new program

hello, i have program for control motor with “time of flight distance(VL053LX)”, actually i test the motor for manual part, but this motor don’t work (the motor work in normal program).

#include "Adafruit_VL53L0X.h"
#include <Wire.h>
#include "rgb_lcd.h"
#include <AFMotor.h>

bool _ABVAR_1_ManAuto = false ;
bool _ABVAR_2_Avancer = false ;
bool _ABVAR_3_Reculer = false ;
bool _ABVAR_4_Droite = false ;
bool _ABVAR_5_Gauche = false ;
bool _ABVAR_6_STOP = false ;
int _ABVAR_7_Longeur = 0 ;
int _ABVAR_8_Largeur = 0 ;
int _ABVAR_9_L = 0 ;
int _ABVAR_10_l = 0 ;
int _ABVAR_11_Dgauche = 0 ;
int _ABVAR_12_DDroit = 0 ;
int _ABVAR_13_LargeurRobot = 0 ;
int _ABVAR_14_angle = 0 ;
int _ABVAR_15_a;
int _ABVAR_1_test = 0 ;

rgb_lcd lcd;

const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

#define LOX3_ADDRESS 0x29
#define LOX2_ADDRESS 0x30
#define LOX1_ADDRESS 0x31

#define SHT_LOX1 7
#define SHT_LOX2 6
#define XSHUT_pin1 22

Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox3 = Adafruit_VL53L0X();

VL53L0X_RangingMeasurementData_t measure1;
VL53L0X_RangingMeasurementData_t measure2;

AF_DCMotor moteur1(1);
void setID() {
  lcd.begin(16, 2);

  lcd.setRGB(colorR, colorG, colorB);

  lcd.print("initialisation");

  lox1.begin(0x29);
  lox2.begin(0x29);
  lox3.begin(0x29);


  pinMode(XSHUT_pin1, OUTPUT);
  lox3.begin(0x30);
  pinMode(XSHUT_pin1, INPUT);
  delay (10) ;
  lox3.begin(0x31);
  analogWrite(52, 255);


  // all reset
  digitalWrite(SHT_LOX1, LOW);
  digitalWrite(SHT_LOX2, LOW);
  delay(10);
  // all unreset
  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, HIGH);
  delay(10);

  // activating LOX1 and reseting LOX2
  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, LOW);

  // initing LOX1
  if (!lox1.begin(LOX1_ADDRESS)) {
    Serial.println(F("Failed to boot first VL53L0X"));
    while (1);
  }
  delay(10);

  // activating LOX2
  digitalWrite(SHT_LOX2, HIGH);
  delay(10);

  //initing LOX2
  if (!lox2.begin(LOX2_ADDRESS)) {
    Serial.println(F("Failed to boot second VL53L0X"));
    while (1);
  }
}

void read_dual_sensors() {

  lcd.clear();

  lox1.rangingTest(&measure1, false);
  lox2.rangingTest(&measure2, false);

  Serial.print("capteur 1: ");
  if (measure1.RangeStatus != 4) {
    Serial.print(measure1.RangeMilliMeter - 30);
    Serial.print("mm                 ");
  } else {
    Serial.print("trop loin     ");
    lcd.setCursor(1, 1); {
      lcd.print("XX");
    }
  }

  Serial.print(" ");


  Serial.print("capteur 2: ");
  if (measure2.RangeStatus != 4) {
    Serial.print(measure2.RangeMilliMeter - 30);
    const char CAP2 = (measure2.RangeMilliMeter - 30);
    Serial.print("mm");
  } else {
    Serial.print("trop loin");
    lcd.setCursor(1, 1); {
      lcd.print("XX");
    }
  }

  Serial.println();
  lcd.setCursor(0, 0); {
    lcd.print("cap1        cap2");
  }
  if ((measure1.RangeMilliMeter - 30) < 7000) {
    lcd.setCursor(1, 1); {
      lcd.print(measure1.RangeMilliMeter - 30);
    }
  } else {
    lcd.setCursor(1, 1); {
      lcd.print("out");
    }

  }
  if ((measure2.RangeMilliMeter - 30) < 7000) {
    lcd.setCursor(13, 1); {
      lcd.print(measure2.RangeMilliMeter - 30);
    }
  } else {
    lcd.setCursor(13, 1); {
      lcd.print("out");
    }

  }

  delay(10);
}

void setup() {


  moteur1.run(RELEASE);

  Serial.begin(9600);
  while (! Serial) {
    delay(1);
  }

  pinMode(SHT_LOX1, OUTPUT);
  pinMode(SHT_LOX2, OUTPUT);

  Serial.println("Shutdown pins inited...");

  digitalWrite(SHT_LOX1, LOW);
  digitalWrite(SHT_LOX2, LOW);

  Serial.println("Both in reset mode...(pins are low)");


  Serial.println("Starting...");
  setID();

  pinMode( 33 , INPUT);
  pinMode( 35 , INPUT);
  pinMode( 37 , INPUT);
  pinMode( 39 , INPUT);
  pinMode( 41 , INPUT);
  pinMode( 31 , INPUT);




}


void loop() {
  {
    read_dual_sensors();
    _ABVAR_1_ManAuto = digitalRead(31) ;
    _ABVAR_2_Avancer = digitalRead(33) ;
    _ABVAR_3_Reculer = digitalRead(35) ;
    _ABVAR_4_Droite = digitalRead(37) ;
    _ABVAR_5_Gauche = digitalRead(39) ;
    _ABVAR_6_STOP = digitalRead(41) ;
    _ABVAR_7_Longeur = analogRead(14) ;
    _ABVAR_8_Largeur = analogRead(15) ;
    _ABVAR_9_L = 0 ;
    _ABVAR_10_l = 0 ;
    _ABVAR_11_Dgauche = 0 ;
    _ABVAR_12_DDroit = 0 ;
    _ABVAR_13_LargeurRobot = 70 ;
    _ABVAR_14_angle = 0 ;
    _ABVAR_1_test = analogRead(0);

    if (( ( _ABVAR_1_ManAuto ) == (LOW) ))
    { read_dual_sensors();
      while ( ( ( _ABVAR_1_ManAuto ) == (LOW) ) )
      { read_dual_sensors();
        _ABVAR_1_test = analogRead(0);
        if (( ( _ABVAR_1_test ) > ( 50 ) ))
        {
          while ( ( ( ( ( _ABVAR_3_Reculer ) == ( LOW ) ) && ( ( _ABVAR_5_Gauche ) == ( LOW ) ) ) && ( ( ( _ABVAR_4_Droite ) == ( LOW ) ) && ( ( _ABVAR_6_STOP ) == ( LOW ) ) && (( ( _ABVAR_1_test ) > ( 50 ) )) ) ) )
          { _ABVAR_1_test = analogRead(0);
                      moteur1.setSpeed(200);
            moteur1.run(FORWARD);
            moteur1.setSpeed(200);
            delay(500);
            read_dual_sensors();

            Serial.println(_ABVAR_1_test);
          }
        }
        else
        {
          if (( ( _ABVAR_3_Reculer ) == ( HIGH ) ))
          {
            while ( ( ( ( ( _ABVAR_2_Avancer ) == ( LOW ) ) && ( ( _ABVAR_5_Gauche ) == ( LOW ) ) ) && ( ( ( _ABVAR_4_Droite ) == ( LOW ) ) && ( ( _ABVAR_6_STOP ) == ( LOW ) ) ) ) )
            { moteur1.run(BACKWARD);
              read_dual_sensors();
            }
          }
          else
          {
            if (( ( _ABVAR_5_Gauche ) == ( HIGH ) ))
            {
              while ( ( ( ( ( _ABVAR_2_Avancer ) == ( LOW ) ) && ( ( _ABVAR_3_Reculer ) == ( LOW ) ) ) && ( ( ( _ABVAR_4_Droite ) == ( LOW ) ) && ( ( _ABVAR_6_STOP ) == ( LOW ) ) ) ) )
              { moteur1.run(FORWARD);
                read_dual_sensors();
              }
            }
            else
            {
              if (( ( _ABVAR_4_Droite ) == ( HIGH ) ))
              {
                while ( ( ( ( ( _ABVAR_2_Avancer ) == ( LOW ) ) && ( ( _ABVAR_3_Reculer ) == ( LOW ) ) ) && ( ( ( _ABVAR_5_Gauche ) == ( LOW ) ) && ( ( _ABVAR_6_STOP ) == ( LOW ) ) ) ) )
                { moteur1.run(BACKWARD);
                  read_dual_sensors();
                }
              }
              else
              {
                if (( ( _ABVAR_6_STOP ) == ( HIGH ) ))
                {
                  while ( ( ( ( ( _ABVAR_2_Avancer ) == ( LOW ) ) && ( ( _ABVAR_3_Reculer ) == ( LOW ) ) ) && ( ( ( _ABVAR_5_Gauche ) == ( LOW ) ) && ( ( _ABVAR_4_Droite ) == ( LOW ) ) ) ) )
                  {
                    moteur1.setSpeed(0);
                    read_dual_sensors();
                  }
                }
              }
            }
          }
        }
      }
    }
    else
    {
      read_dual_sensors();
    }
  }
}

i use shiel motor
i don’t understand why my motor don’t work because is the same thing of this

#include <AFMotor.h>
AF_DCMotor moteur1(1);
void setup(){
moteur1.run(RELEASE);
}
void loop(){
moteur1.run(FORWARD);
moteur1.setSpeed(255);
delay(1000);
moteur1.run(RELEASE);
delay(1000);
moteur1.run(FORWARD);
moteur1.setSpeed(200);
delay(10000);
}

Hey, another coding koala !!! :grinning:

French speaking koalas can join the french section of the forum...

Anyways, have you tested and checked that your sensor works? You should organize your code in atomic functions, easier to test and to read, and also put some Serial.print-s to verify its behavior.

hey, i have make a lot of test, the problem is the "void loop" the motor don't work in this "void" but he work on other "void". Normaly he must work in "void loop" because he work on the little program...

You should print the values of your varaibles, such as these ones

   _ABVAR_1_ManAuto = digitalRead(31) ;
   _ABVAR_2_Avancer = digitalRead(33) ;
   _ABVAR_3_Reculer = digitalRead(35) ;
   _ABVAR_4_Droite = digitalRead(37) ;
   _ABVAR_5_Gauche = digitalRead(39) ;
   _ABVAR_6_STOP = digitalRead(41) ;
   _ABVAR_7_Longeur = analogRead(14) ;
   _ABVAR_8_Largeur = analogRead(15) ;

to see if you go inside any of your ifs.

Also, after each if, put a Serial.println to show how the code behaves, such as

if (( ( _ABVAR_1_ManAuto ) == (LOW) ))
   {  Serial.println("( _ABVAR_1_ManAuto ) == (LOW)");
       read_dual_sensors();

yes, but this part work :) , is not my problem; the real problem is that the motor don't work anywhere I put it in the part "void loop".

It works, meaning probably it compiles correctly. But it doesn't really work as you can't see the motor move. Maybe no if-condition is true and then no motor movement can be seen. That's what I suggest you add prints in the code : to see how it behaves, and if the conditions are fulfilled or not.

Also, I don't see any pinMode for digitalReads 14 & 15...

the if-condition work i use lcd and i see when the condition is active the problem can really come from the fact that I did not put "pinmode" on 14 and 15, even unconditionally the engine does not work

Then if everything works as expected, verify your cables...

The problem is note the cables, if i use the motor on the "void loop" the motor work but if i put the motor control on the "void loop" the motor don't work...

Hoellp: The problem is note the cables, if i use the motor on the "void loop" the motor work but if i put the motor control on the "void loop" the motor don't work...

What does that mean, please?

What's wrong with this picture?

#define LOX3_ADDRESS 0x29
#define LOX2_ADDRESS 0x30
#define LOX1_ADDRESS 0x31

...

  lox1.begin(0x29);
  lox2.begin(0x29);
  lox3.begin(0x29);

Didn't you mean to write

 lox1.begin(LOX1_ADDRESS);
  lox2.begin(LOX2_ADDRESS);
  lox3.begin(LOX3_ADDRESS);

AWOL: What does that mean, please?

the problems do not come from the connections, when I put this in the "void setup" the engine works:

void setup() {
  moteur1.run(RELEASE);
moteur1.run(FORWARD);
moteur1.setSpeed(255);

but when I put exactly the same thing in the "void loop" it does not work.

flounder: What's wrong with this picture

this part works well (it is to use 2 sensors of the same address). But it does not really have to do with my problem...