Firefighting car direction from flame sensor

working on firefighting car ,
currently i am on the car movement.
big idea is front sensor triggered car moves forward up until safe distance from the fire.
and left and right will move the car accordingly until front sensor will face the flame.

// Setting Motor A
int enable1Pin = 14;
int motor1Pin1 = 27;
int motor1Pin2 = 26;

//Settin Motor B
int enable2Pin = 32;
int motor2Pin3 = 25;
int motor2Pin4 = 33;

// define pins for flame sensor
//#define FlamePinForawrd 17
#define FlamePinForawrdAnlog 4 
#define FlamePinRight 15
//#define FlamePinLeft 

// pin 13 that connects to the relay to control the pump
#define RELAY_PIN   12 

//pins for siren led and buzzer
//siren
#define LedBlue 2
#define LedRed 21 
#define Buzzer 19



void setup() {
  //modding motor A
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT); 

  //modding Motor B
  pinMode(enable2Pin, OUTPUT);
  pinMode(motor2Pin3, OUTPUT);
  pinMode(motor2Pin4, OUTPUT);

  //setting flame sensor
  //pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinForawrdAnlog, INPUT);
  pinMode(FlamePinRight, INPUT);
  //pinMode(FlamePinLeft, INPUT);


  //setting siren for right
  pinMode(LedBlue, OUTPUT);  //defined port for right leds
  pinMode(LedRed, OUTPUT);
  pinMode(Buzzer, OUTPUT); // port front buzzer

  // initaite serial monitor 
  Serial.begin(9600);

}

void loop() {
   
    //int FlameCheckForawrd = digitalRead(FlamePinForawrd);
    int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
    int FlameCheckRight = digitalRead(FlamePinRight);
    //int FlameCheckLeft = digitalRead(FlamePinLeft);

    ///sensorTest();

    Serial.println(FlameCheckForawrdAnalog);

    if (FlameCheckForawrdAnalog < 2500) 
    {
      Serial.println("flame dected a head");
      //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
      Serial.println(FlameCheckForawrdAnalog);
      CAR_moveForwardWifi();
      // front fire indicated by both siren on
      Serial.println("sirens on");
      sirenOn(LedBlue, LedRed, Buzzer);
      Serial.println("pump on");
      digitalWrite(RELAY_PIN, HIGH);
      delay(500);}
      
      
    
    else if(FlameCheckRight == LOW)
    {
      Serial.println("flame dected on the right");
      Serial.println("turning right");
      CAR_turnRightWifi();
      Serial.println("siren on");
      sirenOn(LedBlue,LedRed, Buzzer);
      //updated front sensor value
      //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
      //Serial.println(FlameCheckForawrdAnalog);

      //if (FlameCheckForawrdAnalog < 2500) 
        //{
          //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
          //Serial.println(FlameCheckForawrdAnalog);
          //Serial.println("sirens off");
          //sirenoff(LedBlue, LedRed, Buzzer);
          //StopCar();
        //}
      delay(100);
        
    }    
    //else if (FlameCheckLeft == LOW)
     //{
      //Serial.println("flame dected on the left");
      //while(FlameCheckForawrd != LOW)
        //{
         //FlameCheckForawrd = digitalRead(FlamePinForawrd);
         //Serial.println("turning left");
         //CAR_turnLeftWifi();
         //delay(200);
        //} 
     //}     
      
    else
     {Serial.println("pump off");
      digitalWrite(RELAY_PIN, LOW);
      Serial.println("sirens off");
      sirenoff(LedBlue, LedRed, Buzzer);
      StopCar();} 
     
    
    
//delay(300);//change this va

}
     
     
// stop car
void StopCar(){
  Serial.println("StopCar");
  analogWrite(enable1Pin,0);
  analogWrite(enable2Pin,0);

  digitalWrite(motor1Pin1,LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3,LOW);
  digitalWrite(motor2Pin4, LOW);
  delay(700);
}

void CAR_moveForwardWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,186);
  analogWrite(enable2Pin,200);
  //move forawrd
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveBackwardWifi() {
  //setting speed motor A and B
  analogWrite(enable1Pin,190);
  analogWrite(enable2Pin,200);
  //back movement
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
}

void CAR_turnLeftWifi() {
    //Set speed motor A and B

  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,0);
  //turn left
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_turnRightWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  //turn right
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void sensorTest() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read "flame" sensors
    }
    Serial.println(); // print the sensor state
    delay(250);
  }
}

