Elegoo Smart car. How do I change turn behaviour

Hello

I have a Elegoo Smart car with a built in code
Attached

Its working fine except the turn is very exaggerated. On turning left or right it turns almost a full 180 degrees.

Looking at this script I can't see how to change this.

Any advice greatly received

/*
 * @Description: In User Settings Edi
 * @Author: your name
 * @Date: 2019-08-12 18:00:25
 * @LastEditTime: 2019-08-27 10:45:29
 * @LastEditors: Please set LastEditors
 */
#include <IRremote.h>
#include <Servo.h>
#include <stdio.h>
#include "HardwareSerial.h"
#include "ArduinoJson-v6.11.1.h" //Use ArduinoJson Libraries

#define f 16736925    // FORWARD
#define b 16754775    // BACK
#define l 16720605    // LEFT
#define r 16761405    // RIGHT
#define s 16712445    // STOP
#define KEY1 16738455 //Line Teacking mode
#define KEY2 16750695 //Obstacles Avoidance mode

#define KEY_STAR 16728765
#define KEY_HASH 16732845

/*Arduino pin is connected to the IR Receiver*/
#define RECV_PIN 12

/*Arduino pin is connected to the Ultrasonic sensor module*/
#define ECHO_PIN A4
#define TRIG_PIN A5
const int ObstacleDetection = 35;

/*Arduino pin is connected to the Motor drive module*/
#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11

#define LED_Pin 13

/*Arduino pin is connected to the IR tracking module*/
#define LineTeacking_Pin_Right 10
#define LineTeacking_Pin_Middle 4
#define LineTeacking_Pin_Left 2

#define LineTeacking_Read_Right !digitalRead(10) //Right
#define LineTeacking_Read_Middle !digitalRead(4) //Middle
#define LineTeacking_Read_Left !digitalRead(2)   //Left

#define carSpeed 180 //PWM(Motor speed/Speed)

unsigned int carSpeed_rocker = 250;
#define PIN_Servo 3
Servo servo;             //  Create a DC motor drive object
IRrecv irrecv(RECV_PIN); //  Create an infrared receive drive object
decode_results results;  //  Create decoding object

unsigned long IR_PreMillis;
unsigned long LT_PreMillis;

int rightDistance = 0;  //Right distance
int leftDistance = 0;   //left Distance
int middleDistance = 0; //middle Distance

/*DIY_MotorControl: Motor Control: Motor Speed、Motor Direction、Motor Time*/
uint8_t DIY_MotorSelection;
uint8_t DIY_MotorDirection;

uint16_t DIY_MotorSpeed;
unsigned long DIY_leftMotorControl_Millis;
unsigned long DIY_rightMotorControl_Millis;

/*DIY_CarControl: Car Control:Car moving direction、Car Speed、Car moving time*/
uint8_t DIY_CarDirection;
uint8_t DIY_CarSpeed;
uint16_t DIY_CarTimer;
unsigned long DIY_CarControl_Millis;

uint8_t DIY_CarDirectionxxx;
uint8_t DIY_CarSpeedxxx;
uint16_t DIY_Distance;

String CommandSerialNumber; //

enum SERIAL_mode
{
  Serial_rocker,
  Serial_programming,
  Serial_diy,
} Serial_mode = Serial_programming;

enum FUNCTIONMODE
{
  IDLE,                  /*free*/
  LineTeacking,          /*Line Teacking Mode*/
  ObstaclesAvoidance,    /*Obstacles Avoidance Mode*/
  Bluetooth,             /*Bluetooth Control Mode*/
  IRremote,              /*Infrared Control Mode*/
  DIY_MotorControl,      /*Motor Control Mode*/
  DIY_CarControl,        /*Car Control Mode*/
  DIY_CarControlxxx,     /*Car Control Mode*/
  DIY_ClearAllFunctions, /*Clear All Functions Mode*/
} func_mode = IDLE;      /*Functional mode*/

enum MOTIONMODE
{
  STOP,            /*stop*/
  FORWARD,         /*forward*/
  BACK,            /*back*/
  LEFT,            /*left*/
  RIGHT            /*right*/
} mov_mode = STOP; /*move mode*/

