Obstacle Avoiding Robot Using Tinkercad
by R W S in Circuits > Arduino
2252 Views, 0 Favorites, 0 Comments
Obstacle Avoiding Robot Using Tinkercad
Create your obstacle avoiding robot virtually or practically!
To create robot virtually visit https://www.tinkercad.com and signup/login.
Create a New Project
After signing up or logging in go to circuits and create a new project.
Drag Components Into the Workspace
From the search menu drag the required components, all the needed components are:
- 2 x hobby gear motors
- 1 x Arduino UNO
- 1 x Breadboard(small)
- 1 x L293D
- 1 x Ultrasonic Sensor
Make the Connections
After you finish dragging the components start making the connections you can refer to the figure for convenience
Step 1: Place the L293D using the dip rail in the breadboard(see fig).
Step 2: Connect 5V from the Arduino UNO to the positive power rail.
Step 3: Connect GND from Arduino UNO to the negative power rail.
Step 4: Interconnect the power rails on both sides with their respective rail.
Step 5: Connect Enable 1,2; Power 1, Enable 3,4; and Power 2 to the positive power rails.
Step 6: Connect all the GNDs of the L293D to the negative power rails.
Step 7: Connect Trigger and Echo pin of the Ultrasonic Sensor to pin number 2 and 3 of the Arduino UNO respectively.
Step 8: Connect VCC pin of Ultrasonic to positive power rail and GND pin of the Ultrasonic sensor to negative power rail.
Step 9: Connect Input 1,2,3,4 of L293D to pin number 4,5,6,7 of the Arduino UNO.
Step 10: Connect output 1 of L293D to positive terminal of left motor and output 2 of L293D to negative terminal of left motor.
Step 11: Connect output 3 and 4 of L293D to negative and positive terminal of motor respectively.
Good job! your connection is finished you van move on to next slide.
Code
Click on the code button to Code you can either block coding or text coding depending on your knowledge of C++ programming.
To code using blocks you can refer to the above image.
To code using text you can refer to the code below:
// C++ code
// long readUltrasonicDistance(int triggerPin, int echoPin) {
pinMode(triggerPin, OUTPUT);
// Clear the trigger digitalWrite(triggerPin, LOW); delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds digitalWrite(triggerPin, HIGH);
delayMicroseconds(10); digitalWrite(triggerPin, LOW); pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds 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, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
} else {
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
}
delay(10);
// Delay a little bit to improve simulation performance
}
Create Your Robot Practically
You can create your robot practically simply by implementing the same steps, you can ignore this if you don't have all the components if you place the motors on the two sides of a cardboard or plastic sheet you, attach wheels to the motors and fix the Ultrasonic sensor at the front of the car; after programming the Arduino UNO you will observe that the robot seems to move in the forward direction but as soon as an object appears within 10 cms in front of it it will take a turn and start moving in the forward direction.
To open the code file you need to download the Arduino app, please refer to this link for that Arduino app:
https://www.arduino.cc/en/software
Hurrah! you have completed your project! Now you can enjoy it.