//functions for siren 
void sirenOn(int Led1Pin, int Led2Pin,int BuzzerPin)
{
  int i;

  for (int i = 700; i < 800; i++) // duration of the first sound 350 2 millisecond cycles.
    
  {
    tone(BuzzerPin,i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30); 
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

  for(i=800;i>700;i--){
  tone(BuzzerPin,i);
  delay(15);
  digitalWrite(Led1Pin, HIGH); // turn on the leds
  digitalWrite(Led2Pin, LOW);
  delay(30);
  digitalWrite(Led1Pin, LOW); // blinking leds
  digitalWrite(Led2Pin, HIGH);
  delay(30); 
  delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

}

void sirenoff(int Led1Pin, int Led2Pin,int BuzzerPin)
{
    digitalWrite(Led1Pin, LOW); // turn off blinking leds
    digitalWrite(Led2Pin, LOW);

    tone(BuzzerPin,0); // turn off buzzer

}

  

problem is ,even with high low sensitivity ,say on the right sensor,
it takes around 20+ secs for the sensor to stop.
how can i more accurately control the movement?

1 Like

All those arbitrary delays slow down program execution. You need to learn a new programming style.

I suggest to start by studying this excellent Blink Without Delay tutorial.

How does your car perform now?

What is this?

Have you resolved your issues from your previous topic?

not resolved it completely
updated the thread 4 days ago with no responed , so i assumed it was buried.
but i did cut out some components.

now the car will move forward and right when triggered. but it will do it for 20 sec.
which is too much. even when the sensitivity is very close to lowest.

You should not start new topics with the same subject.

As stated in post #2 on this topic, your use of delay() is not allowing the program to proceed. For example; every time "fire" is detected, there are 100 steps of 100ms stopping the program from moving.

You can count all the delay() function times (multiply when in a loop) and you will find your 20 seconds.

Also, as stated in post #2, re-writing your program in the manner of the "blink without delay" will allow you to choose the exact time and duration of the operation of all your devices. Something like this overly-simplified timing list..

  1. Start a motor timer
  2. If "fire" start buzzer timer and buzzer
  3. If "motor move" time, move motor
  4. if "turn servo" time, start turn timer
  5. if "motor stop" time, stop motor
  6. if "buzzer" timeout has expired, stop buzzer
  7. repeat

Compared to your current sketch, which blocks all processing during delay(), the "timed list" allows you to start an event, do other things, check the timer, do other things, stop the event... and repeat.

To get you going in the right direction, here is one of many Programing Electronics Academy posts on managing multiple events.

If you want to tinker with timed events, here is a simulation that you and actively adjust...

Not quite but good that you thought of these devices, too.

The siren goes on between the time you leave the station and turns off just before reaching the fireground. Sirens are very loud and damage hearing as well as interfere with fireground communication (which is the factor that every fireground tactic relies on the most to be a success).

Should be "siren on until close to fire"
then
"siren off and pump on once close enough to hit the fire with a hose/nozzle stream".
The early water thus also serves to protect the equipment (and firefighters) from advancing toward radiant heat.

yeah i didnt want to
but it seemed lost, and new thread got replies almost immedaitly.
not sure how to get an old thread back on the rdaer.

we weren't tahgt this method, i will go over it and give it a try.

good point,
didnt get to the pump part yet
but i will keep that in mind

1 Like

Showing effort or progress.

Consider marketing this to non-smokers as a way to reduce tobacco smoke exposure. If the cigarette doesn't get lit, it won't produce smoke.

// Setting Motor A
int enable1Pin = 14;
int motor1Pin1 = 27;
int motor1Pin2 = 26;

//Settin Motor B
int enable2Pin = 32;
int motor2Pin3 = 25;
int motor2Pin4 = 33;

// define pins for flame sensor
//#define FlamePinForawrd 17
#define FlamePinForawrdAnlog 4 
#define FlamePinRight 15
//#define FlamePinLeft 

// pin 13 that connects to the relay to control the pump
#define RELAY_PIN   12 

//pins for siren led and buzzer
//siren
#define LedBlue 2
#define LedRed 21 
#define Buzzer 19

int FlameCheckForawrdAnalog;
int FlameCheckRight;

const unsigned long SensorReadInterval = 10;
unsigned long previousSensorRead = 0;

const unsigned long eventTime_1Interval = 10;
unsigned long previousTime_1 = 0;


void setup() {
  //modding motor A
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT); 

  //modding Motor B
  pinMode(enable2Pin, OUTPUT);
  pinMode(motor2Pin3, OUTPUT);
  pinMode(motor2Pin4, OUTPUT);

  //setting flame sensor
  //pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinForawrdAnlog, INPUT);
  pinMode(FlamePinRight, INPUT);
  //pinMode(FlamePinLeft, INPUT);


  //setting siren for right
  pinMode(LedBlue, OUTPUT);  //defined port for right leds
  pinMode(LedRed, OUTPUT);
  pinMode(Buzzer, OUTPUT); // port front buzzer

  // initaite serial monitor 
  Serial.begin(9600);


}

void loop() {
   unsigned long currentTime = millis();

   if (currentTime -  previousSensorRead >= SensorReadInterval) {
     //int FlameCheckForawrd = digitalRead(FlamePinForawrd);
     int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
     int FlameCheckRight = digitalRead(FlamePinRight);
     //int FlameCheckLeft = digitalRead(FlamePinLeft);
     Serial.println(FlameCheckForawrdAnalog);


     previousSensorRead = currentTime;

    }
    


    ///sensorTest();

    if (FlameCheckForawrdAnalog < 2500) 
    {
      if(currentTime -  previousTime_1 >= eventTime_1Interval){
        Serial.println("flame dected a head");
        //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
        Serial.println(FlameCheckForawrdAnalog);
        CAR_moveForwardWifi();
        // front fire indicated by both siren on
        Serial.println("sirens on");
        sirenOn(LedBlue, LedRed, Buzzer);
        //Serial.println("pump on");
        //digitalWrite(RELAY_PIN, HIGH);

       previousTime_1 = currentTime;
      }
      
    }
      
      
    
    else if(FlameCheckRight == LOW)
    {
      Serial.println("flame dected on the right");
      Serial.println("turning right");
      CAR_turnRightWifi();
      Serial.println("siren on");
      sirenOn(LedBlue,LedRed, Buzzer);
      //updated front sensor value
      //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
      //Serial.println(FlameCheckForawrdAnalog);

      //if (FlameCheckForawrdAnalog < 2500) 
        //{
          //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
          //Serial.println(FlameCheckForawrdAnalog);
          //Serial.println("sirens off");
          //sirenoff(LedBlue, LedRed, Buzzer);
          //StopCar();
        //}
      delay(2);
    }    
        
    //else if (FlameCheckLeft == LOW)
     //{
      //Serial.println("flame dected on the left");
      //while(FlameCheckForawrd != LOW)
        //{
         //FlameCheckForawrd = digitalRead(FlamePinForawrd);
         //Serial.println("turning left");
         //CAR_turnLeftWifi();
         //delay(200);
        //} 
     //}     
      
    else
     {Serial.println("pump off");
      digitalWrite(RELAY_PIN, LOW);
      Serial.println("sirens off");
      sirenoff(LedBlue, LedRed, Buzzer);
      StopCar();} 
     
    
    
//delay(300);//change this va

}
     
     
// stop car
void StopCar(){
  Serial.println("StopCar");
  analogWrite(enable1Pin,0);
  analogWrite(enable2Pin,0);

  digitalWrite(motor1Pin1,LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3,LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveForwardWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,186);
  analogWrite(enable2Pin,200);
  //move forawrd
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveBackwardWifi() {
  //setting speed motor A and B
  analogWrite(enable1Pin,190);
  analogWrite(enable2Pin,200);
  //back movement
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
}

void CAR_turnLeftWifi() {
    //Set speed motor A and B

  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,0);
  //turn left
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_turnRightWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  //turn right
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void sensorTest() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read "flame" sensors
    }
    Serial.println(); // print the sensor state
    delay(250);
  }
}