void delays(unsigned long t)
{
  for (unsigned long i = 0; i < t; i++)
  {
    getBTData_Plus(); //Bluetooth Communication Data Acquisition
    getIRData();      //Infrared Communication Data Acquisition
    delay(1);
  }
}
/*ULTRASONIC*/
unsigned int getDistance(void)
{ //Getting distance
  static unsigned int tempda = 0;
  unsigned int tempda_x = 0;
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  tempda_x = ((unsigned int)pulseIn(ECHO_PIN, HIGH) / 58);
  tempda = tempda_x;
  // if (tempda_x < 150)
  // {
  //   tempda = tempda_x;
  // }
  // else
  // {
  //   tempda = 30;
  // }
  return tempda;
  //return tempda_x;
}
/*
  Control motor:Car movement forward
*/
void forward(bool debug, int16_t in_carSpeed)
{
  analogWrite(ENA, in_carSpeed);
  analogWrite(ENB, in_carSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  if (debug)
    Serial.println("Go forward!");
}
/*
  Control motor:Car moving backwards
*/
void back(bool debug, int16_t in_carSpeed)
{
  analogWrite(ENA, in_carSpeed);
  analogWrite(ENB, in_carSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  if (debug)
    Serial.println("Go back!");
}
/*
  Control motor:The car turns left and moves forward
*/
void left(bool debug, int16_t in_carSpeed)
{

  analogWrite(ENA, in_carSpeed);
  analogWrite(ENB, in_carSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);

  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  if (debug)
    Serial.println("Go left!");
}
/*
  Control motor:The car turns right and moves forward
*/
void right(bool debug, int16_t in_carSpeed)
{
  analogWrite(ENA, in_carSpeed);
  analogWrite(ENB, in_carSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  if (debug)
    Serial.println("Go right!");
}
/*
  Stop motor control:Turn off the motor drive
*/
void stop(bool debug = false)
{
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
  if (debug)
    Serial.println("Stop!");
}
/*
  Bluetooth serial port data acquisition and control command parsing
*/
void getBTData_Plus(void)
{
  String comdata = "";

  while ((Serial.available() > 0) && (false == comdata.endsWith("}")))
  {
    if (Serial_mode == Serial_rocker)
    {
      comdata += char(Serial.read());
      delay(3);
    }
    else if (Serial_mode == Serial_programming)
    {
      comdata += char(Serial.read());
      delay(6);
    }
    else if (Serial_mode == Serial_diy)
    {
      comdata += char(Serial.read());
      delay(6);
    }
  }
  if ((comdata.length() > 0) && (comdata != "") && (true == comdata.endsWith("}")))
  {
    StaticJsonDocument<200> doc;                                //Create a JsonDocument object
    DeserializationError error = deserializeJson(doc, comdata); //Deserialize JSON data
    if (!error)                                                 //Check if deserialization is successful
    {
      int control_mode_N = doc["N"];
      char buf[3];
      uint8_t temp = doc["H"];
      sprintf(buf, "%d", temp);
      CommandSerialNumber = buf; //Get the serial number of the new command
      switch (control_mode_N)
      {
      case 21: /*Ultrasonic module  processing <command:N 21>*/
        Serial_mode = Serial_programming;
        DIY_UltrasoundModuleStatus_Plus(doc["D1"]);
        break;
      case 22: /*Trace module data processing <command:N 22>*/
        Serial_mode = Serial_programming;
        DIY_TraceModuleStatus_Plus(doc["D1"]);
        break;
      case 1: /*Motion module  processing <command:N 1>*/
        Serial_mode = Serial_programming;
        func_mode = DIY_MotorControl;
        DIY_MotorSelection = doc["D1"];
        DIY_MotorDirection = doc["D2"];
        DIY_MotorSpeed = doc["D3"];
        Serial.print('{' + CommandSerialNumber + "_ok}");
        break;
      case 4: /*Motion module  processing <command:N 4>*/
        Serial_mode = Serial_programming;
        func_mode = DIY_CarControl;
        DIY_CarDirection = doc["D1"];
        DIY_CarSpeed = doc["D2"];
        DIY_CarTimer = doc["T"];
        DIY_CarControl_Millis = millis(); //Get the timestamp
        //Serial.print("{ok}");
        break;
      case 40:
        Serial_mode = Serial_programming;
        func_mode = DIY_CarControlxxx;
        DIY_CarDirectionxxx = doc["D1"];
        DIY_CarSpeedxxx = doc["D2"];

        Serial.print('{' + CommandSerialNumber + "_ok}");
        break;
      case 5: /*Clear mode  processing <command:N 5>*/
        func_mode = DIY_ClearAllFunctions;

        Serial.print('{' + CommandSerialNumber + "_ok}");
        break;
      case 3: /*Remote switching mode  processing <command:N 3>*/
        Serial_mode = Serial_rocker;
        if (1 == doc["D1"]) // Line Teacking Mode
        {
          func_mode = LineTeacking;
          Serial.print('{' + CommandSerialNumber + "_ok}");
        }
        else if (2 == doc["D1"]) //Obstacles Avoidance Mode
        {
          func_mode = ObstaclesAvoidance;
          Serial.print('{' + CommandSerialNumber + "_ok}");
        }
        break;

      case 2: /*Remote switching mode  processing <command:N 2>*/
        Serial_mode = Serial_rocker;
        int SpeedRocker = doc["D2"];
        if (SpeedRocker != 0)
        {
          carSpeed_rocker = SpeedRocker;
        }
        if (1 == doc["D1"])
        {
          func_mode = Bluetooth;
          mov_mode = LEFT;
          // Serial.print('{' + CommandSerialNumber + "_ok}");
        }
        else if (2 == doc["D1"])
        {
          func_mode = Bluetooth;
          mov_mode = RIGHT;
          // Serial.print('{' + CommandSerialNumber + "_ok}");
        }
        else if (3 == doc["D1"])
        {
          func_mode = Bluetooth;
          mov_mode = FORWARD;
          //Serial.print('{' + CommandSerialNumber + "_ok}");
        }
        else if (4 == doc["D1"])
        {
          func_mode = Bluetooth;
          mov_mode = BACK;
          //Serial.print('{' + CommandSerialNumber + "_ok}");
        }
        else if (5 == doc["D1"])
        {
          func_mode = Bluetooth;
          mov_mode = STOP;
          //Serial.print('{' + CommandSerialNumber + "_ok}");
        }
        break;
      default:
        break;
      }
    }
  }
  else if (comdata != "")
  {
    if (true == comdata.equals("f"))
    {
      func_mode = DIY_CarControlxxx;
      DIY_CarDirectionxxx = 3;
      DIY_CarSpeedxxx = 180;
    }
    else if (true == comdata.equals("b"))
    {
      func_mode = DIY_CarControlxxx;
      DIY_CarDirectionxxx = 4;
      DIY_CarSpeedxxx = 180;
    }
    else if (true == comdata.equals("l"))
    {
      func_mode = DIY_CarControlxxx;
      DIY_CarDirectionxxx = 1;
      DIY_CarSpeedxxx = 180;
    }
    else if (true == comdata.equals("r"))
    {
      func_mode = DIY_CarControlxxx;
      DIY_CarDirectionxxx = 2;
      DIY_CarSpeedxxx = 180;
    }
    else if (true == comdata.equals("s"))
    {

      func_mode = Bluetooth;
      mov_mode = STOP;
    }
    else if (true == comdata.equals("1"))
    {
      func_mode = LineTeacking;
    }
    else if (true == comdata.equals("2"))
    {
      func_mode = ObstaclesAvoidance;
    }
  }
}
/*
  Infrared Communication Data Acquisition
*/
void getIRData(void)
{

  if (irrecv.decode(&results))
  {
    IR_PreMillis = millis();
    switch (results.value)
    {
    case f:
      func_mode = IRremote;
      mov_mode = FORWARD;
      break; /*forward*/
    case b:
      func_mode = IRremote;
      mov_mode = BACK;
      break; /*back*/
    case l:
      func_mode = IRremote;
      mov_mode = LEFT;
      break; /*left*/
    case r:
      func_mode = IRremote;
      mov_mode = RIGHT;
      break; /*right*/
    case s:
      func_mode = IRremote;
      mov_mode = STOP;
      break; /*stop*/
    case KEY1:
      func_mode = LineTeacking;
      break; /*Line Teacking Mode*/
    case KEY2:
      func_mode = ObstaclesAvoidance;
      break; /*Obstacles Avoidance Mode*/
    default:
      break;
    }
    irrecv.resume();
  }
}
/*
  Bluetooth remote control mode
*/
void bluetooth_mode()
{
  if (func_mode == Bluetooth)
  {
    switch (mov_mode)
    {
    case FORWARD:
      forward(false, carSpeed_rocker);
      break;
    case BACK:
      back(false, carSpeed_rocker);
      break;
    case LEFT:
      left(false, carSpeed_rocker);
      break;
    case RIGHT:
      right(false, carSpeed_rocker);
      break;
    case STOP:
      stop();
      break;
    default:
      break;
    }
  }
}
/*
  Infrared remote control mode
*/
void irremote_mode(void)
{
  if (func_mode == IRremote)
  {
    switch (mov_mode)
    {
    case FORWARD:
      forward(false, carSpeed);
      break;
    case BACK:
      back(false, carSpeed);
      break;
    case LEFT:
      left(false, carSpeed);
      break;
    case RIGHT:
      right(false, carSpeed);
      break;
    case STOP:
      stop();
      break;
    default:
      break;
    }
    if (millis() - IR_PreMillis > 500)
    {
      mov_mode = STOP;
      IR_PreMillis = millis();
    }
  }
}
/*
  Line Teacking Mode
*/
void line_teacking_mode(void)
{
  if (func_mode == LineTeacking)
  {
    if (LineTeacking_Read_Middle)
    { //Detecting in the middle infrared tube

      forward(false, carSpeed); //Control motor:the car moving forward
      LT_PreMillis = millis();
    }
    else if (LineTeacking_Read_Right)
    { //Detecting in the right infrared tube

      right(false, carSpeed); //Control motor:the car moving right
      while (LineTeacking_Read_Right)
      {
        getBTData_Plus(); //Bluetooth data acquisition
        getIRData();      //Infrared data acquisition
      }
      LT_PreMillis = millis();
    }
    else if (LineTeacking_Read_Left)
    {                        //Detecting in the left infrared tube
      left(false, carSpeed); //Control motor:the car moving left
      while (LineTeacking_Read_Left)
      {
        getBTData_Plus(); //Bluetooth data acquisition
        getIRData();      //Infrared data acquisition
      }
      LT_PreMillis = millis();
    }
    else
    {
      if (millis() - LT_PreMillis > 150)
      {
        stop(); //Stop motor control:Turn off motor drive mode
      }
    }
  }
}
/*
  Obstacles Avoidance Mode
*/
/*f(x) int */
static boolean function_xxx(long xd, long sd, long ed) //f(x)
{
  if (sd <= xd && xd <= ed)
    return true;
  else
    return false;
}

/*Obstacle avoidance*/
void obstacles_avoidance_mode(void)
{
  static uint16_t ULTRASONIC_Get = 0;
  static unsigned long ULTRASONIC_time = 0;
  static boolean stateCar = false;
  static boolean CarED = false;
  static uint8_t switc_ctrl = 0x00;
  static boolean timestamp = true;

  if (func_mode == ObstaclesAvoidance)
  {
    servo.attach(3);
    if (millis() - ULTRASONIC_time > 100)
    {
      ULTRASONIC_Get = getDistance(); //Measuring obstacle distance
      ULTRASONIC_time = millis();
      if (function_xxx(ULTRASONIC_Get, 0, 30)) //If the distance is less than Xcm obstacles
      {
        stateCar = true;
        stop(); //stop
      }
      else
      {
        stateCar = false;
      }
    }
    if (false == CarED)
    {
      if (stateCar == true)
      {
        timestamp = true;
        CarED = true;
        switc_ctrl = 0x00;
        stop();          //stop
        servo.write(30); //sets the servo position according to the  value
        delays(500);
        if (function_xxx(getDistance(), 0, 35)) //How many cm in the front have obstacles?
        {
          switc_ctrl |= 0x01;
        }
        else
        {
          switc_ctrl &= (~0x01);
        }
        servo.write(150); //sets the servo position according to the  value
        delays(500);
        if (function_xxx(getDistance(), 0, 35)) //How many cm in the front have obstacles?
        {
          switc_ctrl |= 0x02;
        }
        else
        {
          switc_ctrl &= (~0x02);
        }
        servo.write(90); //tell servo to go to position in variable 30
        delays(500);
        if (function_xxx(getDistance(), 0, 35)) //How many cm in the front have obstacles?
        {
          switc_ctrl |= 0x04;
        }
        else
        {
          switc_ctrl &= (~0x04);
        }
      }
      else
      {
        forward(false, 150); //Control motor:the car moving forwar
        CarED = false;
      }
    }

    if (true == CarED)
    {
      // Get cpu time
      static unsigned long MotorRL_time;
      if (timestamp == true || millis() - MotorRL_time > 420)
      {
        timestamp = false;
        MotorRL_time = millis();
      }
      if (function_xxx((millis() - MotorRL_time), 0, 400))
      {
        switch (switc_ctrl)
        {
        case 0 ... 1:
          left(false, 250); //Control motor:The car moves forward and left
          break;
        case 2:
          right(false, 250); //Control motor:The car moves forward and right
          break;
        case 3:
          forward(false, 150); //Control motor:the car moving forwar
          break;
        case 4 ... 5:
          left(false, 250); //Control motor:The car moves forward and left
          break;
        case 6:
          right(false, 250); //Control motor:The car moves forward and right
          break;
        case 7:
          back(false, 250); //Control motor:Car backwards
          break;
        }
      }
      else
      {
        CarED = false;
      }
    }
  }
  else
  {
    servo.detach();
    ULTRASONIC_Get = 0;
    ULTRASONIC_time = 0;
  }
}

/*****************************************************Begin@DIY**************************************************************************************/

/*
  N21:command
  DIY mode:Ultrasonic module:App controls module status, module sends data to app
*/
void DIY_UltrasoundModuleStatus_Plus(uint8_t is_get) //Ultrasonic module processing
{
  //uint16_t
  DIY_Distance = getDistance(); //Ultrasonic module measuring distance

  if (1 == is_get) // is_get Start  true:Obstacles / false:No obstacles
  {
    if (DIY_Distance <= 50)
    {
      Serial.print('{' + CommandSerialNumber + "_true}");
    }
    else
    {
      Serial.print('{' + CommandSerialNumber + "_false}");
    }
  }
  else if (2 == is_get) //Ultrasonic is_get data
  {
    char toString[10];
    sprintf(toString, "%d", DIY_Distance);
    // Serial.print(toString);
    Serial.print('{' + CommandSerialNumber + '_' + toString + '}');
  }
}
/*
  N22:command
   DIY mode:Teacking module:App controls module status, module sends data to app
*/
void DIY_TraceModuleStatus_Plus(uint8_t is_get) //Tracking module processing
{
  if (0 == is_get) /*Get traces on the left*/
  {
    if (LineTeacking_Read_Left)
    {
      //Serial.print("{true}");
      Serial.print('{' + CommandSerialNumber + "_true}");
    }
    else
    {
      //Serial.print("{false}");
      Serial.print('{' + CommandSerialNumber + "_false}");
    }
  }
  else if (1 == is_get) /*Get traces on the middle*/
  {
    if (LineTeacking_Read_Middle)
    {
      //Serial.print("{true}");
      Serial.print('{' + CommandSerialNumber + "_true}");
    }
    else
    {
      //Serial.print("{false}");
      Serial.print('{' + CommandSerialNumber + "_false}");
    }
  }
  else if (2 == is_get)
  { /*Get traces on the right*/

    if (LineTeacking_Read_Right)
    {
      //Serial.print("{true}");
      Serial.print('{' + CommandSerialNumber + "_true}");
    }
    else
    {
      //Serial.print("{false}");
      Serial.print('{' + CommandSerialNumber + "_false}");
    }
  }
}

/*
  N1:command
  DIY mode:Sport mode <motor control> Control motor by app
  Input:uint8_t is_MotorSelection,  Motor selection   1:left  2:right  0:all
        uint8_t is_MotorDirection,   Motor steering  1:Forward  2:Reverse 0:stop
        uint8_t is_MotorSpeed,       Motor speed   0-250   
*/
void DIY_MotorControl_Plus(uint8_t is_MotorSelection, uint8_t is_MotorDirection, uint8_t is_MotorSpeed)
{
  static boolean MotorControl = false;

  if (func_mode == DIY_MotorControl) //Motor control mode
  {
    MotorControl = true;
    if (is_MotorSelection == 1 || is_MotorSelection == 0) //Left motor
    {
      if (is_MotorDirection == 1) //Positive rotation
      {
        analogWrite(ENA, is_MotorSpeed);
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
      }
      else if (is_MotorDirection == 2) //Reverse
      {
        analogWrite(ENA, is_MotorSpeed);
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
      }
      else if (is_MotorDirection == 0)
      {
        digitalWrite(ENA, LOW); //Turn off the motor enable pin
      }
    }
    if (is_MotorSelection == 2 || is_MotorSelection == 0) //Right motor
    {
      if (is_MotorDirection == 1) //Positive rotation
      {
        analogWrite(ENB, is_MotorSpeed);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);
      }
      else if (is_MotorDirection == 2) //Reverse
      {
        analogWrite(ENB, is_MotorSpeed);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);
      }
      else if (is_MotorDirection == 0)
      {
        digitalWrite(ENB, LOW); //Turn off the motor enable pin
      }
    }
  }
  else
  {
    if (MotorControl == true)
    {
      MotorControl = false;
      digitalWrite(ENA, LOW); //Turn off the motor enable pin
      digitalWrite(ENB, LOW);
    }
  }
}

/*
  N4:command
  DIY mode:<Car control> APP control car
  Time limited
*/
void DIY_CarControl_Plus(uint8_t is_CarDirection, uint8_t is_CarSpeed, uint8_t is_Timer)
{
  static boolean CarControl = false;
  static boolean CarControl_TE = false; //Have time to spend
  static boolean CarControl_return = false;
  if (func_mode == DIY_CarControl) //Car Control Mode
  {
    CarControl = true;
    if (is_Timer != 0) //Setting time cannot be empty
    {
      if ((millis() - DIY_CarControl_Millis) > (is_Timer * 1000)) //check the time
      {
        CarControl_TE = true;
        digitalWrite(ENA, LOW); //Turn off the motor enable pin
        digitalWrite(ENB, LOW);

        if (CarControl_return == false)
        {
          Serial.print('{' + CommandSerialNumber + "_ok}");
          CarControl_return = true;
        }
      }
      else
      {
        CarControl_TE = false; //Have time to spend
        CarControl_return = false;
      }
    }
    if (CarControl_TE == false)
    {
      switch (is_CarDirection)
      {
      case 1: /*Left-Forward Motion Mode*/
        left(false, is_CarSpeed);
        break;
      case 2: /*Right-Forward Motion Mode*/
        right(false, is_CarSpeed);
        break;
      case 3: /*Sport mode forward*/
        forward(false, is_CarSpeed);
        break;
      case 4: /*Sport mode back*/
        back(false, is_CarSpeed);
        break;
      default:
        break;
      }
    }
  }
  else
  {
    if (CarControl == true)
    {
      CarControl_return = false;
      CarControl = false;
      digitalWrite(ENA, LOW); //Turn off the motor enable pin
      digitalWrite(ENB, LOW);
      DIY_CarControl_Millis = 0;
    }
  }
}

/*
  N40:command
  DIY mode:<Car control> APP control car
  No time limit
*/
void DIY_CarControl_Plusxxx(uint8_t is_CarDirection, uint8_t is_CarSpeed)
{
  static boolean CarControl = false;
  if (func_mode == DIY_CarControlxxx) //Car Control Mode
  {
    CarControl = true;
    switch (is_CarDirection)
    {
    case 1: /*Left-Forward Motion Mode*/
      left(false, is_CarSpeed);
      break;
    case 2: /*Right-Forward Motion Mode*/
      right(false, is_CarSpeed);
      break;
    case 3: /*Sport mode forward*/
      forward(false, is_CarSpeed);
      break;
    case 4: /*Sport mode back*/
      back(false, is_CarSpeed);
      break;
    default:
      break;
    }
  }
  else
  {
    if (CarControl == true)
    {
      CarControl = false;
      digitalWrite(ENA, LOW); //Turn off the motor enable pin
      digitalWrite(ENB, LOW);
    }
  }
}

/*
  N5:command
  DIY mode:Clear all features
*/
void DIY_ClearAllFunctionsXXX(void)
{
  if (func_mode == DIY_ClearAllFunctions)
  {

    mov_mode = STOP;
    func_mode = IDLE;
    digitalWrite(ENA, LOW); //Turn off the motor enable pin
    digitalWrite(ENB, LOW);

    /*DIY_MotorControl:Motor Control: Motor Speed、Motor Direction、Motor Time*/
    DIY_MotorSelection = NULL;
    DIY_MotorDirection = NULL;

    DIY_MotorSpeed = NULL;
    DIY_leftMotorControl_Millis = NULL;
    DIY_rightMotorControl_Millis = NULL;

    /*DIY_CarControl:Car Control:Car moving direction、Car Speed、Car moving time*/
    DIY_CarDirection = NULL;
    DIY_CarSpeed = NULL;
    DIY_CarTimer = NULL;
    DIY_CarControl_Millis = NULL;
  }
}

void getDistance_xx(void)
{
  DIY_Distance = getDistance(); //Ultrasonic measurement distance
}

/*****************************************************End@DIY**************************************************************************************/

void setup(void)
{
  Serial.begin(9600);                 //initialization
  servo.attach(PIN_Servo, 500, 2400); //500: 0 degree  2400: 180 degree
  servo.write(90);                    //sets the servo position according to the 90(middle)
  irrecv.enableIRIn();                //Enable infrared communication NEC

  pinMode(ECHO_PIN, INPUT); //Ultrasonic module initialization
  pinMode(TRIG_PIN, OUTPUT);

  pinMode(IN1, OUTPUT); //Motor-driven port configuration
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);

  pinMode(LineTeacking_Pin_Right, INPUT); //Infrared tracking module port configuration
  pinMode(LineTeacking_Pin_Middle, INPUT);
  pinMode(LineTeacking_Pin_Left, INPUT);
}

