Hello, do you see any mistakes with my line follower, or have a recomendation?

Hello, i’m trying to do a line follower that when it hits an object it opens a compartment, and then turns around, this is my current code, but i haven’t had any chance to test it, so it would be cool if y’all could take a look at it.
int distancia;

//J1 = Right Frontal IR Sensor
//J2 = Midle Frotal IR Sensor
//J3 = Left Frontal IR Sensor
//M1 = right motor
//M2 = left motor
void setup() {
Serial.begin(9600);
motorSpeed (M1, 65);
motorSpeed (M2, 65);
lineCalibrate(J1, 400);
lineCalibrate(J2, 450);
lineCalibrate(J3, 250);
int sensor1 = lineRead(J1);
int sensor2 = lineRead(J2);
int sensor3 = lineRead(J3);
}
void loop() {
int sensor1 = lineRead(J1);
int sensor2 = lineRead(J2);
int sensor3 = lineRead(J3);
distancia = ultrasoundRead(J5);
Serial.print ( sensor1);
Serial.print ( sensor2);
Serial.print ( sensor3);
Serial.println (distancia);
delay (100);
if (sensor1 == 3 && sensor2 == 3 && sensor3 == 3){
motorOff (M1);
motorOff (M2);
}
if (sensor1 == WHITE && sensor2 == BLACK && sensor3 == WHITE){
motorOn (M1,FORWARD);
motorOn (M2,REVERSE);
motorSpeed(M1,100);
motorSpeed (M2,100);
}
if (sensor1 == WHITE && sensor2 == WHITE && sensor3 == BLACK){
motorOn (M1,FORWARD);
motorOn (M2,REVERSE);
motorSpeed(M1,100);
motorSpeed (M2,100);
}
if (sensor1 == BLACK && sensor2 == WHITE && sensor3 == WHITE){
motorOn (M2,FORWARD);
motorOn (M1,REVERSE);
motorSpeed(M1,100);
motorSpeed (M2,100);
}
if (sensor1 == WHITE && sensor2 == BLACK && sensor3 == BLACK){
motorOn (M1,FORWARD);
motorOn (M2,REVERSE);
motorSpeed(M1,100);
motorSpeed (M2,100);
}
if (sensor1 == BLACK && sensor2 == BLACK && sensor3 == WHITE){
motorOn (M2,FORWARD);
motorOn (M1,REVERSE);
motorSpeed(M1,100);
motorSpeed (M2,100);
}
if (sensor1 == BLACK && sensor2 == BLACK && sensor3 == BLACK && distancia > 5){
motorOn (M2,FORWARD);

motorOn (M1,REVERSE);

 motorSpeed(M1,100);
motorSpeed (M2,100);
delay (500);
}
if (sensor1 == BLACK && sensor2 == BLACK && sensor3 == BLACK && distancia < 5){
motorOff (M1);
motorOff (M2);
motorOn (M3, FORWARD);
motorSpeed(M3,100);
delay (20000);
motorOn (M3, REVERSE);
motorSpeed(M3,73);
motorOn (M1,FORWARD);
motorOn (M2,REVERSE);
motorSpeed(M1,100);
motorSpeed (M2,100);
delay (500);
}
}

First of all, it will not compile. Where do you define things like J1? And motorSpeed of lineCalibrate?

And you have at the top you mean with J1 the right frontal IR sensor. Why not bloody call that way but make it something cryptic like J1...

Speaking about cryptic. Please use indents next time. The code is very unreadable. And maybe a blank line after a function. And comments, use comments. Tell us (and future you) what you (try to) do.

So yeay, don't bother testing it. First fix it ;)

Hi, You need to define what pins are for the sensors and that they are inputs. You need to define what pins are for the motors and that they are outputs.

For example.

//define sensor right front and its pin number , in this case pin 4.
//define motors and their pin numbers.

int RightFrontSensor = 3;
int MiddleFrontSensor = 4;
int RightMotor = 5;
int LeftMotor = 6;

//then setup inputs and outputs

void setup(){
pinMode(RightFrontSensor, INPUT);
pinMode(MiddleFrontSensor, INPUT);
pinMode(RightMotor, OUTPUT);
pinMode(LeftMotor, OUTPUT);
}

// then to control
void loop(){
analogWrite(RightMotor,60);
analogWrite(LeftMotor,60);
}

You still have a fair bit of programming to do. What is your electronics, programming, arduino, hardware experience?

Tom.. :)

Hello, there’s no problem compiling as terms like J1 are the name of the ports being used for the sensors, the same can be said for M1 for the motors, i have to add that i’m using a modified version of arduino called innobot IDE, which allows me to do the things specified above without issue

Yeay you damn well should! If you use Innobot IDE and not the Arduino IDE, why do you ask questions here? This is a forum for the Arduino IDE...

Touche, it's just that Innobot IDE doesn't have a forum or anything, and well i didn't lose anything trying here. anyway thanks :3

If they have all kind of weird build in functions then it's a bit hard for a normal Arduino reader to debug...

I don't get why they made there own IDE. Why not just make a libary/board.... Ow well....