//functions for siren 
void sirenOn(int Led1Pin, int Led2Pin,int BuzzerPin)
{
  int i;

  for (int i = 700; i < 800; i++) // duration of the first sound 350 2 millisecond cycles.
    
  {
    tone(BuzzerPin,i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30); 
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

  for(i=800;i>700;i--){
  tone(BuzzerPin,i);
  delay(15);
  digitalWrite(Led1Pin, HIGH); // turn on the leds
  digitalWrite(Led2Pin, LOW);
  delay(30);
  digitalWrite(Led1Pin, LOW); // blinking leds
  digitalWrite(Led2Pin, HIGH);
  delay(30); 
  delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

}

void sirenoff(int Led1Pin, int Led2Pin,int BuzzerPin)
{
    digitalWrite(Led1Pin, LOW); // turn off blinking leds
    digitalWrite(Led2Pin, LOW);

    tone(BuzzerPin,0); // turn off buzzer

}

i changed the code slightly , to test

added time vars for the first if statement line 85

// time vars for flame sensor reading
const unsigned long SensorReadInterval = 10;
unsigned long previousSensorRead = 0;
//time vars for front sensor
const unsigned long eventTime_1Interval = 10;
unsigned long previousTime_1 = 0;

this for sensor reading , line 69

if (currentTime -  previousSensorRead >= SensorReadInterval) {
     //int FlameCheckForawrd = digitalRead(FlamePinForawrd);
     int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
     int FlameCheckRight = digitalRead(FlamePinRight);
     //int FlameCheckLeft = digitalRead(FlamePinLeft);
     Serial.println(FlameCheckForawrdAnalog);


     previousSensorRead = currentTime;

    }

and for front sensor line 85

if (FlameCheckForawrdAnalog < 2500) 
    {
      if(currentTime -  previousTime_1 >= eventTime_1Interval){
        Serial.println("flame dected a head");
        //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
        Serial.println(FlameCheckForawrdAnalog);
        CAR_moveForwardWifi();
        // front fire indicated by both siren on
        Serial.println("sirens on");
        sirenOn(LedBlue, LedRed, Buzzer);
        //Serial.println("pump on");
        //digitalWrite(RELAY_PIN, HIGH);

       previousTime_1 = currentTime;
      }
      
    }

the result is constant right sensor triggered

4095
flame dected on the right
turning right
siren on

i am assuming its because of the brackets in the sensor reading statements.
should i do first read without brackets then one with the timer brackets?
or is it duplicating code?
how else can i overcome it?

when i am dropping them , still front sensor goes for about 20 sec.
with interval of 10ms, then increments of 100 ms until 1800.
its still goes between 15 to 20 sec before stops.

You have commented-out all the "FlamePinLeft" so it will never turn left. My guess is if you enable "Left" your robot will be having a constant race condition where two signal are saying to turn two different directions.

Verify FlamePinRight sensor and FlamePinLeft sensor are ANALOG or DIGITAL.

Match the sensor function. If Digital, use digiralRead(); if Analog, use analogRead();

Match the logic. If DIGITAL, sensor will output HIGH or LOW. If ANALOG, sensor will output 0 to 1023.

i should of clarified
i am testing the front and right, didnt wire the left yet.
the problem wasn't the left , the problem was the robot, no matter flame or not, goes right into the right condition and never goes out of it.
but now that what i get ,even without flame

4095
flame dected a head
0
sirens on
4095
flame dected a head
0
sirens on

right now i am using analog on the front sensor(to control distance) and the other two digital.
should they all be one or the other?

btw, am using the "blink without delay" the right way?

updated
newest code

// Setting Motor A
int enable1Pin = 14;
int motor1Pin1 = 27;
int motor1Pin2 = 26;

//Settin Motor B
int enable2Pin = 32;
int motor2Pin3 = 25;
int motor2Pin4 = 33;

// define pins for flame sensor
//#define FlamePinForawrd 17
#define FlamePinForawrdAnlog 4 
#define FlamePinRight 15
//#define FlamePinLeft 

// pin 13 that connects to the relay to control the pump
#define RELAY_PIN   12 

//pins for siren led and buzzer
//siren
#define LedBlue 2
#define LedRed 21 
#define Buzzer 19

int FlameCheckForawrdAnalog;
int FlameCheckRight;

// time vars for flame sensor reading
const unsigned long SensorReadInterval = 200;
unsigned long previousSensorRead = 0;
//time vars for front sensor trigger
const unsigned long eventTime_1Interval = 200;
unsigned long previousTime_1 = 0;


void setup() {
  //modding motor A
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT); 

  //modding Motor B
  pinMode(enable2Pin, OUTPUT);
  pinMode(motor2Pin3, OUTPUT);
  pinMode(motor2Pin4, OUTPUT);

  //setting flame sensor
  //pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinForawrdAnlog, INPUT);
  pinMode(FlamePinRight, INPUT);
  //pinMode(FlamePinLeft, INPUT);


  //setting siren for right
  pinMode(LedBlue, OUTPUT);  //defined port for right leds
  pinMode(LedRed, OUTPUT);
  pinMode(Buzzer, OUTPUT); // port front buzzer

  // initaite serial monitor 
  Serial.begin(9600);


}

void loop() {
   unsigned long currentTime = millis();
   int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
   int FlameCheckRight = digitalRead(FlamePinRight);

  //  if (currentTime -  previousSensorRead >= SensorReadInterval) {
  //    //int FlameCheckForawrd = digitalRead(FlamePinForawrd);
  //    int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
  //    int FlameCheckRight = digitalRead(FlamePinRight);
  //    //int FlameCheckLeft = digitalRead(FlamePinLeft);
  //    Serial.println(FlameCheckForawrdAnalog);


  //    previousSensorRead = currentTime;

  //   }
    


    ///sensorTest();
   
   if (FlameCheckForawrdAnalog < 2500)
    {
      if(currentTime -  previousTime_1 >= eventTime_1Interval) {
        Serial.println("flame dected a head");
        //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
        Serial.println(FlameCheckForawrdAnalog);
        CAR_moveForwardWifi();
        // front fire indicated by both siren on
        Serial.println("sirens on");
        //sirenOn(LedBlue, LedRed, Buzzer);
        //Serial.println("pump on");
        //digitalWrite(RELAY_PIN, HIGH);

       previousTime_1 = currentTime;
      }
      
    }
      
      
    
   else if(FlameCheckRight == LOW)
    {
      Serial.println("flame dected on the right");
      Serial.println("turning right");
      CAR_turnRightWifi();
      Serial.println("siren on");
      sirenOn(LedBlue,LedRed, Buzzer);
      //updated front sensor value
      //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
      //Serial.println(FlameCheckForawrdAnalog);

      //if (FlameCheckForawrdAnalog < 2500) 
        //{
          //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
          //Serial.println(FlameCheckForawrdAnalog);
          //Serial.println("sirens off");
          //sirenoff(LedBlue, LedRed, Buzzer);
          //StopCar();
        //}
    }    
        
    //else if (FlameCheckLeft == LOW)
     //{
      //Serial.println("flame dected on the left");
      //while(FlameCheckForawrd != LOW)
        //{
         //FlameCheckForawrd = digitalRead(FlamePinForawrd);
         //Serial.println("turning left");
         //CAR_turnLeftWifi();
         //delay(200);
        //} 
     //}     
      
    else
     {Serial.println("pump off");
      digitalWrite(RELAY_PIN, LOW);
      Serial.println("sirens off");
      sirenoff(LedBlue, LedRed, Buzzer);
      StopCar();} 
     
    
    
//delay(300);//change this va

}
     
     
// stop car
void StopCar(){
  Serial.println("StopCar");
  analogWrite(enable1Pin,0);
  analogWrite(enable2Pin,0);

  digitalWrite(motor1Pin1,LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3,LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveForwardWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,186);
  analogWrite(enable2Pin,200);
  //move forawrd
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveBackwardWifi() {
  //setting speed motor A and B
  analogWrite(enable1Pin,190);
  analogWrite(enable2Pin,200);
  //back movement
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
}

void CAR_turnLeftWifi() {
    //Set speed motor A and B

  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,0);
  //turn left
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_turnRightWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  //turn right
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void sensorTest() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read "flame" sensors
    }
    Serial.println(); // print the sensor state
    delay(250);
  }
}

