Something is not working

Greetings.I am looking for help regarding my code for an Arduino project.It is an autonomous fire extinguishing robot,Arduino UNO,IR sensors,4 x DC motors,L298N motor driver,SG90 servo-motor and a water pump.The hardware works alright,but the problem is with the code.I have a code,that is open source and works just fine,but i cannot use it,since it does not belong to me.I adapted the code and the right side motors OUT3 OUT4 stop working and i do not understand why.Unfortunately i cannot add attachements,because i am new,so i will just put down the codes.
The code that works along with the robot-

type or pas Circuit Diagram
 
 #define enA 10//Enable1 L298 Pin enA
 #define in1 9 //Motor1 L298 Pin in1
 #define in2 8 //Motor1 L298 Pin in2
 #define in3 7 //Motor2 L298 Pin in3
#define in4 6 //Motor2 L298 Pin in4
 #define enB 5 //Enable2 L298 Pin enB
 #define ir_R A0
 #define ir_F A1
 #define ir_L A2
 #define servo A4
 #define pump A5
 int Speed = 160; // Write The Duty Cycle 0 to 255 Enable for Motor Speed
 int s1, s2, s3;
 void setup(){ // put your setup code here, to run once
 Serial.begin(9600); // start serial communication at 9600bps
 pinMode(ir_R, INPUT);// declare fire sensor pin as input
 pinMode(ir_F, INPUT);// declare fire sensor pin as input
 pinMode(ir_L, INPUT);// declare fire sensor pin as input
 pinMode(enA, OUTPUT); // declare as output for L298 Pin enA
 pinMode(in1, OUTPUT); // declare as output for L298 Pin in1
 pinMode(in2, OUTPUT); // declare as output for L298 Pin in2
 pinMode(in3, OUTPUT); // declare as output for L298 Pin in3
 pinMode(in4, OUTPUT); // declare as output for L298 Pin in4
 pinMode(enB, OUTPUT); // declare as output for L298 Pin enB
 pinMode(servo, OUTPUT);
 pinMode(pump, OUTPUT);
 for (int angle = 90; angle <= 140; angle += 5) {
 servoPulse(servo, angle); }
 for (int angle = 140; angle >= 40; angle-= 5) {
 servoPulse(servo, angle); }
 for (int angle = 40; angle <= 95; angle += 5) {
 servoPulse(servo, angle); }
 analogWrite(enA, Speed); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed
 analogWrite(enB, Speed); // Write The Duty Cycle 0 to 255 Enable Pin B for Motor2 Speed
 delay(500);
 }
 void loop(){
 s1 = analogRead(ir_R);
 s2 = analogRead(ir_F);
s3 = analogRead(ir_L);
 //=============================================================
 //
 Auto Control
 //=============================================================
 Serial.print(s1);
 Serial.print("\t");
 Serial.print(s2);
 Serial.print("\t");
 Serial.println(s3);
 delay(50);
 if(s1<250){
 Stop();
 digitalWrite(pump, 1);
 for(int angle = 90; angle >= 40; angle-= 3){
 servoPulse(servo, angle);
 }
 for(int angle = 40; angle <= 90; angle += 3){
 servoPulse(servo, angle);
 }
 }
 else if(s2<350){
 Stop();
 digitalWrite(pump, 1);
 for(int angle = 90; angle <= 140; angle += 3){
 servoPulse(servo, angle);
 }
 for(int angle = 140; angle >= 40; angle-= 3){
 servoPulse(servo, angle);
 }
 for(int angle = 40; angle <= 90; angle += 3){
 servoPulse(servo, angle);
 }
 }
 else if(s3<250){
 Stop();
digitalWrite(pump, 1);
 for(int angle = 90; angle <= 140; angle += 3){
 servoPulse(servo, angle);
 }
 for(int angle = 140; angle >= 90; angle-= 3){
 servoPulse(servo, angle);
 }
 }
 else if(s1>=251 && s1<=700){
 digitalWrite(pump, 0);
 backword();
 delay(100);
 turnRight();
 delay(200);
 }
 else if(s2>=251 && s2<=800){
 digitalWrite(pump, 0);
 forword();
 }
 else if(s3>=251 && s3<=700){
 digitalWrite(pump, 0);
 backword();
 delay(100);
 turnLeft();
 delay(200);
 }else{
 digitalWrite(pump, 0);
 Stop();
 }
 delay(10);
 }
 void servoPulse (int pin, int angle){
 int pwm = (angle*11) + 500;
 digitalWrite(pin, HIGH);
 delayMicroseconds(pwm);
 // Convert angle to microseconds
 digitalWrite(pin, LOW);
delay(50);
 // Refresh cycle of servo
 }
 void forword(){ //forword
 digitalWrite(in1, HIGH); //Right Motor forword Pin
 digitalWrite(in2, LOW); //Right Motor backword Pin
 digitalWrite(in3, LOW); //Left Motor backword Pin
 digitalWrite(in4, HIGH); //Left Motor forword Pin
 }
 void backword(){ //backword
 digitalWrite(in1, LOW); //Right Motor forword Pin
 digitalWrite(in2, HIGH); //Right Motor backword Pin
 digitalWrite(in3, HIGH); //Left Motor backword Pin
 digitalWrite(in4, LOW); //Left Motor forword Pin
 }
 void turnRight(){ //turnRight
 digitalWrite(in1, LOW); //Right Motor forword Pin
 digitalWrite(in2, HIGH); //Right Motor backword Pin
 digitalWrite(in3, LOW); //Left Motor backword Pin
 digitalWrite(in4, HIGH); //Left Motor forword Pin
 }
 void turnLeft(){ //turnLeft
 digitalWrite(in1, HIGH); //Right Motor forword Pin
 digitalWrite(in2, LOW); //Right Motor backword Pin
 digitalWrite(in3, HIGH); //Left Motor backword Pin
 digitalWrite(in4, LOW); //Left Motor forword Pin
 }
 void Stop(){ //stop
 digitalWrite(in1, LOW); //Right Motor forword Pin
 digitalWrite(in2, LOW); //Right Motor backword Pin
 digitalWrite(in3, LOW); //Left Motor backword Pin
 digitalWrite(in4, LOW); //Left Motor forword Pin
 }te code here

