Car movement distance control with flame sensor

i a testing this 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 FlamePinForawrd 15 
#define RELAY_PIN   12  // pin 13 that connects to the relay to control the pump


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);


  pinMode(FlamePinForawrd, INPUT);

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

}

void loop() {
   
    int FlameCheckForawrd = digitalRead(FlamePinForawrd);

    if (FlameCheckForawrd == LOW) 
    {
     Serial.println("flame dected");
     MoveForward();
     digitalWrite(RELAY_PIN, HIGH);
     delay(400);
    }
    else if(FlameCheckForawrd == HIGH)
    {
     Serial.println("no flame dected");
     StopCar();
     digitalWrite(RELAY_PIN, LOW);
     delay(400);
    }
     
     
    
    
    //else if (digitalRead(Left) ==0)
    ///{TurnRight();}
    
    //else if (digitalRead(Right) ==0) 
    ///{TurnLeft();}
    
//delay(300);//change this va

}


//move forward
void MoveForward(){
  Serial.println("MoveForward");
  //Set speed motor A and B
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear(); 
}

//move backward
void MoveBackward(){
  Serial.println("MoveBackward");
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
  //lcd.clear();
  delay(700);
}

//turn car left
void TurnLeft(){
  Serial.println("TurnLeft");
   //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  StopCar();
}


//turn car  right 
void TurnRight(){
  Serial.println("TurnRight");
   //turn right
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  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);
  delay(700);
}

how can i distance control from the flame
sp the car wont keep running into the flame?

Please stop creating topics then deleting them

Post a link to the specifications of your flame sensors. Maybe they have both an analog and a digital output. Using the analog output, connected to an Arduino analog input, your code may be able to know the brightness of the flame, which will increase as the car gets closer to the source of the flame.

sorry i dont know how to erase the thread completely

this one

in my code i am trying a left turning of the car ,but i dont get a responses on the left sensor.
i tested the sensor on its own and it works.

here is the code so far

// 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 FlamePinForawrd 15 
#define FlamePinLeft 17 

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


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);


  pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinLeft, INPUT);

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

}

void loop() {
   
    int FlameCheckForawrd = digitalRead(FlamePinForawrd);
    int FlameCheckLeft = digitalRead(FlamePinLeft);

    if (FlameCheckForawrd == LOW) 
    {
     Serial.println("flame dected");
     MoveForward();
     digitalWrite(RELAY_PIN, HIGH);
     delay(400);
    }
    else if(FlameCheckForawrd == HIGH)
    {
     Serial.println("no flame dected");
     StopCar();
     digitalWrite(RELAY_PIN, LOW);
     delay(400);
    }
    else if(FlameCheckLeft == LOW)
    {
     Serial.println("flame dected on the left");
     while(FlameCheckForawrd == HIGH)
      {Serial.println("turning left");
       CAR_turnLeftWifi();}
     StopCar();
     digitalWrite(RELAY_PIN,HIGH);
     delay(400);
     } 
     
     
     
        //else if (digitalRead(Left) ==0)
    ///{TurnRight();}
    
    //else if (digitalRead(Right) ==0) 
    ///{TurnLeft();}
    
//delay(300);//change this va

}
     
     
    
    



//move forward
void MoveForward(){
  Serial.println("MoveForward");
  //Set speed motor A and B
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear(); 
}

//move backward
void MoveBackward(){
  Serial.println("MoveBackward");
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
  //lcd.clear();
  delay(700);
}

//turn car left
void TurnLeft(){
  Serial.println("TurnLeft");
   //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  StopCar();
}


//turn car  right 
void TurnRight(){
  Serial.println("TurnRight");
   //turn right
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  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);
  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);
}

Hi,
What model Arduino are you using?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

disregard the code.

the center flame sensor is pin 15 and the left is 17 (the wokwi doesnt have flame sensor)

so i change the code since last time, realised the problem with the third condition.
that the new one

// 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 FlamePinForawrd 15 
#define FlamePinRight 17 

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


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);


  pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinRight, INPUT);

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

}

void loop() {
   
    int FlameCheckForawrd = digitalRead(FlamePinForawrd);
    int FlameCheckRight = digitalRead(FlamePinRight);

    if (FlameCheckForawrd == LOW) 
    {
      while(FlameCheckForawrd == LOW){
        Serial.println("flame dected");
        MoveForward();
        digitalWrite(RELAY_PIN, HIGH);
        delay(400);
        }
    }
    
    else if(FlameCheckRight == LOW)
    {
      Serial.println("flame dected on the right");
      while(FlameCheckForawrd == HIGH)
        {Serial.println("turning right");
         CAR_turnRightWifi();
        } 
        
    } 
     
    else
     {StopCar();} 

     
     
     
     
        //else if (digitalRead(Left) ==0)
    ///{TurnRight();}
    
    //else if (digitalRead(Right) ==0) 
    ///{TurnLeft();}
    
//delay(300);//change this va

}
     
     
    
    



