Hello, welcome back. In this tutorial, we will learn how to make a multi-functional robot car using Arduino. Also, this robot car includes three functions. That is, line-following, recognizing obstacles, and controlling the robotic arm. For that, it uses two IR infrared sensors, one ultrasonic sensor, and one robotic arm.

The process of this robot car
When this robot car is activated, it starts to move forward on the black line. Two IR infrared sensors were used for this purpose. Going forward in this way, the ultrasonic sensor calculates the distance ahead. In this case, when there is an obstacle in front of 9 cm, the robot stops. Then, the obstacle is removed using the robotic arm. After, the robot will move forward freely again. This process continues. Also, all of these components are controlled by the Arduino Uno board and the l293d motor driver shield.
OK, let’s do this project step by step. The required components are given below.
Arduino Uno - Buy Now
Servo Motor (SG90) - BUY NOW
Ultrasonic Sensor - Buy Now
Gear motor — BUY NOW
65mm Robot wheel x 2 — BUY NOW
Lithium Battery (3.7V) x 2 - BUY NOW
Lithium Battery Holder x 2 - BUY NOW
Jumper-Wires - BUY NOW
Foam board
Robot arm
L293D motor driver
PWM servo motor driver
Step 1
Firstly, identify these components.

Step 2
Secondly, cut a piece of foam board according to the size below.


Step 3
Thirdly, attach the gear motors to the foam board.

Step 4
Then, attach the robot wheels as follows.

Step 5
Next, cut a 10 cm long piece of foam board and attach the two IR sensors and the ultrasonic sensor to it.

Step 6
Then, cut out the following sizes and glue them as shown below.

Step 7
Now, glue these parts to the front of the robot.

Step 8
Next, attach the robot arm to the robot car chassis. For that, you can use a robot arm kit.
Step 9
After, connect the motor driver shield to the Arduino UNO board. After, glue it to the robot and connect the gear motors to it.

Step 10
Next, attach the PWM servo motor driver and connect the servo motors to it. For that, use the circuit diagram below.

Step 11
Then, connect the two IR sensors and the ultrasonic sensor to the motor driver shield. To do this, use the circuit diagram above.
Step 12
Next, attach the li-ion battery holder to this robot car.
Step 13
Now, connect this robot car to the computer and upload the program for this robot. It is as follows.


/*Multi function robot with Arduino.
* https://webotricks.com
*/
#include <AFMotor.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver srituhobby = Adafruit_PWMServoDriver();
AF_DCMotor motor1(2);
AF_DCMotor motor2(3);
#define Echo A0
#define Trig A1
#define S1 A2
#define S2 A3
#define Speed 150
#define servo1 0
#define servo2 1
#define servo3 2
#define servo4 3
void setup() {
pinMode(S1, INPUT);
pinMode(S2, INPUT);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
webotricks.begin();
webotricks.setPWMFreq(60);
webotricks.setPWM(servo1, 0, 340);
webotricks.setPWM(servo2, 0, 150);
webotricks.setPWM(servo3, 0, 300);
webotricks.setPWM(servo4, 0, 290);
motor1.setSpeed(Speed);
motor2.setSpeed(Speed);
}
void loop() {
int distance = obstacle();
Serial.println(distance);
if (distance <= 9) {
motor1.run(RELEASE);
motor2.run(RELEASE);
motor1.run(BACKWARD);
motor2.run(BACKWARD);
delay(100);
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(100);
robotArm();
delay(100);
motor1.run(FORWARD);
motor2.run(FORWARD);
delay(100);
} else {
linefollower();
}
}
void linefollower() {
bool value1 = digitalRead(S1);
bool value2 = digitalRead(S2);
if (value1 == 0 && value2 == 0) {
motor1.run(FORWARD);
motor2.run(FORWARD);
} else if (value1 == 1 && value2 == 1) {
motor1.run(RELEASE);
motor2.run(RELEASE);
} else if (value1 == 1 && value2 == 0) {
motor1.run(BACKWARD);
motor2.run(FORWARD);
} else if (value1 == 0 && value2 == 1) {
motor1.run(FORWARD);
motor2.run(BACKWARD);
}
}
int obstacle() {
digitalWrite(Trig, LOW);
delayMicroseconds(4);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
long t = pulseIn(Echo, HIGH);
int cm = t / 29 / 2;
return cm;
}
void robotArm() {
for (int S4value = 290; S4value <= 490; S4value++) {
webotricks.setPWM(servo4, 0, S4value);
delay(10);
}
for (int S3value = 300; S3value <= 450; S3value++) {
webotricks.setPWM(servo3, 0, S3value);
delay(10);
}
for (int S2value = 150; S2value <= 190; S2value++) {
webotricks.setPWM(servo2, 0, S2value);
delay(10);
}
for (int S4value = 490; S4value > 290; S4value--) {
webotricks.setPWM(servo4, 0, S4value);
delay(10);
}
for (int S3value = 450; S3value > 300; S3value--) {
webotricks.setPWM(servo3, 0, S3value);
delay(10);
}
for (int S2value = 190; S2value <= 320; S2value++) {
webotricks.setPWM(servo2, 0, S2value);
delay(10);
}
for (int S1value = 340; S1value >= 150; S1value--) {
webotricks.setPWM(servo1, 0, S1value);
delay(10);
}
for (int S3value = 300; S3value <= 410; S3value++) {
webotricks.setPWM(servo3, 0, S3value);
delay(10);
}
for (int S4value = 290; S4value <= 490; S4value++) {
webotricks.setPWM(servo4, 0, S4value);
delay(10);
}
for (int S4value = 490; S4value > 290; S4value--) {
webotricks.setPWM(servo4, 0, S4value);
delay(10);
}
for (int S3value = 410; S3value > 300; S3value--) {
webotricks.setPWM(servo3, 0, S3value);
delay(10);
}
for (int S2value = 320; S2value > 150; S2value--) {
webotricks.setPWM(servo2, 0, S2value);
delay(10);
}
for (int S1value = 150; S1value < 340; S1value++) {
webotricks.setPWM(servo1, 0, S1value);
delay(10);
}
}
