Pump is always on even when fire is not detected

I am making a fire fighting robot for my school project. I am using arduino nano with flame sensors. Even when the flame is not detected the pump is on. The pump is powered through a relay module. Please help me . Sorry if I have made any mistake in choosing the catagory for the post. This is my first post. Here's the code:

#include <Wire.h>
#include <Servo.h>

Servo myservo;

#define Left A2
#define Right A1
#define Forward A0
#define LM1 2
#define LM2 3
#define RM1 4
#define RM2 5
#define pump 7

void setup() {
  pinMode(Left, INPUT);
  pinMode(Right, INPUT);
  pinMode(Forward, INPUT);
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
  pinMode(pump, OUTPUT);

  myservo.attach(11);
  myservo.write(90);

  digitalWrite(pump, HIGH); // Initialize pump pin to LOW
}

void sweepServo() {
  for (int pos = 50; pos <= 130; pos += 1) {
    myservo.write(pos);
    delay(10);
  }
  for (int pos = 130; pos >= 50; pos -= 1) {
    myservo.write(pos);
    delay(10);
  }
}

void put_off_fire() {
  digitalWrite(LM1, LOW);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, LOW);
  digitalWrite(RM2, LOW);
  digitalWrite(pump, HIGH);
  sweepServo();  
  digitalWrite(pump, LOW); // Turn off the pump after sweeping
}

void loop() {
  int leftSensor = digitalRead(Left);
  int rightSensor = digitalRead(Right);
  int forwardSensor = digitalRead(Forward);

  if (leftSensor && rightSensor && forwardSensor) {
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, HIGH);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  } else {
    // Stop the motors
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);

    // Adjust movement based on sensor inputs
    if(forwardSensor == HIGH) {
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, HIGH);
      digitalWrite(RM2, LOW);
    }

    if (leftSensor == HIGH) {
      // Turn left
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, LOW);
      digitalWrite(RM2, LOW);
    }

    if (rightSensor == HIGH) {
      // Turn right
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, HIGH);
      digitalWrite(RM1, LOW);
      digitalWrite(RM2, HIGH);
    }
  }

  // Check for fire detection (TO DO: implement fire detection logic)
  // If fire is detected, call put_off_fire() function
  // put_off_fire();
}

Here's the circuit diagram:


Hey guys we recently found a loophole in our project which is when we connect the signal pin of the relay to any digital pins the relay turns on the arduino nano is mounted on a breadboard is that the cause ?
Please help us we are out of time.

Thanks,

Describe how your program will make your project work.

Can you explain what the following should do?

These should be mirrors of each other:

You never call this function:

Could it be this line?

digitalWrite(pump, HIGH); // Initialize pump pin to LOW

We fixed the pump pin to low in the setup

digitalWrite(pump, LOW); // Initialize pump pin to LOW

I applied you suggestion- "These should be mirrors of each other:" We fixed the Sensor part.

 if (leftSensor == HIGH) {
      // Turn left
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, LOW);
      digitalWrite(RM2, LOW);
    }

    if (rightSensor == HIGH) {
      // Turn right
      digitalWrite(LM1, LOW);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, HIGH);
      digitalWrite(RM2, LOW);
    }

Can you explain this part: "You never call this function:"
Thanks for helping,

[Edit]- The code should turn on the pump when flame is detected, there are three flame sensors(Right,Front,Left). I took the code from Youtube. -https://youtu.be/tgW03QJo9lI?si=UtVCyp86iek-Ji-m

I fixed that line.

digitalWrite(pump, LOW); // Initialize pump pin to LOW

Why are the other pins of Arduino Nano which I am not using are giving HIGH output.

I think they are not outputting HIGH. The outputs are floating. Floating means they are neither outputting HIGH or LOW. If you measure them with a multimeter, they might seem to be outputting HIGH or LOW unpredictably.

To test if a pin is outputting HIGH, connect an LED and series resistor between the pin and ground. If the pin is outputting HIGH, the led will light. If it does not light, the pin might be outputting LOW or it could be floating. To find out which of those, 2 possibilities it is, connect the LED and series resistor between Vcc and the pin. If the pin is outputting LOW, the led will light. If it does not light, the pin is floating. (Note: make sure you connect the LED's anode and cathode correctly during these tests. Never change connections in a circuit while the circuit is powered).

That function stops the motors and turns the water pump on. You never turn the pump on to put out the fire.

Now the pump is not working. I think the Nano isnt't giving the HIGH value , when there is flame. Here's the updated code:

#include <Wire.h>
#include <Servo.h>

Servo myservo;

#define Left A2
#define Right A1
#define Forward A0
#define LM1 2
#define LM2 3
#define RM1 4
#define RM2 5
#define pump 7

void setup() {
  pinMode(Left, INPUT);
  pinMode(Right, INPUT);
  pinMode(Forward, INPUT);
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
  pinMode(pump, OUTPUT);

  myservo.attach(11);
  myservo.write(90);

  digitalWrite(pump, LOW); // Initialize pump pin to LOW
}

void sweepServo() {
  for (int pos = 50; pos <= 130; pos += 1) {
    myservo.write(pos);
    delay(10);
  }
  for (int pos = 130; pos >= 50; pos -= 1) {
    myservo.write(pos);
    delay(10);
  }
}

void put_off_fire() {
  digitalWrite(LM1, LOW);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, LOW);
  digitalWrite(RM2, LOW);
  digitalWrite(pump, HIGH);
  sweepServo();  
  digitalWrite(pump, LOW); // Turn off the pump after sweeping
}

void loop() {
  int leftSensor = digitalRead(Left);
  int rightSensor = digitalRead(Right);
  int forwardSensor = digitalRead(Forward);

  if (leftSensor && rightSensor && forwardSensor) {
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, HIGH);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, HIGH);
  } else {
    // Stop the motors
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);

    // Adjust movement based on sensor inputs
    if(forwardSensor == HIGH) {
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, HIGH);
      digitalWrite(RM1, HIGH);
      digitalWrite(RM2, HIGH);
    }

    if (leftSensor == HIGH) {
      // Turn left
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, LOW);
      digitalWrite(RM2, LOW);
    }

    if (rightSensor == HIGH) {
      // Turn right
      digitalWrite(LM1, LOW);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, HIGH);
      digitalWrite(RM2, LOW);
    }
  }

  // Check for fire detection (TO DO: implement fire detection logic)
  // If fire is detected, call put_off_fire() function
  // put_off_fire();
}

Thanks,

Because you do not call the function.

Don't guess or imagine what you think is happening. Test to find out what is truly happening. I explained how to test if a pin is outputting HIGH in my previous post.

Thanks, I think that's the problem, now 'll fix that.