//move forward
void MoveForward(){
  Serial.println("MoveForward");
  //Set speed motor A and B
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear(); 
}

//move backward
void MoveBackward(){
  Serial.println("MoveBackward");
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
  //lcd.clear();
  delay(700);
}

//turn car left
void TurnLeft(){
  Serial.println("TurnLeft");
   //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  StopCar();
}


//turn car  right 
void TurnRight(){
  Serial.println("TurnRight");
   //turn right
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  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);
  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);
}

my problem is when the car turning right,
and the flame is in front the center flame sensor the car wont stop.
in the second
else if
the while(FlameCheckForawrd == HIGH).

Ok, as I mentioned, you can connect the A0 pin of this type of sensor to an Arduino analog pin. The Arduino can read the intensity level output by the sensor. This will probably not give an accurate estimate of the distance to the flame, but might be good enough to sense "need to get closer to flame" and "must not get any closer to flame" levels.

This is the flaw in your coding. When the code enters the while-loop, it will remain in the loop forever. This is because FlameCheckForawrd is not updated by any code inside the while-loop. The same thing will happen for the other while-loop.

You could read the FlamePinForawrd pin again inside the while-loop and update FlameCheckForawrd. However, if you continue to use this method, it will make your code messy and repetitive and before long you will find you can no longer find and fix errors in the code because it is too long and untidy.

My advice would be not to use while-loops like this. Let loop() itself be your only loop. In order to do this you will need to learn about "state machines".

i am trying to make (in this case) a right turn, so the front sensor will face the flame.
i tried with condition on the front sensor, turn right until front sensor triggered.

i guess i can estimate the time for the front sensor to face ahead with the delay function.
is there any modification i can do with the code or is it just "state machines"?

i did this instead

void loop() {
   
    int FlameCheckForawrd = digitalRead(FlamePinForawrd);
    int FlameCheckRight = digitalRead(FlamePinRight);

    if (FlameCheckForawrd == LOW) 
    {
      
      Serial.println("flame dected");
      MoveForward();
      digitalWrite(RELAY_PIN, HIGH);
      delay(400);
    }    
         
      
    
    
    else if(FlameCheckRight == LOW)
    {
      Serial.println("flame dected on the right");
      while(FlameCheckForawrd != LOW)
        {
         FlameCheckForawrd = digitalRead(FlamePinForawrd);
         Serial.println("turning right");
         CAR_turnRightWifi();
         delay(200);
        } 
    }    
      
        
     
     
    else
     {StopCar();} 

     
     
     
     
    //else if (digitalRead(Left) ==0)
    ///{TurnRight();}
    
    //else if (digitalRead(Right) ==0) 
    ///{TurnLeft();}
    
//delay(300);//change this va

}

the plan is one more for left turn.
will it still be too messy?
the overall plan is recoginizing the flame direction, getting close then put it out.

How will your code know the direction, if your two sensors only return HIGH or LOW?

if the right sensor trigrred the car will turn right untill front sensor is in the front .
same for the left, what i am missing?

also i am trying this 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 FlamePinForawrd 15 
#define FlamePinRight 17 
#define FlamePinLeft 16 

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


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);


  pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinRight, INPUT);
  pinMode(FlamePinLeft, INPUT);

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

}

void loop() {
   
    int FlameCheckForawrd = digitalRead(FlamePinForawrd);
    int FlameCheckRight = digitalRead(FlamePinRight);
    int FlameCheckLeft = digitalRead(FlamePinLeft);

    if (FlameCheckForawrd == LOW) 
    {
      
      Serial.println("flame dected ahead");
      MoveForward();
      digitalWrite(RELAY_PIN, HIGH);
      delay(400);
    }    
    else if(FlameCheckRight == LOW)
    {
      Serial.println("flame dected on the right");
      while(FlameCheckForawrd != LOW)
        {
         FlameCheckForawrd = digitalRead(FlamePinForawrd);
         Serial.println("turning right");
         CAR_turnRightWifi();
         delay(200);
        } 
    }    
    else if (FlameCheckLeft == LOW)
     {
      Serial.println("flame dected on the left");
      while(FlameCheckForawrd != LOW)
        {
         FlameCheckForawrd = digitalRead(FlamePinForawrd);
         Serial.println("turning right");
         CAR_turnRightWifi();
         delay(200);
        } 
     }     
      
    else
     {StopCar();} 
    
    
//delay(300);//change this va

}
     
     
    
    