//functions for siren 
void sirenOn(int Led1Pin, int Led2Pin,int BuzzerPin)
{
  int i;

  for (int i = 700; i < 800; i++) // duration of the first sound 350 2 millisecond cycles.
    
  {
    tone(BuzzerPin,i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30); 
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

  for(i=800;i>700;i--){
  tone(BuzzerPin,i);
  delay(15);
  digitalWrite(Led1Pin, HIGH); // turn on the leds
  digitalWrite(Led2Pin, LOW);
  delay(30);
  digitalWrite(Led1Pin, LOW); // blinking leds
  digitalWrite(Led2Pin, HIGH);
  delay(30); 
  delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

}

void sirenoff(int Led1Pin, int Led2Pin,int BuzzerPin)
{
    digitalWrite(Led1Pin, LOW); // turn off blinking leds
    digitalWrite(Led2Pin, LOW);

    tone(BuzzerPin,0); // turn off buzzer

}

changes i made
line 69 commented out.
basically didn't implement "blink without delay" on the sensor reads.
implemented only on the condition of the movement.
line 85.

why wrapping the sensor reading lines in the "blink without delay" method
makes the code goes right into the condition of line 85 and never go back out?

This "analog" input is on a digital pin... use one of the Analog Input (ADC) pins... A0 for example.

#define FlamePinForawrdAnlog 4

You created TWO FlameCheckRight by declaring one GLOBAL and one LOCAL (you do that on many variables in your code).

int FlameCheckRight; // global
.
.
  int FlameCheckRight = digitalRead(FlamePinRight); // local

You never check FlameCheckRight because it is in an "if..else" after an analog reading that is always TRUE (see next problem).

 else if (FlameCheckRight == LOW)

This line will always be TRUE because analog (ADC - analog to digital) range is 0 to 1023

 if (FlameCheckForawrdAnalog < 2500)

This code says "do this and never exit" but is never called.

void sensorTest() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read "flame" sensors
    }
    Serial.println(); // print the sensor state
    delay(250);
  }
}

This code has two totally different "i" variables.