void loop(void)
{

  getBTData_Plus();           //Bluetooth data acquisition
  getIRData();                //Infrared data acquisition
  bluetooth_mode();           //Bluetooth remote mode
  irremote_mode();            //Infrared NEC remote control mode
  line_teacking_mode();       //Line Teacking Mode
  obstacles_avoidance_mode(); //Obstacles Avoidance Mode

  if (Serial_mode == Serial_programming || Serial_mode == Serial_diy)
  {
    DIY_Distance = getDistance(); //Ultrasonic measurement distance
    /*DIY_MotorControl: Motor Control: Motor Speed、Motor Direction、Motor Time*/
    DIY_MotorControl_Plus(DIY_MotorSelection, DIY_MotorDirection, DIY_MotorSpeed); //Control motor steering
    /*  DIY mode:<Car control> APP control car*/
    DIY_CarControl_Plus(DIY_CarDirection, DIY_CarSpeed, DIY_CarTimer); //Control the direction of the car<Time limited>
    DIY_CarControl_Plusxxx(DIY_CarDirectionxxx, DIY_CarSpeedxxx);      //Control the direction of the car<No Time limited>
    DIY_ClearAllFunctionsXXX();
  }
}

also for info, the kit came with individual codes which I belive you can stack I have amalgamated them (sorry, very long).

