Adding an ultrasonic sensor to a robot car

Hi, so I have this robot car kit.

http://osoyoo.com/2017/09/21/2wd-robot-car-installation/

It doesn't come with an ultrasonic sensor, but I have one and I'm trying to add it. However, I'm finding that I really don't have the skills to modify one of the codes to have the car avoid obstacles or anything. It also seems like the codes that I have for the car only work if I'm using the sensor shield, but maybe the ultrasonic sensor doesn't work with the sensor shield. The code for using the car with remote control is below. There's also a line tracing code on the website. Any help would be very much appreciated. I'm running a robotics club.

#include <IRremote.h>
#define IN1 7 //K1、K2 motor direction
#define IN2 8 //K1、K2 motor direction
#define IN3 9 //K3、K4 motor direction
#define IN4 10 //K3、K4 motor direction
#define ENA 5 // Needs to be a PWM pin to be able to control motor speed ENA
#define ENB 6 // Needs to be a PWM pin to be able to control motor speed ENA
#define IRPIN 4 //IR receiver Signal pin connect to Arduino pin 4

#define IR_ADVANCE 0x00FF18E7 //code from IR controller "▲" button
#define IR_BACK 0x00FF4AB5 //code from IR controller "▼" button
#define IR_RIGHT 0x00FF5AA5 //code from IR controller ">" button
#define IR_LEFT 0x00FF10EF //code from IR controller "<" button
enum DN
{
GO_ADVANCE, //go ahead
GO_LEFT, //left turn
GO_RIGHT,//right turn
GO_BACK,//go back
DEF
}Drive_Num=DEF;
IRrecv IR(IRPIN); // IRrecv object IR get code from IR remoter
decode_results IRresults;
bool stopFlag = true;//set stop flag
bool JogFlag = false;
uint16_t JogTimeCnt = 0;
uint32_t JogTime=0;
/motor control/
void go_back(int t) //motor rotate clockwise -->robot go ahead
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4,HIGH);
delay(t);
}
void go_ahead(int t) //motor rotate counterclockwise -->robot go back
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4,LOW);
delay(t);
}
void go_stop() //motor brake -->robot stop
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4,LOW);
}
void turn_left(int t) //left motor rotate clockwise and right motor rotate counterclockwise -->robot turn right
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(t);
}
void turn_right(int t) //left motor rotate counterclockwise and right motor rotate clockwise -->robot turn left
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
delay(t);
}
/*set motor speed /
void set_motorspeed(int lspeed,int rspeed) //change motor speed
{
analogWrite(ENA,lspeed);//lspeed:0-255
analogWrite(ENB,rspeed);//rspeed:0-255
}
/detect IR code
/
void do_IR_Tick()
{
if(IR.decode(&IRresults))
{
if(IRresults.value==IR_ADVANCE)
{
Drive_Num=GO_ADVANCE;
}
else if(IRresults.value==IR_RIGHT)
{
Drive_Num=GO_RIGHT;
}
else if(IRresults.value==IR_LEFT)
{
Drive_Num=GO_LEFT;
}
else if(IRresults.value==IR_BACK)
{
Drive_Num=GO_BACK;
}
IRresults.value = 0;
IR.resume();
}
}
/car control/
void do_Drive_Tick()
{
switch (Drive_Num)
{
case GO_ADVANCE:
set_motorspeed(225,225);go_ahead(20);JogFlag = true;JogTimeCnt = 3;JogTime=millis();break;//if GO_ADVANCE code is detected, then go advance
case GO_LEFT:
set_motorspeed(120,120);turn_left(1);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_LEFT code is detected, then turn left
case GO_RIGHT:
set_motorspeed(120,120);turn_right(1);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_RIGHT code is detected, then turn right
case GO_BACK:
set_motorspeed(225,225);go_back(20);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_BACK code is detected, then backward
default:break;
}
Drive_Num=DEF;
//keep current moving mode for 100 millis seconds
if(millis()-JogTime>=100)
{
JogTime=millis();
if(JogFlag == true)
{
stopFlag = false;
if(JogTimeCnt <= 0)
{
JogFlag = false; stopFlag = true;
}
JogTimeCnt--;
}
if(stopFlag == true)
{
JogTimeCnt=0;
go_stop();
}
}
}
void setup() {
/L298N/
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);

pinMode(IRPIN, INPUT);
digitalWrite(IRPIN, HIGH);
IR.enableIRIn();
}

void loop() {
do_IR_Tick();
do_Drive_Tick();
}

Please edit your post to add code tags, as described in "How to use this forum".

Get the ultrasonic sensor working with the example code, and make sure you understand it before modifying the car code.

Hi,

Here is a detailed how-to for a robot similar to yours but with added servo/ultrasonic:

https://arduinoinfo.mywikis.net/wiki/RobotKitMenu

See the servo that moves the ultrasonic :