void sirenOn(int Led1Pin, int Led2Pin, int BuzzerPin)
{
  int i;
  for (int i = 700; i < 800; i++) // duration of the first sound 350 2 millisecond cycles.
  {
    tone(BuzzerPin, i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30);
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

  for (i = 800; i > 700; i--) {
    tone(BuzzerPin, i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30);
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }
}

Your car moves to the right because your wiring is incorrect. This code makes the left motor go forward and the right motor go reverse AND you drive the right side faster than the left side.

void CAR_moveForwardWifi() {
  Serial.print("CAR_moveForwardWifi + ");
  //Set speed motor A and B
  analogWrite(enable1Pin, 186);
  analogWrite(enable2Pin, 200);
  //move forawrd
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

There is more to "fix" in your code, but I will stop here with an example and a suggestion.

This simulation shows the enable and direction of the TWO wheels using LEDs. The text describes how the "car" will drive. The motors "drive" for about three seconds for each of eight actions (described in the text).

My suggestion is for you to start over:

  • Make correct pin selections (DIO for 1/0, ADC for 0 - 1023).
  • Configure DIO with INPUT_PULLUP (make code read pins HIGH when NOT active, LOW when ACTIVE), or if you can not do this, use external pulldown resistors (LOW inactive/HIGH active)
  • Practice reading DIO pins to detect 1 and 0
  • Make your car DRIVE as you command (see the simulation in this post)

Here is your code (click to reveal) slightly modified to discover what is (and is not) happening.

sketch.ino
// Setting Motor A
int enable1Pin = 14;
int motor1Pin1 = 27;
int motor1Pin2 = 26;

//Settin Motor B
int enable2Pin = 32;
int motor2Pin3 = 25;
int motor2Pin4 = 33;

// define pins for flame sensor
//#define FlamePinForawrd 17
#define FlamePinForawrdAnlog A0//4
#define FlamePinRight 15
//#define FlamePinLeft

// pin 13 that connects to the relay to control the pump
#define RELAY_PIN   12

//pins for siren led and buzzer
//siren
#define LedBlue 2
#define LedRed 21
#define Buzzer 19
int FlameCheckForawrdAnalog;
int FlameCheckRight;

// time vars for flame sensor reading
const unsigned long SensorReadInterval = 200;
unsigned long previousSensorRead = 0;
//time vars for front sensor trigger
const unsigned long eventTime_1Interval = 200;
unsigned long previousTime_1 = 0;

void setup() {
  //modding motor A
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  //modding Motor B
  pinMode(enable2Pin, OUTPUT);
  pinMode(motor2Pin3, OUTPUT);
  pinMode(motor2Pin4, OUTPUT);
  //setting flame sensor
  //pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinForawrdAnlog, INPUT);
  pinMode(FlamePinRight, INPUT_PULLUP);
  //pinMode(FlamePinLeft, INPUT);

  //setting siren for right
  pinMode(LedBlue, OUTPUT);  //defined port for right leds
  pinMode(LedRed, OUTPUT);
  pinMode(Buzzer, OUTPUT); // port front buzzer
  // initaite serial monitor
  Serial.begin(9600);
}

void loop() {
  unsigned long currentTime = millis();
  int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
  int FlameCheckRight = digitalRead(FlamePinRight);
  //  if (currentTime -  previousSensorRead >= SensorReadInterval) {
  //    //int FlameCheckForawrd = digitalRead(FlamePinForawrd);
  //    int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
  //    int FlameCheckRight = digitalRead(FlamePinRight);
  //    //int FlameCheckLeft = digitalRead(FlamePinLeft);
  //    Serial.println(FlameCheckForawrdAnalog);
  //    previousSensorRead = currentTime;
  //   }

  ///sensorTest();

  if (FlameCheckForawrdAnalog < 2500)
  {
    if (currentTime -  previousTime_1 >= eventTime_1Interval) {
      Serial.print("flame dected ahead + ");
      //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
      Serial.println(FlameCheckForawrdAnalog);
      CAR_moveForwardWifi();
      // front fire indicated by both siren on
      Serial.print("sirens on + ");
      //sirenOn(LedBlue, LedRed, Buzzer);
      //Serial.println("pump on");
      //digitalWrite(RELAY_PIN, HIGH);
      previousTime_1 = currentTime;
    }
  }

  else if (FlameCheckRight == LOW)
  {
    Serial.print("flame detected right + ");
    Serial.print("turning right + ");
    CAR_turnRightWifi();
    Serial.print("siren on + ");
    sirenOn(LedBlue, LedRed, Buzzer);
    //updated front sensor value
    //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
    //Serial.println(FlameCheckForawrdAnalog);
    //if (FlameCheckForawrdAnalog < 2500)
    //{
    //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
    //Serial.println(FlameCheckForawrdAnalog);
    //Serial.println("sirens off");
    //sirenoff(LedBlue, LedRed, Buzzer);
    //StopCar();
    //}
  }

  //else if (FlameCheckLeft == LOW)
  //{
  //Serial.println("flame dected on the left");
  //while(FlameCheckForawrd != LOW)
  //{
  //FlameCheckForawrd = digitalRead(FlamePinForawrd);
  //Serial.println("turning left");
  //CAR_turnLeftWifi();
  //delay(200);
  //}
  //}

  else
  { Serial.println("pump off");
    digitalWrite(RELAY_PIN, LOW);
    Serial.println("sirens off");
    sirenoff(LedBlue, LedRed, Buzzer);
    StopCar();
  }
  //delay(300);//change this va
}

// stop car
void StopCar() {
  Serial.print("StopCar + ");
  analogWrite(enable1Pin, 0);
  analogWrite(enable2Pin, 0);
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveForwardWifi() {
  Serial.print("CAR_moveForwardWifi + ");
  //Set speed motor A and B
  analogWrite(enable1Pin, 186);
  analogWrite(enable2Pin, 200);
  //move forawrd
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveBackwardWifi() {
  Serial.print("CAR_moveBackwardWifi + ");
  //setting speed motor A and B
  analogWrite(enable1Pin, 190);
  analogWrite(enable2Pin, 200);
  //back movement
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
}

void CAR_turnLeftWifi() {
  Serial.print("CAR_turnLeftWifi + ");
  //Set speed motor A and B
  analogWrite(enable1Pin, 255);
  analogWrite(enable2Pin, 0);
  //turn left
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_turnRightWifi() {
  Serial.print("CAR_turnRightWifi + ");
  //Set speed motor A and B
  analogWrite(enable1Pin, 255);
  analogWrite(enable2Pin, 255);
  //turn right
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void sensorTest() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read "flame" sensors
    }
    Serial.println(); // print the sensor state
    delay(250);
  }
}

//functions for siren
void sirenOn(int Led1Pin, int Led2Pin, int BuzzerPin)
{
  int i;
  for (int i = 700; i < 800; i++) // duration of the first sound 350 2 millisecond cycles.
  {
    tone(BuzzerPin, i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30);
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

  for (i = 800; i > 700; i--) {
    tone(BuzzerPin, i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30);
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }
}

void sirenoff(int Led1Pin, int Led2Pin, int BuzzerPin)
{
  digitalWrite(Led1Pin, LOW); // turn off blinking leds
  digitalWrite(Led2Pin, LOW);
  tone(BuzzerPin, 0); // turn off buzzer
}

This file is for the WOKWI simulator (paste into the diagram.json tab)

diagram.json
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-mega", "id": "mega", "top": 10.2, "left": -13.2, "attrs": {} },
    {
      "type": "wokwi-led",
      "id": "led1",
      "top": -116.4,
      "left": 438.6,
      "rotate": 90,
      "attrs": { "color": "limegreen" }
    },
    {
      "type": "wokwi-led",
      "id": "led2",
      "top": -87.6,
      "left": 438.6,
      "rotate": 90,
      "attrs": { "color": "white" }
    },
    {
      "type": "wokwi-led",
      "id": "led3",
      "top": -58.8,
      "left": 438.6,
      "rotate": 90,
      "attrs": { "color": "red" }
    },
    {
      "type": "wokwi-led",
      "id": "led4",
      "top": -116.4,
      "left": 318.2,
      "rotate": 270,
      "attrs": { "color": "limegreen", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led5",
      "top": -87.6,
      "left": 318.2,
      "rotate": 270,
      "attrs": { "color": "white", "flip": "1" }
    },
    {
      "type": "wokwi-led",
      "id": "led6",
      "top": -58.8,
      "left": 318.2,
      "rotate": 270,
      "attrs": { "color": "red", "flip": "1" }
    },
    { "type": "wokwi-potentiometer", "id": "pot1", "top": 85.1, "left": 383.8, "attrs": {} },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": 83,
      "left": 470.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-relay-module",
      "id": "relay1",
      "top": -96.6,
      "left": -32,
      "rotate": 180,
      "attrs": {}
    },
    { "type": "wokwi-vcc", "id": "vcc1", "top": -124.04, "left": 105.6, "attrs": {} },
    {
      "type": "wokwi-led",
      "id": "led7",
      "top": -118.8,
      "left": 195.8,
      "attrs": { "color": "blue" }
    },
    {
      "type": "wokwi-led",
      "id": "led8",
      "top": -118.8,
      "left": 224.6,
      "attrs": { "color": "red" }
    },
    {
      "type": "wokwi-buzzer",
      "id": "bz1",
      "top": -189.6,
      "left": 270.6,
      "attrs": { "volume": "0.1" }
    }
  ],
  "connections": [
    [ "mega:14", "led2:A", "cyan", [ "h1.9", "v-28.8", "h163.2", "v-48" ] ],
    [ "mega:27", "led1:A", "limegreen", [ "v1.05", "h55", "v-124.8" ] ],
    [ "mega:26", "led3:A", "magenta", [ "v10.65", "h84.2", "v-76.8" ] ],
    [ "mega:GND.5", "led1:C", "black", [ "v0.95", "h16.6", "v-268.8" ] ],
    [ "mega:GND.5", "led2:C", "black", [ "v0.95", "h16.6", "v-240" ] ],
    [ "mega:GND.5", "led3:C", "black", [ "v0.95", "h16.6", "v-211.2" ] ],
    [ "mega:GND.5", "led6:C", "black", [ "v0.95", "h16.6", "v-211.2" ] ],
    [ "mega:GND.5", "led5:C", "black", [ "v0.95", "h16.6", "v-240" ] ],
    [ "mega:GND.5", "led4:C", "black", [ "v0.95", "h16.6", "v-268.8" ] ],
    [ "mega:32", "led5:A", "blue", [ "v1.1", "h45.8", "v-124.8" ] ],
    [ "mega:25", "led4:A", "green", [ "v0.95", "h45.4", "v-115.2" ] ],
    [ "mega:33", "led6:A", "purple", [ "v1.1", "h26.2", "v-96" ] ],
    [ "mega:A0", "pot1:SIG", "green", [ "v16.5", "h207.9" ] ],
    [ "mega:GND.3", "pot1:GND", "black", [ "v26.1", "h251.85" ] ],
    [ "mega:5V", "pot1:VCC", "red", [ "v35.7", "h290.3" ] ],
    [ "mega:GND.3", "btn1:2.r", "black", [ "v26.1", "h328.65" ] ],
    [ "btn1:1.r", "mega:15", "green", [ "v-115.2", "h-259" ] ],
    [ "mega:GND.1", "relay1:GND", "black", [ "v0" ] ],
    [ "vcc1:VCC", "relay1:VCC", "red", [ "v0" ] ],
    [ "mega:12", "relay1:IN", "green", [ "v0" ] ],
    [ "mega:2", "led7:A", "green", [ "v0" ] ],
    [ "mega:GND.1", "led7:C", "black", [ "v-86.4", "h105" ] ],
    [ "mega:GND.1", "led8:C", "black", [ "v-86.4", "h133.8" ] ],
    [ "mega:21", "led8:A", "green", [ "v-19.2", "h-74.7" ] ],
    [ "mega:19", "bz1:2", "green", [ "v0" ] ],
    [ "mega:GND.1", "bz1:1", "black", [ "v-86.4", "h182.2" ] ]
  ],
  "dependencies": {}
}

that the datasheet


4 reads analog.
i am getting reading with ranges
0- 4095
12 bits i guess

4095
4095
flame dected on the right
turning right
siren on
4095
4095
4095
4095
4095
4095

the void sensorTest() commented out.
it a code to check which and if the sensor are working.

you can ignore the buzzer code for now (two declared i s)

the left and right turns are fine, the physical wiring were flipped so the code reflect that.

the difference in speed is because one motor works weaker than the other one.so i compensated with the different speeds.

my L298 wont work so i ordered new one, for now i rely on the monitor.

latest code

// Setting Motor A
int enable1Pin = 14;
int motor1Pin1 = 27;
int motor1Pin2 = 26;

//Settin Motor B
int enable2Pin = 32;
int motor2Pin3 = 25;
int motor2Pin4 = 33;

// define pins for flame sensor
//#define FlamePinForawrd 17
#define FlamePinForawrdAnlog 4 
#define FlamePinRight 15
//#define FlamePinLeft 

// pin 13 that connects to the relay to control the pump
#define RELAY_PIN   12 

//pins for siren led and buzzer
//siren
#define LedBlue 2
#define LedRed 21 
#define Buzzer 19

int FlameCheckForawrdAnalog;
int FlameCheckRight;


//time vars for front sensor trigger and movement forward
const unsigned long eventCarMovementInterval = 200;
unsigned long previouseventCarMovement = 0;
//time vars for front sensor trigger and movment left and right 
const unsigned long eventCarSideMovementInterval = 200;
unsigned long previouseventCarSideMovement = 0;
//time vars for siren
const unsigned long eventSirenInterval = 500;
unsigned long previousEventSiren = 0;
//time vars for water pump
const unsigned long eventPumpInterval = 500;
unsigned long previousEventPump = 0;

void setup() {
  //modding motor A
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT); 

  //modding Motor B
  pinMode(enable2Pin, OUTPUT);
  pinMode(motor2Pin3, OUTPUT);
  pinMode(motor2Pin4, OUTPUT);

  //setting flame sensor
  //pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinForawrdAnlog, INPUT);
  pinMode(FlamePinRight, INPUT);
  //pinMode(FlamePinLeft, INPUT);


  //setting siren for right
  pinMode(LedBlue, OUTPUT);  //defined port for right leds
  pinMode(LedRed, OUTPUT);
  pinMode(Buzzer, OUTPUT); // port front buzzer

  // initaite serial monitor 
  Serial.begin(9600);


}

void loop() {
   unsigned long currentTime = millis();

   int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
   int FlameCheckRight = digitalRead(FlamePinRight);
   Serial.println(FlameCheckForawrdAnalog);

  //  if (currentTime -  previousSensorRead >= SensorReadInterval) {
  //    //int FlameCheckForawrd = digitalRead(FlamePinForawrd);
  //    int FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
  //    int FlameCheckRight = digitalRead(FlamePinRight);
  //    //int FlameCheckLeft = digitalRead(FlamePinLeft);
  //    Serial.println(FlameCheckForawrdAnalog);


  //    previousSensorRead = currentTime;

  //   }
    


    ///sensorTest();
    //if (FlameCheckForawrdAnalog < 2500)
   
   if (FlameCheckForawrdAnalog < 4000 && FlameCheckForawrdAnalog > 2000)
    {
      if(currentTime -  previouseventCarMovement >= eventCarMovementInterval) {
        Serial.println("flame dected a head");
        //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
        Serial.println(FlameCheckForawrdAnalog);
        CAR_moveForwardWifi();
        // front fire indicated by both siren on
        Serial.println("sirens on");
        //sirenOn(LedBlue, LedRed, Buzzer);
        //Serial.println("pump on");
        //digitalWrite(RELAY_PIN, HIGH);

       previouseventCarMovement = currentTime;
      }
      if(currentTime -  previousEventSiren >= eventSirenInterval){
        //  siren on
        Serial.println("sirens on");
        //sirenOn(LedBlue, LedRed, Buzzer);
        //sirenOn(LedBlue, LedRed, Buzzer);

        previousEventSiren = currentTime;
      }

      if(currentTime -  previousEventPump >= eventPumpInterval ){
        Serial.println("pump on");
        //digitalWrite(RELAY_PIN, HIGH);
        
        previousEventSiren = currentTime; 
      }

    }
      
      
    
   else if(FlameCheckRight == LOW && !FlameCheckForawrdAnalog < 4000 )
    {
      if(currentTime -  previouseventCarSideMovement >= eventCarSideMovementInterval){
        Serial.println("flame dected on the right");
        Serial.println("turning right");
        CAR_turnRightWifi();
        Serial.println("siren on");
        //sirenOn(LedBlue,LedRed, Buzzer);

        previouseventCarSideMovement = currentTime;
      }
    }    
        
    //else if (FlameCheckLeft == LOW)
     //{
      //Serial.println("flame dected on the left");
      //while(FlameCheckForawrd != LOW)
        //{
         //FlameCheckForawrd = digitalRead(FlamePinForawrd);
         //Serial.println("turning left");
         //CAR_turnLeftWifi();
         //delay(200);
        //} 
     //}     
      
    else
     {Serial.println("pump off");
      digitalWrite(RELAY_PIN, LOW);
      Serial.println("sirens off");
      sirenoff(LedBlue, LedRed, Buzzer);
      StopCar();} 
     
    
    
//delay(300);//change this va

}
     
     
// stop car
void StopCar(){
  Serial.println("StopCar");
  analogWrite(enable1Pin,0);
  analogWrite(enable2Pin,0);

  digitalWrite(motor1Pin1,LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3,LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveForwardWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,186);
  analogWrite(enable2Pin,200);
  //move forawrd
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveBackwardWifi() {
  //setting speed motor A and B
  analogWrite(enable1Pin,190);
  analogWrite(enable2Pin,200);
  //back movement
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
}

void CAR_turnLeftWifi() {
    //Set speed motor A and B

  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,0);
  //turn left
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_turnRightWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  //turn right
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void sensorTest() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read "flame" sensors
    }
    Serial.println(); // print the sensor state
    delay(250);
  }
}