There is a //car_control.ino which I belive is the one I have to change, however there is also a ////left_wheel_rotation orig.ino and a //right_wheel_rotation orig.ino

If I change the //car_control.ino will this impact the //left and right_wheel_rotation

or do I not need the left and right as they are covered in the car control?

//www.elegoo.com
//AUTO_GO.ino////////////////////////////////////////////////////////////////////////////////////////////////

//    The direction of the car's movement
//  ENA   ENB   IN1   IN2   IN3   IN4   Description  
//  HIGH  HIGH  HIGH  LOW   LOW   HIGH  Car is runing forward
//  HIGH  HIGH  LOW   HIGH  HIGH  LOW   Car is runing back
//  HIGH  HIGH  LOW   HIGH  LOW   HIGH  Car is turning left
//  HIGH  HIGH  HIGH  LOW   HIGH  LOW   Car is turning right
//  HIGH  HIGH  LOW   LOW   LOW   LOW   Car is stoped
//  HIGH  HIGH  HIGH  HIGH  HIGH  HIGH  Car is stoped
//  LOW   LOW   N/A   N/A   N/A   N/A   Car is stoped


//define L298n module IO Pin
#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11

void forward(){ 
  digitalWrite(ENA,HIGH); //enable L298n A channel
  digitalWrite(ENB,HIGH); //enable L298n B channel
  digitalWrite(IN1,HIGH); //set IN1 hight level
  digitalWrite(IN2,LOW);  //set IN2 low level
  digitalWrite(IN3,LOW);  //set IN3 low level
  digitalWrite(IN4,HIGH); //set IN4 hight level
  Serial.println("Forward");//send message to serial monitor
}

