ishkapoor2000 / FIRE_FIGHTING_AUTOMATED_ROBOT

This is the official repository of the Fire Fighting Robot under Chimi Changa (Robotics Club).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GPT based improved void loop()

ishkapoor2000 opened this issue · comments

https://github.com/ishkapoor2000/FIRE_FIGHTING_AUTOMATED_ROBOT/blob/7d8e8483495787b24fd74818dd31fd6306959859/_MODIFIED____ARDUINO_OBSTACLE_FIRE_FIGHTING_BOT/_MODIFIED____ARDUINO_OBSTACLE_FIRE_FIGHTING_BOT.ino#LL51

@kuwarkapur @ankitkumar174

void loop() {
  delay(40);

  // Read the distance from the ultrasonic sensor
  distance = readPing();

  // Check if there is an obstacle within 8 cm
  if (distance <= 8) {
    Serial.println(distance);

    // Stop the robot
    moveStop();
    delay(100);

    // Read the flame sensor and map the reading to a range of 0-3
    sensorReading = analogRead(A0);
    int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

    if (range == 0) {
      // Extinguish the fire
      Serial.println("Flame");
      moveStop();
      fire_ex();
      delay(500);
    } else {
      // Move backward and look left and right to determine which direction to turn
      moveBackward();
      delay(300);
      moveStop();
      delay(200);
      int distanceR = lookRight();
      delay(200);
      int distanceL = lookLeft();
      delay(200);

      // Turn in the direction with the most clearance
      if (distanceR >= distanceL) {
        turnRight();
        moveStop();
      } else {
        turnLeft();
        moveStop();
      }
    }
  } else {
    // Move forward
    Serial.println(distance);
    moveForward();
  }
}