//functions for siren 
void sirenOn(int Led1Pin, int Led2Pin,int BuzzerPin)
{
  int i;

  for (int i = 700; i < 800; i++) // duration of the first sound 350 2 millisecond cycles.
    
  {
    tone(BuzzerPin,i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30); 
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

  for(i=800;i>700;i--){
  tone(BuzzerPin,i);
  delay(15);
  digitalWrite(Led1Pin, HIGH); // turn on the leds
  digitalWrite(Led2Pin, LOW);
  delay(30);
  digitalWrite(Led1Pin, LOW); // blinking leds
  digitalWrite(Led2Pin, HIGH);
  }

}

void sirenoff(int Led1Pin, int Led2Pin,int BuzzerPin)
{
    digitalWrite(Led1Pin, LOW); // turn off blinking leds
    digitalWrite(Led2Pin, LOW);

    tone(BuzzerPin,0); // turn off buzzer

}

how about the last question on post 14?

thats my latest code

// Setting Motor A
int enable1Pin = 14;
int motor1Pin1 = 27;
int motor1Pin2 = 26;

//Settin Motor B
int enable2Pin = 32;
int motor2Pin3 = 25;
int motor2Pin4 = 33;

// define pins for flame sensor
//#define FlamePinForawrd 17
#define FlamePinForawrdAnlog 4 
#define FlamePinRight 15
//#define FlamePinLeft 

// define pins for gas sensor
#define GasSensorDi 17

// pin 13 that connects to the relay to control the pump
#define RELAY_PIN   12 

//pins for siren led and buzzer
//siren
#define LedBlue 2
#define LedRed 21 
#define Buzzer 19

//vars for falme sensor read
int FlameCheckForawrdAnalog;
int FlameCheckRight;

//vars for gas sensor read
int GasSensorD;
int three60forward = 0;//var for 360 turn 


//time vars for front sensor trigger and movement forward
const unsigned long eventCarMovementInterval = 200;
unsigned long previouseventCarMovement = 0;
//time vars for front sensor trigger and movment left and right 
const unsigned long eventCarSideMovementInterval = 200;
unsigned long previouseventCarSideMovement = 0;
//time vars for siren
const unsigned long eventSirenInterval = 500;
unsigned long previousEventSiren = 0;
//time vars for water pump
const unsigned long eventPumpInterval = 500;
unsigned long previousEventPump = 0;
//var for movement forward on the gas condition
const unsigned long eventCarMovementGasInterval = 2500;
unsigned long previouseventGasCarMovement = 0;

void setup() {
  //modding motor A
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT); 

  //modding Motor B
  pinMode(enable2Pin, OUTPUT);
  pinMode(motor2Pin3, OUTPUT);
  pinMode(motor2Pin4, OUTPUT);

  //setting flame sensor as input
  //pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinForawrdAnlog, INPUT);
  pinMode(FlamePinRight, INPUT);
  //pinMode(FlamePinLeft, INPUT);

  //setting gas sensor as input
  pinMode(GasSensorDi,INPUT);

  //setting siren for right
  pinMode(LedBlue, OUTPUT);  //defined port for right leds
  pinMode(LedRed, OUTPUT);
  pinMode(Buzzer, OUTPUT); // port front buzzer

  // initaite serial monitor 
  Serial.begin(9600);


}