void back(){
  digitalWrite(ENA,HIGH);
  digitalWrite(ENB,HIGH);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("Back");
}

void left(){
  digitalWrite(ENA,HIGH);
  digitalWrite(ENB,HIGH);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH); 
  Serial.println("Left");
}

void right(){
  digitalWrite(ENA,HIGH);
  digitalWrite(ENB,HIGH);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("Right");
}

//before execute loop() function, 
//setup() function will execute first and only execute once
void setup() {
  Serial.begin(9600);//open serial and set the baudrate
  pinMode(IN1,OUTPUT);//before useing io pin, pin mode must be set first 
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
}

//Repeat execution
void loop() {
  forward();  //go forward
  delay(1000);//delay 1000 ms
  back();     //go back
  delay(1000);
  left();     //turning left
  delay(1000);
  right();    //turning right
  delay(1000);
}


//car_control.ino//////////////////////////////////////////////////////////////////////////

//www.elegoo.com

//     Right motor truth table
//Here are some handy tables to show the various modes of operation.
//  ENB         IN3             IN4         Description  
//  LOW   Not Applicable   Not Applicable   Motor is off
//  HIGH        LOW             LOW         Motor is stopped (brakes)
//  HIGH        LOW             HIGH        Motor is on and turning forwards
//  HIGH        HIGH            LOW         Motor is on and turning backwards
//  HIGH        HIGH            HIGH        Motor is stopped (brakes)   

