Building a robot that can avoid obstacles

With the help of its two motors (left and right), a self-driving bot will always go forward. It pauses if the ultrasonic sensor identifies an obstruction 30 centimeters or less in front of it. After that, the robot spins by slowly turning one wheel while stopping the other, until the obstruction is removed, at which point it keeps moving forward. Please assist with coding along with the design in tinkerCAD. Thank you.

What is your budget and required completion date?

I don't have to build it in real life. I have to build it in TinkerCAD using sensors, actuators breadboard and arduino. I am really having a hard time getting this done. Someone please help me with it. I would really appreciate it.

Members of this forum expect you to do most of the work. Post your best efforts, describe what goes wrong, and people will be happy to help.

Posting instructions can be found in the "How to get the best out of this forum" post, linked at the head of every forum category.

Okay, thank you.

You might have a look at this project for inspiration: GitHub - frameworklabs/ego: An M5 powered LEGO robot

Show what you have done.

When is your assignment due?

It is due tomorrow night at 11:59pm.

Best get to work then, you have time to make some progress on your assignment.

Show your work.

This is what I have so far. I am having difficulty writing a code to detect an obstacle that is 30 CM or less in front of it with the Ultrasonic Sensor. it stops. In addition, one (1) wheel should turn slowly while the other stops (and thus the robot rotates) until the obstacle is
cleared, wherein then it continues to drive forward. Please assist with this. Thanks.

This is the code I have so far, and both of the motors are moving.

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}

void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}

void loop()
{
if (0.01723 * readUltrasonicDistance(2, 3) < 10) {
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
} else {
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

Perhaps you should examine the reasoning behind this obscure line of code:

if (0.01723 * readUltrasonicDistance(2, 3) < 10) {

Please use code tags when posting code.

Also, consider adding comments explaining what the code does. You have just one, for the least useful line in the entire program.

Follow the rules. Put your code in a code block...