void loop() {
   unsigned long currentTime = millis();
   //vars for storing flame sensor vlaues
   FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
   FlameCheckRight = digitalRead(FlamePinRight);
   Serial.println(FlameCheckForawrdAnalog);
   //vars for storing gas sensor vlaues
   GasSensorD=digitalRead(GasSensorDi);


    ///sensorTest();
   
   if ((FlameCheckForawrdAnalog < 4090) || (FlameCheckForawrdAnalog > 3500))
    {
      if(currentTime -  previouseventCarMovement >= eventCarMovementInterval) {
        Serial.println("flame dected a head");
        //FlameCheckForawrdAnalog = analogRead(FlamePinForawrdAnlog);
        Serial.println(FlameCheckForawrdAnalog);
        CAR_moveForwardWifi();
        

        previouseventCarMovement = currentTime;
      }
      if(currentTime -  previousEventSiren >= eventSirenInterval){
        //  siren on
        Serial.println("sirens on");
        //sirenOn(LedBlue, LedRed, Buzzer);

        previousEventSiren = currentTime;
      }
    }

      if(FlameCheckForawrdAnalog < 2500 ){//turn pump while in front sensor triggred
         if(currentTime -  previousEventPump >= eventPumpInterval ){
          Serial.println("pump on");
          //digitalWrite(RELAY_PIN, HIGH);
        
          previousEventSiren = currentTime; 
        } 
    }
   else if(FlameCheckRight == LOW && !FlameCheckForawrdAnalog < 4000 )
    {
      if(currentTime -  previouseventCarSideMovement >= eventCarSideMovementInterval){
        Serial.println("flame dected on the right");
        Serial.println("turning right");
        CAR_turnRightWifi();
        Serial.println("siren on");
        //sirenOn(LedBlue,LedRed, Buzzer);

        previouseventCarSideMovement = currentTime;
      }
    }    
        
    //else if (FlameCheckLeft == LOW)
     //{
      //Serial.println("flame dected on the left");
      //while(FlameCheckForawrd != LOW)
        //{
         //FlameCheckForawrd = digitalRead(FlamePinForawrd);
         //Serial.println("turning left");
         //CAR_turnLeftWifi();
         //delay(200);
        //} 
     //} 

   else if(GasSensorD == LOW && !FlameCheckForawrdAnalog < 4000){
        if(currentTime -  previousEventSiren >= eventSirenInterval){
          //  siren on
          Serial.println("sirens on");
          //sirenOn(LedBlue, LedRed, Buzzer);

          previousEventSiren = currentTime;}
        if(three60forward < 20){
            Serial.println("gas dected ,looking around for fire");
            Serial.println("turning right");
            Serial.println(three60forward);
            CAR_turnRightWifi();
            three60forward++;}
        else{
           {Serial.println("move forawrd");
            CAR_moveForwardWifi();
            delay(1000);}
            three60forward = 0;}
   }   
       
   else
     {Serial.println("pump off");
      digitalWrite(RELAY_PIN, LOW);
      Serial.println("sirens off");
      sirenoff(LedBlue, LedRed, Buzzer);
      StopCar();} 
     
   }

     
     