// define IO pin
#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11

//set car speed
#define CAR_SPEED 100
typedef unsigned char u8;  
//Change the name of unsigned char to u8

void forward(u8 car_speed)
{

  analogWrite(ENA, car_speed);
  analogWrite(ENB, car_speed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}


void back(u8 car_speed)
{

  analogWrite(ENA, car_speed);
  analogWrite(ENB, car_speed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}


void left(u8 car_speed)
{

  analogWrite(ENA, 250);
  analogWrite(ENB, 250);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);

  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

void right(u8 car_speed)
{
  analogWrite(ENA, 250);
  analogWrite(ENB, 250);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}
/*
  停止对电机控制:关闭电机驱动使能端口
*/
void stop()
{
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
}




void setup() {
  pinMode(IN1,OUTPUT);//before useing io pin, pin mode must be set first 
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
}

void loop() {
  forward(CAR_SPEED);  //go forward
  delay(1000);//delay 1000 ms
  back(CAR_SPEED);     //go back
  delay(1000);
  left(CAR_SPEED);     //turning left
  delay(1000);
  right(CAR_SPEED);    //turning right
  delay(1000);
  stop();
  while(1);

}


//left_wheel_rotation orig.ino/////////////////////////////////////////////////////////////////////////////////////////


//www.elegoo.com


//     Left motor truth table

//Here are some handy tables to show the various modes of operation.

//  ENA         IN1               IN2         Description  

//  LOW   Not Applicable    Not Applicable    Motor is off

//  HIGH        LOW               LOW         Motor is stopped (brakes)

//  HIGH        HIGH              LOW         Motor is on and turning forwards

//  HIGH        LOW               HIGH        Motor is on and turning backwards

//  HIGH        HIGH              HIGH        Motor is stopped (brakes)


// define IO pin

#define ENA 5 

#define IN1 7

#define IN2 8



//init the car

void setup() {

  pinMode(IN1, OUTPUT);   //set IO pin mode OUTPUT
  
  pinMode(IN2, OUTPUT);

  pinMode(ENA, OUTPUT);

  digitalWrite(ENA, HIGH);//Enable left motor

}



//mian loop

void loop() {
  
 digitalWrite(IN1, HIGH);      
  
 digitalWrite(IN2, LOW); //Right wheel turning forwards
  
 delay(500);             //delay 500ms
  digitalWrite(IN1, LOW);      
  
 digitalWrite(IN2, LOW); //Right wheel stoped
  delay(500);
  
 digitalWrite(IN1, LOW);      
  
 digitalWrite(IN2, HIGH);//Right wheel turning backwards
  
 delay(500);
  digitalWrite(IN1, HIGH);      
  
 digitalWrite(IN2, HIGH); //Right wheel stoped
  
 delay(500);

}



//forward_back.ino////////////////////////////////////////////////////////////////////////////////////
//
//    Left motor truth table

//  ENA         IN1               IN2         Description  

//  LOW   Not Applicable    Not Applicable    Motor is off

//  HIGH        LOW               LOW         Motor is stopped (brakes)

//  HIGH        HIGH              LOW         Motor is on and turning forwards

//  HIGH        LOW               HIGH        Motor is on and turning backwards

//  HIGH        HIGH              HIGH        Motor is stopped (brakes)


//    Right motor truth table

//  ENB         IN3             IN4         Description  

//  LOW   Not Applicable   Not Applicable   Motor is off

//  HIGH        LOW             LOW         Motor is stopped (brakes)

//  HIGH        LOW             HIGH        Motor is on and turning forwards

//  HIGH        HIGH            LOW         Motor is on and turning backwards

//  HIGH        HIGH            HIGH        Motor is stopped (brakes)  


//    The direction of the car's movement

//  Left motor    Right motor     Description  

//  stop(off)     stop(off)       Car is stopped

//  forward       forward         Car is running forwards

//  forward       backward        Car is turning right

//  backward      forward         Car is turning left

//  backward      backward        Car is running backwards


//define the L298n IO pin

#define ENA 5

#define ENB 6

#define IN1 7

#define IN2 8

#define IN3 9

#define IN4 11

void setup() {
 
 pinMode(IN1, OUTPUT);
  
pinMode(IN2, OUTPUT);
  
pinMode(IN3, OUTPUT);
  
pinMode(IN4, OUTPUT);
  
pinMode(ENA, OUTPUT);
  
pinMode(ENB, OUTPUT);
  
digitalWrite(ENA, HIGH);  
  
digitalWrite(ENB, HIGH); 
}

void loop() {
  
digitalWrite(IN1, HIGH);      
  
digitalWrite(IN2, LOW); 
  
digitalWrite(IN3, LOW);      
  
digitalWrite(IN4, HIGH);  
//go forward
  
delay(500);
  
digitalWrite(IN1, LOW);      
  
digitalWrite(IN2, LOW);
  
digitalWrite(IN3, LOW);      
  
digitalWrite(IN4, LOW);   
//stop
  
delay(500);
  
digitalWrite(IN1, LOW);      
  
digitalWrite(IN2, HIGH);
  
digitalWrite(IN3, HIGH);      
  
digitalWrite(IN4, LOW);   
//go back
  delay(500);
  
digitalWrite(IN1, LOW);      
  
digitalWrite(IN2, LOW); 
  
digitalWrite(IN3, HIGH);      
  
digitalWrite(IN4, HIGH);  
//stop
  
delay(500);
}




//left_wheel_rotation.ino ///////////////////////////////////////////////////
//

//     Left motor truth table

//Here are some handy tables to show the various modes of operation.

//  ENA         IN1               IN2         Description  

//  LOW   Not Applicable    Not Applicable    Motor is off

//  HIGH        LOW               LOW         Motor is stopped (brakes)

//  HIGH        HIGH              LOW         Motor is on and turning forwards

//  HIGH        LOW               HIGH        Motor is on and turning backwards

//  HIGH        HIGH              HIGH        Motor is stopped (brakes)


// define IO pin
#define ENA 5 
#define IN1 7
#define IN2 8


//init the car
void setup() {
  pinMode(IN1, OUTPUT);   
//set IO pin mode OUTPUT
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);
  digitalWrite(ENA, HIGH);
//Enable left motor       
}


//mian loop

void loop() {
  
digitalWrite(IN1, HIGH);      
  
digitalWrite(IN2, LOW); //Right wheel turning forwards
  
delay(500);             //delay 500ms
  
digitalWrite(IN1, LOW);      
  
digitalWrite(IN2, LOW); //Right wheel stoped
  
delay(500);
  
digitalWrite(IN1, LOW);      
  
digitalWrite(IN2, HIGH);//Right wheel turning backwards
  
delay(500);
  
digitalWrite(IN1, HIGH);      
  
digitalWrite(IN2, HIGH); //Right wheel stoped
  
delay(500);
}



//right_wheel_rotation.ino
//     Right motor truth table

//Here are some handy tables to show the various modes of operation.

//  ENB         IN3             IN4         Description  

//  LOW   Not Applicable   Not Applicable   Motor is off

//  HIGH        LOW             LOW         Motor is stopped (brakes)

//  HIGH        LOW             HIGH        Motor is on and turning forwards

//  HIGH        HIGH            LOW         Motor is on and turning backwards

//  HIGH        HIGH            HIGH        Motor is stopped (brakes)      


// define IO pin
#define ENB 6 
#define IN3 9
#define IN4 11


//init the car
void setup() {
  pinMode(IN3, OUTPUT); 
//set IO pin mode OUTPUT
  
pinMode(IN4, OUTPUT);
  
pinMode(ENB, OUTPUT);
  
digitalWrite(ENB, HIGH);  
//Enable right motor       
}


//mian loop

void loop() {
  
digitalWrite(IN3, LOW);      
  
digitalWrite(IN4, HIGH);//Right wheel turning forwards
  
delay(500);             
//delay 500ms
  
digitalWrite(IN3, LOW);      
  
digitalWrite(IN4, LOW); //Right wheel stoped
  
delay(500);
  
digitalWrite(IN3, HIGH);      
  
digitalWrite(IN4, LOW); //Right wheel turning backwards
  
delay(500);
  
digitalWrite(IN3, HIGH);      
  
digitalWrite(IN4, HIGH); //Right wheel stoped
  
delay(500);
}


//speed_control.ino/////////////////////////////////////////////////////////////////////////////////

#define ENA 5

#define ENB 6

#define IN1 7

#define IN2 8

#define IN3 9

#define IN4 11


void setup() {
  
pinMode(IN1,OUTPUT);
  
pinMode(IN2,OUTPUT);
  
pinMode(IN3,OUTPUT);
  
pinMode(IN4,OUTPUT);
  
pinMode(ENA,OUTPUT);
  
pinMode(ENB,OUTPUT);
}


void loop() {
  
//go forward
  
digitalWrite(IN1,HIGH); 
  
digitalWrite(IN2,LOW);  
  
digitalWrite(IN3,LOW);  
  
digitalWrite(IN4,HIGH);
  

//reduce the speed
  for(int i = 255; i >= 0; i--)
{ 
    
analogWrite(ENB,i);
    
analogWrite(ENA,i);
    
delay(20);
  }

  
//stop
  analogWrite(ENB,0); 
//speed = 0
  analogWrite(ENA,0);  
  
delay(1000);

  

//runing back
  digitalWrite(IN1,LOW);
  
digitalWrite(IN2,HIGH);
  
digitalWrite(IN3,HIGH);
  
digitalWrite(IN4,LOW);
  

//accelerate
  for(int i = 0; i <= 255; i++)
{ 
    
analogWrite(ENB,i);
    
analogWrite(ENA,i);
    
delay(20);
  } 
  
  

//stop
  digitalWrite(ENB,LOW); 
//Motor is off 
  
digitalWrite(ENA,LOW);  
  
delay(2000);   
}


//bluetooth_blink.ino//////////////////////////////////////////////////////////////////

#define LED 13    //Define 13 pin for LED
bool state = LOW; //The initial state of the function is defined as a low level
char getstr;      //Defines a function that receives the Bluetooth character

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

//Control LED sub function
void stateChange() {
  state = !state; 
  digitalWrite(LED, state);  
}

void loop() {
  //The Bluetooth serial port to receive the data in the function
  getstr = Serial.read();
  Serial.print(getstr);
  if(getstr == 'a'){
    stateChange();
  }
}

//bluetooth_car.ino//////////////////////////////////////////////////////////////////

#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11
#define LED 13

unsigned char carSpeed = 250;
bool state = LOW;

void forward(){ 
  digitalWrite(ENA,HIGH);
  digitalWrite(ENB,HIGH);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  Serial.println("Forward");
}

void back(){
  digitalWrite(ENA,HIGH);
  digitalWrite(ENB,HIGH);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("Back");
}

void left(){
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH); 
  Serial.println("Left");
}