and the code that does not work

type or past#include <Servo.h>  // Adăugăm biblioteca Servo

#define enA 10
#define in1 9 
#define in2 8 
#define in3 7 
#define in4 6 
#define enB 5 
#define ir_R A0
#define ir_F A1
#define ir_L A2
#define servo A4
#define pump A5

// Variabile globale
int Speed = 160;
int sR, sF, sL;
Servo SG90;  // Creăm obiectul Servo

void setup(){  
    Serial.begin(9600);  

    // Configurare pini  
    pinMode(ir_R, INPUT);
    pinMode(ir_F, INPUT);
    pinMode(ir_L, INPUT);
    pinMode(enA, OUTPUT);  
    pinMode(in1, OUTPUT);  
    pinMode(in2, OUTPUT);  
    pinMode(in3, OUTPUT);  
    pinMode(in4, OUTPUT);  
    pinMode(enB, OUTPUT);  
    pinMode(pump, OUTPUT);

    // Atașare servomotor
   SG90.attach(servo);

    // Mișcăm servo-ul la pornire
SG90.write(90);
delay(500);

    // Setare viteză motoare  
    analogWrite(enA, Speed);  
    analogWrite(enB, Speed);  
    delay(500);
}

void loop(){  
    // Citire senzori  
    sR = analogRead(ir_R);
    sF = analogRead(ir_F);
    sL = analogRead(ir_L);

    Serial.print(sR);
    Serial.print("\t");
    Serial.print(sF);
    Serial.print("\t");
    Serial.println(sL);

    delay(50);

    if(sR < 250){
        Stop();
        digitalWrite(pump, 1);
        for(int angle = 90; angle >= 60; angle -= 3){
            SG90.write(angle);
            delay(50);
        }
        for(int angle = 60; angle <= 90; angle += 3){
            SG90.write(angle);
            delay(50);
        }
    }
    else if(sF < 350){
        Stop();
        digitalWrite(pump, 1);
        for(int angle = 90; angle <= 120; angle += 3){
            SG90.write(angle);
            delay(50);
        }
        for(int angle = 120; angle >= 60; angle -= 3){
           SG90.write(angle);
            delay(50);
        }
        for(int angle = 60; angle <= 90; angle += 3){
            SG90.write(angle);
            delay(50);
        }
    }
    else if(sL < 250){
        Stop();
        digitalWrite(pump, 1);
        for(int angle = 90; angle <= 120; angle += 3){
            SG90.write(angle);
            delay(50);
        }
        for(int angle = 120; angle >= 90; angle -= 3){
            SG90.write(angle);
            delay(50);
        }
    }
    else if(sR >= 251 && sR <= 700){
        digitalWrite(pump, 0);
        backward();
        delay(100);
        turnRight();
        delay(200);
    }
    else if(sF >= 251 && sF <= 800){
        digitalWrite(pump, 0);
        forward();
    }
    else if(sL >= 251 && sL <= 700){
        digitalWrite(pump, 0);
        backward();
        delay(100);
        turnLeft();
        delay(200);
    } else {
        digitalWrite(pump, 0);
        Stop();
    }
    delay(10);
}