// stop car
void StopCar(){
  Serial.println("StopCar");
  analogWrite(enable1Pin,0);
  analogWrite(enable2Pin,0);

  digitalWrite(motor1Pin1,LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3,LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveForwardWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,186);
  analogWrite(enable2Pin,200);
  //move forawrd
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_moveBackwardWifi() {
  //setting speed motor A and B
  analogWrite(enable1Pin,190);
  analogWrite(enable2Pin,200);
  //back movement
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
}

void CAR_turnLeftWifi() {
    //Set speed motor A and B

  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,0);
  //turn left
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
}

void CAR_turnRightWifi() {
  //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  //turn right
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
}

void sensorTest() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read "flame" sensors
    }
    Serial.println(); // print the sensor state
    delay(250);
  }
}

//functions for siren 
void sirenOn(int Led1Pin, int Led2Pin,int BuzzerPin)
{
  int i;

  for (int i = 700; i < 800; i++) // duration of the first sound 350 2 millisecond cycles.
    
  {
    tone(BuzzerPin,i);
    delay(15);
    digitalWrite(Led1Pin, HIGH); // turn on the leds
    digitalWrite(Led2Pin, LOW);
    delay(30);
    digitalWrite(Led1Pin, LOW); // blinking leds
    digitalWrite(Led2Pin, HIGH);
    delay(30); 
    delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

  for(i=800;i>700;i--){
  tone(BuzzerPin,i);
  delay(15);
  digitalWrite(Led1Pin, HIGH); // turn on the leds
  digitalWrite(Led2Pin, LOW);
  delay(30);
  digitalWrite(Led1Pin, LOW); // blinking leds
  digitalWrite(Led2Pin, HIGH);
  delay(30); 
  delay(15); // wait 1 millisecond and restart from the for statement (100 repetitions)
  }

}

void sirenoff(int Led1Pin, int Led2Pin,int BuzzerPin)
{
    digitalWrite(Led1Pin, LOW); // turn off blinking leds
    digitalWrite(Led2Pin, LOW);

    tone(BuzzerPin,0); // turn off buzzer

}

in line 96 the car should move forward in between these values
if ((FlameCheckForawrdAnalog < 4090) || (FlameCheckForawrdAnalog > 3500))
but in practise it move even after the lower bound

34
pump on
32
pump on
80
flame dected a head
80
pump on
79
pump on
81
pump on
83
pump on
89
pump on

the flame detect a head line = forward movement.
the goal is the moves ,stops before the fire and then intiatate the water pump until no fire detect.

anything below this 4090, even 0, or above 3500, to infinity, will go forward. "bound" the two values (3500 and 4090) with && between the conditions.

I updated this simulation with the "&&" change. Much more needs fixing.

changed it to &&

StopCar
2707
pump off
sirens off
StopCar
2583
pump off
sirens off
StopCar
2559
pump off
sire

the value are between 4000 and 3500
but the car wont move, it goes the last else statement
line 170

else
     {Serial.println("pump off");
      digitalWrite(RELAY_PIN, LOW);
      Serial.println("sirens off");
      sirenoff(LedBlue, LedRed, Buzzer);
      StopCar();}

That's what you wanted.

The working code is in the simulation in Post #18. The fire is out, or was never there. Your problem two posts ago was that the car would not stop. State your goal. Describe everything that works. Describe everything that does not work. Stop being a moving target. Post your working code, or the code that is not working and describe everything right and wrong with it.