void right(){
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("Right");
}

void stop(){
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);
  Serial.println("Stop!");
}

void stateChange(){
  state = !state;
  digitalWrite(LED, state);
  Serial.println("Light");  
}

void setup() { 
  Serial.begin(9600);
  pinMode(LED, OUTPUT); 
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
  stop();
}

void loop() { 
  if(Serial.available())
  {
    char getstr = Serial.read();
    switch(getstr){
      case 'f': forward(); break;
      case 'b': back();   break;
      case 'l': left();   break;
      case 'r': right();  break;
      case 's': stop();   break;
      case 'a': stateChange(); break;
      default:  break;
    }
  }
}


//www.elegoo.com


#include <IRremote.h>


#define RECV_PIN  12        /
/Infrared signal receiving pin

#define LED       13        
//define LED pin

#define L         16738455

#define UNKNOWN_L 1386468383

bool state = LOW;           
//define default input mode
unsigned long val; 

IRrecv irrecv(RECV_PIN);   
//initialization

decode_results results;   
//Define structure type


void stateChange() {
  state = !state;          
  
digitalWrite(LED, state);
}


void setup() {
  
pinMode(LED, OUTPUT); 
//initialize LED as an output
  
Serial.begin(9600);  
// debug output at 9600 baud
  
irrecv.enableIRIn();  
// Start receiving

}

