How to make a 4-in-1 smart robot car using an Arduino Nano board | Obstacle avoidance | Gesture control | Remote control | Voice control
Hello and welcome back. In this project, we will learn how to make a 4-in-1 smart robot car using an Arduino Nano board. The four key functions of this robot are obstacle avoidance, Bluetooth remote control, voice control, and gesture control. I have used an ultrasonic sensor to detect obstacles and an HC05 Bluetooth module for Bluetooth communication. Additionally, I used the L293D motor driver IC to control the gear motors, making it a 2WD smart robot. Also, I’ve added an SG90 servo motor that rotates the sensor left and right to scan the surroundings, allowing the robot to detect obstacles in different directions. You can choose any suitable servo motor as you like, but the SG90 works well for this project. If you want to learn how to operate these components individually, please refer to our previous tutorials.
Additionally, I’ve designed a custom PCB for this project. It’s like a car chassis, which means we don’t need to build a separate chassis for that. We can easily solder and install all components onto the chassis PCB. I used JLCPCB to print the PCBs, and you can even get free coupons to print your own PCBs, making it a cost-effective option for prototyping.
OK, let’s do this project step by step. The required components are given below.
- Arduino Nano board x 1 — Our Store / Amazon
- HC-05 Bluetooth module x 1 — Our Store / Amazon
- L293D motor driver IC x 1 — Our store / Amazon
- IC base x 1 — Our store / Amazon
- 5mm white LED x 2 — Our store / Amazon
- 100-ohm Resistor x 2 — Our Store / Amazon
- Male header x 1 — Our Store / Amazon
- Barrel jack socket x 1 — Our store / Amazon
- 5v Active buzzer x 1 — Our store / Amazon
- DIP slide switch x 1 — Our store / Amazon
- Two-pin terminal x 2 — Our store / Amazon
- Female header x 2 — Our store / Amazon
- Gear motor x 2 — Our store / Amazon
- 65mm Robot wheel x 2 — Our store / Amazon
- Cater wheel x 1 — Our store / Amazon
- Li-ion battery x 2 — Our store / Amazon
- Li-ion battery holder x 2 — Our store / Amazon
- Jumper wires — Our Store / Amazon
- Servo motor x 1 — Our Store / Amazon
- Ultrasonic sensor x 1 — Our Store / Amazon
Step 1
Firstly, identify these components.
Step 2
Secondly, let’s order PCBs for this smart car.
- Now, click the instant quote button and upload the Gerber file. You can download it using the link below.
- Gerber file — Download
- I have ordered five black PCBs. Next, select the build time and shipping options, then click the ‘Save to Cart’ button.
Step 3
Thirdly, unbox your PCB package. You will then see the chassis PCB.
Step 4
Next, position the components on the PCB and solder them individually.
Step 5
Now, connect the wheels to the motors and install them on the chassis. I used double-sided tape for this.
Step 6
Afterward, install the caster wheel on the back side of the chassis.
Step 7
Next, connect the gear motors to the two-pin terminals.
Step 8
Now, install the servo motor on the front side of the chassis. Afterward, calibrate the servo motor using the PWM servo motor driver.
Step 9
Next, install the ultrasonic sensor on the servo horn and connect it to the PCB using jumper wires. Afterward, connect the servo motor, L293D IC, and Arduino Nano board to the chassis PCB.
Step 10
Now, install the battery holder and connect it to the DC barrel jack. Then, connect the Arduino board to the computer.
Step 11
OK now copy and paste the following program to the Arduino IDE.
- Code and Gerber file — Download
/*Bluetooth control and Obstacle avoidance car with Arduino Nano
Home Page
*/
#include <Servo.h>
Servo servo;
int Spoint = 75; //servo center point
int Lvalue;
int Rvalue;
int dis;
int count = 0;
long duration;
int obstacleCount = 0;
#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 10
#define LED1 11
#define LED2 12
#define Buzzer 13
#define trig A1
#define echo A0
#define Speed 180
void setup() {
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
servo.attach(3);//define servo pin
servo.write(Spoint);//servo motor start point
delay(2000);
start();
}
void loop() {
//obstacle ();
//bluetoothControl();
}
//ultrasonic sensor readings
int distance () {
digitalWrite(trig, LOW);
delayMicroseconds(4);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
int t = pulseIn(echo, HIGH);//input pulse and save it veriable
int cm = t / 29 / 2; //time convert distance
return cm;
}
void obstacle () {
dis = distance ();
if (dis <= 9) {
Stop();
Backward();
delay(50);
Stop();
Lvalue = leftsee();
Serial.println(Lvalue);
Rvalue = rightsee();
Serial.println(Rvalue);
if (Lvalue < Rvalue) {
Right();
delay(300);
Stop();
} else if (Lvalue > Rvalue) {
Left();
delay(300);
Stop();
}
} else {
Forward();
}
}
void bluetoothControl(){
if (Serial.available() > 0) {
char value = Serial.read();
Serial.println(value);
if (value == 'U') {
Forward();
} else if (value == 'D') {
Backward();
} else if (value == 'S') {
Stop();
} else if (value == 'L') {
Left();
} else if (value == 'R') {
Right();
} else if (value == '1') {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
} else if (value == '2') {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
} else if(value == '3'){
digitalWrite(Buzzer, HIGH);
} else if(value == '4'){
digitalWrite(Buzzer, LOW);
}
}
}
void Forward() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void Backward() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void Stop() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
void Left() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void Right() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void start() {
servo.write(0);
delay(500);
servo.write(180);
delay(500);
for (byte a = 0; a < 5; a++) {
servo.write(50);
delay(100);
servo.write(110);
delay(100);
}
servo.write(Spoint);
}
int leftsee() {
servo.write(150);
dis = distance ();
delay(1000);
return dis;
}
int rightsee() {
servo.write(30);
dis = distance ();
delay(1000);
servo.write(Spoint);
return dis;
}
- Now, uncomment the obstacle function first.
- Afterward, select the board and port. Then, click the upload button.
Step 12
Next, remove the USB cable and insert the batteries into the battery holder. Then, power on the robot. Finally, you can test the robot using obstacles. If the servo motor doesn’t reach the correct positions, adjust the angles as needed.
Step 13
Now, let’s try the Bluetooth remote control, gesture control, and voice control modes. To do this, power off the robot and reconnect the Arduino board to the computer. If the Bluetooth module is connected, please remove it. Then, comment out the obstacle function and uncomment the Bluetooth control function in the previous code.
- Afterward, select the board and port. Then, click the upload button.
Step 14
Next, remove the USB cable and connect the Bluetooth module to the PCB. Then, power on the car and download the SriTu Hobby app from the Play Store. Now, run the app and open the Bluetooth control remotes.
- You can download it using this link — Download
Step 15
Now, click the gear wheel icon and find your device. At this point, you have to enable location and location permission. Then select your Bluetooth module. Finally, you will see the green indicator on the screen.
Step 16
Afterward, you can try the gesture and voice control modes. To do this, click the arrow drop-down button and select the mode. At this point, also connect your car to the remote. Enjoy the project! The full video guide is below. We hope to see you in the next project. Have a great day!
Troubleshooting Tips
- Check all connections.
- Check the Bluetooth connection.
- Check the motor directions. If they don’t rotate correctly, please swap the wires.
- Calibrate the servo motor properly. If it doesn’t reach the correct positions, adjust the degrees as needed.
- Update the app to the latest version.
- Check the power sources.
- Check the status of hardware components.