//move forward
void MoveForward(){
  Serial.println("MoveForward");
  //Set speed motor A and B
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear(); 
}

//move backward
void MoveBackward(){
  Serial.println("MoveBackward");
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
  //lcd.clear();
  delay(700);
}

//turn car left
void TurnLeft(){
  Serial.println("TurnLeft");
   //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  StopCar();
}


//turn car  right 
void TurnRight(){
  Serial.println("TurnRight");
   //turn right
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  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);
  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);
}

and getting


there is no flame presence but it seems stuck on the while loop

while(FlameCheckForawrd != LOW)
        {
         FlameCheckForawrd = digitalRead(FlamePinForawrd);
         Serial.println("turning right");
         CAR_turnRightWifi();
         delay(200);
        } 

It is stuck in the loop because there is no flame presence!

If there is no flame presence, how did it get into the if statement that is before the loop? Are the sensors adjusted differently, so that the left sensor detected the flame but the forward sensor does not?

What do the led indicators on the sensors tell you?

they are about the same.
the flame led is off on both ,there is no flame.

i dont get how it got to the while statement either, its starting from there.

when i put a flame in front the front sensor i get

Hi,
Are all the switch indicators OFF?
Power indicator show be ON.
image
Do you have a DMM? (Digital MultiMeter)

PLEASE reverse engineer YOUR circuit and post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you post some images of your project?
So we can see your component layout.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

i dont have Digital MultiMeter.

you can ignore the servo and the sr04
in this code i am testing just the flame sensor and motor driver.


and the 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 FlamePinForawrd 15 
#define FlamePinRight 17 
#define FlamePinLeft 16 

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


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);


  pinMode(FlamePinForawrd, INPUT);
  pinMode(FlamePinRight, INPUT);
  pinMode(FlamePinLeft, INPUT);

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

}

void loop() {
   
    int FlameCheckForawrd = digitalRead(FlamePinForawrd);
    int FlameCheckRight = digitalRead(FlamePinRight);
    int FlameCheckLeft = digitalRead(FlamePinLeft);

    if (FlameCheckForawrd == LOW) 
    {
      
      Serial.println("flame dected ahead");
      MoveForward();
      digitalWrite(RELAY_PIN, HIGH);
      delay(400);
    }    
    else if(FlameCheckRight == LOW)
    {
      Serial.println("flame dected on the right");
      while(FlameCheckForawrd != LOW)
        {
         FlameCheckForawrd = digitalRead(FlamePinForawrd);
         Serial.println("turning right");
         CAR_turnRightWifi();
         delay(200);
        } 
    }    
    else if (FlameCheckLeft == LOW)
     {
      Serial.println("flame dected on the left");
      while(FlameCheckForawrd != LOW)
        {
         FlameCheckForawrd = digitalRead(FlamePinForawrd);
         Serial.println("turning right");
         CAR_turnRightWifi();
         delay(200);
        } 
     }     
      
    else
     {StopCar();} 
    
    
//delay(300);//change this va

}
     
     
    
    



//move forward
void MoveForward(){
  Serial.println("MoveForward");
  //Set speed motor A and B
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear(); 
}

//move backward
void MoveBackward(){
  Serial.println("MoveBackward");
  analogWrite(enable1Pin,178);
  analogWrite(enable2Pin,195);
  
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, HIGH);
  //lcd.clear();
  delay(700);
}

//turn car left
void TurnLeft(){
  Serial.println("TurnLeft");
   //Set speed motor A and B
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin3, LOW);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  StopCar();
}


//turn car  right 
void TurnRight(){
  Serial.println("TurnRight");
   //turn right
  analogWrite(enable1Pin,255);
  analogWrite(enable2Pin,255);
  
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin3, HIGH);
  digitalWrite(motor2Pin4, LOW);
  //lcd.clear();
  delay(625);

  //Stop motor for half second
  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);
  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);
}

Add this function:

void sensorTest() {
  while (1) { // never leave this test
    for (int i = 0; i < 3; i++) {
      Serial.print(digitalRead(i + 15)); // read 3 "flame" sensors and print it
    }
    Serial.println();
    delay(250);
  }
}

Add this line to loop():

void loop() {
  sensorTest();

You should get a printout in your serial monitor showing three digits, representing what your flame sensors indicate.

When you are done using the test, remove the function call in loop()

Which flame sensors do you test and what do you observe?

without a flame
image

with flame in the right sensor
image
and flame in the front sensor
image

right sensor wont go below 100 no matter the adjusment