void loop() {
  
if (irrecv.decode(&results)) { 
    
val = results.value;
    
Serial.println(val);
   
irrecv.resume();      
// Receive the next value
    
delay(150);
    
if(val == L || val == UNKNOWN_L) {  
      stateChange();
    }
  }
}


//infared_remote_control_car.ino////////////////////////////////


#include <IRremote.h>


////////// IR REMOTE CODES //////////

#define F 16736925	// FORWARD

#define B 16754775	// BACK

#define L 16720605	// LEFT

#define R 16761405	// RIGHT

#define S 16712445	// STOP

#define UNKNOWN_F 5316027		  // FORWARD

#define UNKNOWN_B 2747854299	// BACK

#define UNKNOWN_L 1386468383	// LEFT

#define UNKNOWN_R 553536955		// RIGHT

#define UNKNOWN_S 3622325019	// STOP

#define KEY1 16738455

#define KEY2 16750695

#define KEY3 16756815

#define KEY4 16724175

#define KEY5 16718055

#define KEY6 16743045

#define KEY7 16716015

#define KEY8 16726215

#define KEY9 16734885

#define KEY0 16730805

#define KEY_STAR 16728765

#define KEY_HASH 16732845


#define RECV_PIN  12

/*define channel enable output pins*/

#define ENA 5	  // Left  wheel speed

#define ENB 6	  // Right wheel speed
/*define logic control output pins*/

#define IN1 7	  // Left  wheel forward

#define IN2 8	  // Left  wheel reverse

#define IN3 9	  // Right wheel reverse

#define IN4 11	// Right wheel forward

#define carSpeed 250	// initial speed of car >=0 to <=255

IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long val;
unsigned long preMillis;

/**
 * BEGIN DEFINE FUNCTIONS
 */

 void forward(){ 
  digitalWrite(ENA,HIGH);
  digitalWrite(ENB,HIGH);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);
  Serial.println("go forward!");
}
void back(){
  digitalWrite(ENA,HIGH);
  digitalWrite(ENB,HIGH);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("go back!");
}
void left(){
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH); 
  Serial.println("go left!");
}
void right(){
  analogWrite(ENA,carSpeed);
  analogWrite(ENB,carSpeed);
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  Serial.println("go right!");
}
void stop(){
  digitalWrite(ENA, LOW);
  
digitalWrite(ENB, LOW);
  
Serial.println("STOP!");  
}


void setup() {
  
Serial.begin(9600);
  
pinMode(IN1,OUTPUT);
  
pinMode(IN2,OUTPUT);
  
pinMode(IN3,OUTPUT);
  
pinMode(IN4,OUTPUT);
  
pinMode(ENA,OUTPUT);
  
pinMode(ENB,OUTPUT);
  
stop();
  
irrecv.enableIRIn();  
}


void loop() {
  
if (irrecv.decode(&results)){ 
    
preMillis = millis();
    
val = results.value;
    
Serial.println(val);
    
irrecv.resume();
    
switch(val){
      
case F: 
      
case UNKNOWN_F: forward(); 
break;
      
case B: 
      case UNKNOWN_B: back(); 
break;
      
case L: 
      case UNKNOWN_L: left(); 
break;
      
case R: 
      case UNKNOWN_R: right();
break;
      
case S: 
      case UNKNOWN_S: stop(); 
break;
      
default: break;
    }
  }
  
else{
    
if(millis() - preMillis > 500){
      
stop();
      
preMillis = millis();
    }
  }
} 




//Obstacle_avoidance_car.ino///////////////////////////////////////////////


#include <Servo.h>  
//servo library

Servo myservo;      
// create servo object to control servo

int Echo = A4;  
int Trig = A5; 

#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11
#define carSpeed 250
int rightDistance = 0, leftDistance = 0, middleDistance = 0;

void forward(){ 
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("Forward");
}

void back() {
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Back");
}

void left() {
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH); 
  Serial.println("Left");
}

void right() {
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Right");
}

void stop() {
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
  Serial.println("Stop!");
} 

//Ultrasonic distance measurement Sub function
int Distance_test() {
  digitalWrite(Trig, LOW);   
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);  
  delayMicroseconds(20);
  digitalWrite(Trig, LOW);   
  float Fdistance = pulseIn(Echo, HIGH);  
  Fdistance= Fdistance / 58;       
  return (int)Fdistance;
}  

void setup() { 
  myservo.attach(3,700,2400);  // attach servo on pin 3 to servo object
  Serial.begin(9600);     
  pinMode(Echo, INPUT);    
  pinMode(Trig, OUTPUT);  
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  stop();
} 

void loop() { 
    myservo.write(90);  //setservo position according to scaled value
    delay(500); 
    middleDistance = Distance_test();

    if(middleDistance <= 40) {     
      stop();
      delay(500);                         
      myservo.write(10);          
      delay(1000);      
      rightDistance = Distance_test();
      
      delay(500);
      myservo.write(90);              
      delay(1000);                                                  
      myservo.write(180);              
      delay(1000); 
      leftDistance = Distance_test();
      
      delay(500);
      myservo.write(90);              
      delay(1000);
      if(rightDistance > leftDistance) {
        right();
        delay(360);
      }
      else if(rightDistance < leftDistance) {
        left();
        delay(360);
      }
      else if((rightDistance <= 40) || (leftDistance <= 40)) {
        back();
        delay(180);
      }
      else {
        forward();
      }
    }  
    else {
        forward();
    }                     
}





1 Like

I think this is the part where the 'left' or 'right' commands are applied for a certain amount of time. Perhaps changing the 400 and 420 to smaller values will turn a smaller angle.

1 Like

Many thanks, I will try this tonight when I get home :smile:

I don't know how I did it or what happened but I managed to add the wrong code to this post! John, Im so sorry I waisted your time, however, I was able to apply your advice to the code I should have posted and made some massive progress.
So thanks so much!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.