// 📌 Funcții pentru motoare
void forward(){  
    digitalWrite(in1, HIGH);  
    digitalWrite(in2, LOW);  
    digitalWrite(in3, LOW);  
    digitalWrite(in4, HIGH);  
}

void backward(){  
    digitalWrite(in1, LOW);  
    digitalWrite(in2, HIGH);  
    digitalWrite(in3, HIGH);  
    digitalWrite(in4, LOW);  
}

void turnRight(){  
    digitalWrite(in1, LOW);  
    digitalWrite(in2, HIGH);  
    digitalWrite(in3, LOW);  
    digitalWrite(in4, HIGH);  
}

void turnLeft(){  
    digitalWrite(in1, HIGH);  
    digitalWrite(in2, LOW);  
    digitalWrite(in3, HIGH);  
    digitalWrite(in4, LOW);  
}

void Stop(){  
    digitalWrite(in1, LOW);  
    digitalWrite(in2, LOW);  
    digitalWrite(in3, LOW);  
    digitalWrite(in4, LOW);  
}

e code here

thank you for your time.

Can you explain why the open source did not work?
And what changes you made?
And post a schematic and a picture?
You need to do some reading on the forum to 'earn' rights to post pictures (not my idea!).
And in IDE press ctrl-t and tgen paste the code here again... it will format your code, and make it easier to find errors.

The open source IS working.my code does not work properly.it has a flaw i cannot find.i simplified the code for servomotor,whicn can be seen in the 2 codes attached.my code causes right side motors not to work.and changing the code to my version is a must.

Also it does not find any errors.

Just curious, why is that?

a7

Because its a project requirement.i cznnot show up with somebody elses work.

Still not clear what you changed...
Are you expecting me to struggle through and find the 2 differences?

But you can ask here and beg that you are a beginner so some form of do-it-for-me will string out and since you won't get caught it will yours not someone else's?

Is the project for a job or school? Are you trying to make a product for yourself or someone else? Or are you trying to pass a course to get a degree that says you can do what... get free help?

i told you i simplified the code for SG90.i see you are struggling without me expecting anything of you.but it seems you did not see that,just like you did not see the difference in the codes for some reason.

are we staying on topic?i asked for help with the code,not free judgement.if you do not have anything to add,what is the point of writing in here?

What does your sketch write to the Serial monitor?

type orfor (int angle = 90; angle <= 140; angle += 5) {
 servoPulse(servo, angle); }
 for (int angle = 140; angle >= 40; angle-= 5) {
 servoPulse(servo, angle); }
 for (int angle = 40; angle <= 95; angle += 5) {
 servoPulse(servo, angle); }

has been change to

#include <Servo.h> 
SG90.attach(servo);
SG90.write(90);
delay(500);

The changes:
1st code had the servo move on a 90 degrees axis.
2nd code changed that to 60 degrees.(can be seen further down into the codes)
1st code has the servo move when the robot starts,which can show the servo is functioning.
2nd code set it not to move at start at 90degrees.no need to show the servo functioning,because i know its functioning.
1st code used a longer complicated code,
2nd code used #include <Servo.h> which uses PWM instead of servopulse like in the 1st code.
But all this change is for servo and nothing else.But for some reason 2 motors stop working with the 2nd code,which for me makes no sense.

yesterday when i checked it was 1021 1022 1023 or something like that.was showing that the IR sensors are reading well.

But in your code the sensor values MUST be in range 251...800 units as an condition to work the motors.
It seems that your sensors outputs HIGH all the way. It seems that you have a problem with sensor connections.

@MyEyezBurn
I just tested the difference between your both codes by diff. I see you replaced ServoPulse by Servo, change some comments and indexes.
Nothing from that can affects the motors.

I think the problem is not in the code, but in the hardware. Either you connected something incorrectly when assembling the circuit for the second code, or you don't have enough power for the motors, so the new servos consume more than the old ones.

When i switch back to the the open source code it works alright.I also thought it's a hardware problem.but all it need is a code change and it works.this is why this so tricky and i can't understand where the problem is.I didn't change anything in the hardware.i just upload open source code and it works and then when i upload the modified one,right side motors OUT3 OUT4 stop working.makes no sense.

Please test again and show Serial output for both codes

because you try to pass off someone else's code as your own

i just said i'm not doing that.also it's open source and it's accepted and also legal to bring modifications to an open source code.In addition,the original code will be shown in the project along with the modifications and all credit will be given.

You wrote a something complete different above:

This only means that you changed the code to hide that it is "open source code" you found online and want to pass it off as your own.

it means i changed the code because i need to change it ,you cannot take someone elses work and claim to be yours and like i said it's accepted to change something open source and use,as long as you give credit,like i also said i will,which means i'm not hiding and all is legal and accepted.wtf?