The mobile robot consists of 2 types of sensors: the ultrasonic and the TCRT5000 sensor.

In this article, sponsored by JLCPCB, you will learn step-by-step how to build a 2-wheel mobile robot from scratch. I'll even show you how to assemble the Arduino UNO shield plate itself to facilitate the connection of all electronic devices of your 2-wheel mobile robot.

See some images of our project.

r4.png

This article has a lot of information for you to build any 2-wheel mobile robot. I invite you to discover the JLCPCB Mobile Robot with 2 wheels.

After reading this article, you will learn:


Build your 2-wheel mobile robot right now with Arduino UNO and various resources.

2-Wheel Mobile Robot Development

Our Mobile Robot was modeled and developed with the help of Fusion 360 Software. See some images of our digital prototype.

Every 2-wheel mobile robot must consist of the following items:

2-Wheel Mobile Robot Chassis

Based on this structure you can build any mobile robot. Next, we will present and discuss each item mentioned above.

2-Wheel Mobile Robot Chassis Structure

The robot chassis is made up of all the parts that make up the structure. Each piece of the structure has its purpose. Next, we'll introduce them all.


Figure 3A - 2-Wheel Mobile Robot Chassis complete frame.


Figure 3b - Mobile Robot Chassis with electronic elements.Figure 3C - Part of the base of the 2-wheel mobile robot.Figura 3D - Part from the upper region of the mobile robot.Figura 3E - Part for fixing the Mobile Robot ultrasonic sensor.Figure 3F - Part for fixing the motor drive driver.Figure 3G - Spacers for fixing the parts of the base and top cover of the mobile robot.

The chassis structure of the mobile robot is formed by a set of 14 pieces. Next, we will discuss the purpose of each.

In each part of the structure, several elements were added to add functionalities to the mobile robot. Among them, we have a button to turn the mobile robot on and off.

Button to turn the robot on and off

Most mobile robot chassis do not have a structure for attaching a button. We fixed the button in the base region. Through this button, we can turn our robot on and off.

Figure 4A - View of the button in the lower region of the mobile robot base piece.Figure 4B - Base piece with cutout for fixing the ON/OFF button.

Figure 4C - Top view of base piece with button attached.

In the figure above, it is possible to observe the button fixed at the place where the piece was cut.

Battery system for powering the 2-Wheel Mobile Robot

The mobile robot's power supply system consists of 2 18650 batteries. They were used to ensure greater autonomy in the robot's operation.

The mobile robot draws a current of an approximate value of 560 mA.

Our batteries have a capacity of 2600 mAh. Therefore, the robot is capable of operating for about 4 hours and 30 minutes.

This result is obtained through the equation: time = capacity/consumption

So we have:

time = (2600 mAh/560);

time = 4h 30 min

The batteries are shown below and connected in series to provide a voltage of 7.4V.

Figure 5 - 18650 Battery.

We use a connector installed on the rear of the mobile robot. This socket allows the installation of 2 batteries.

Figure 6 - Socket of 18650 Battery.

Figure 6 - Socket of 18650 Battery.

The 2 wires (positive and negative) will be used to power the auxiliary control board and power the entire system.

Connection auxiliary board and Arduino UNO

For this project, we developed an auxiliary board for connecting all devices. It was created to solve a big problem and can be useful for you. Pay attention to it!

In many projects we need, for example, to connect all GND terminals through the use of soldering. This makes connecting cables more difficult and makes the circuit more complex.

This also happens for connections of other voltage levels.

To avoid this problem, we developed the shield in the figure below. This shield has multiple GND rails, +3.3V, +5V, Vin, and Arduino pin terminals.

Figure 7 - Arduino Shield Board.

Figure 7 - Arduino Shield Board.

Save your time in assembling projects and use this shield. We provide 5 free samples for you to earn and use in your projects.

Access the walkthrough below and get 5 free samples.

You must follow all these steps below.

In the figure below we have the shield connected to Arduino UNO.

Figure 8 - Shield connected in Arduino.

Figure 8 - Shield connected in Arduino.

After connecting all the devices, Arduino will be responsible for reading the sensors, processing the data, and activating the motors to control the movement of the 2-wheel mobile robot.

2-Wheel Mobile Robot Sensors

The mobile robot consists of 2 types of sensors: the ultrasonic and the TCRT5000 sensor.

The ultrasonic sensor is installed on the front of the mobile robot. See the figure below.

Figure 9 - Ultrassonic sensor connected in piece.


The ultrasonic sensor is used so that the robot can detect and avoid obstacles. This calculation is based on the speed of sound propagation in the air.

The propagation speed of sound in air is 340 m/s. The Arduino triggers the sensor to emit the sound signal and measures the time (t) that the signal goes back and forth to the receiver.

From the speed data (340m/s) and time (t), we were able to calculate the distance between the robot and the object.

The distance is determined from the equation below.

Distance = 0.034*(t/2)

From this equation, the robot determines the distance and changes its trajectory if it is close to an obstacle.

Finally, we have the TCRT5000 sensors for the line follower function. Two sensors were fixed in the lower region of the base piece of the mobile robot. See the figure below.

Figure 10 - TCRT5000 sensors.

The 2 sensors are responsible for detecting the ground and the line. They must be installed with a distance less than 8mm to the ground. Above that they will not be able to detect the line.

L293D Driver and Direct Current Motors

The mobile robot moves through the use of 2 direct current motors. See the engines in the figure below.

Figure 11 - DC Motors with wheels.

For fixing the motors, two rods were created. In addition to fixing, the rods have the function of creating a space between the lower and upper base of the 2-wheel mobile robot. The rods are shown in the figure below.

Figure 12 - Pieces to connect the DC Motors.

Fixing parts are connected and fixed to the base of the mobile robot. Motors are fixed using M3x30 screws. See the figure below.

Figure 13 - DC Motors installed in the robot structure.

Note one very important thing in the picture above! We solder the wires to the terminals of each motor. We then apply electrical tape. It is very important to use it.

The insulating tape immobilizes the movement of the wires in the region of the terminals and prevents movements in the wires from weakening and breaking the motor terminals.

In this way, you protect and extend the life of the DC motor.

Each motor must be connected to the L293D driver control terminals. See the figure below.

Figure 14 - Driver L293D.

The L293D driver is responsible for carrying out the drive, direction and speed control of the mobile robot motors.

Command signals are sent via 4 digital pins of the Arduino UNO.

Next, we will present a connection circuit to program the function of avoiding obstacles and control via bluetooth.

2-Wheel Mobile Robot Electronic Circuit

Below we have the developed circuit. We have the power circuit, which is made up of the two batteries and the button.

After pressing the button, the system energizes the entire circuit of the 2-wheel mobile robot.

All peripherals (bluetooth module, ultrasonic sensor and L293D driver).

Figure 15 - Electronic Schematic of the Mobile Robot with 2 wheels.

Figure 15 - Electronic Schematic of the Mobile Robot with 2 wheels.

The 2 motors are connected to the L293D driver terminals.

The GND and +5V terminals that connect to each other must be connected to the +5V and GND pin bar of the shield board. This process facilitates and reduces the complexity of circuit connections.

After understanding the circuit, we provide the code to avoid obstacles.

Mobile robot control and drive logic

The code below allows the mobile robot to work autonomously through the use of the ultrasonic sensor. At certain time intervals it will take the reading and check for obstacles in front of the robot.

If this is true, then the robot will change its direction of movement. See the code below.

#define Motor1A 2#define Motor1B 3#define Motor2A 4#define Motor2B 5#define echoPin 10#define trigPin 11long tempo = 0;byte distancia = 0;void setup() {    pinMode(Motor1A, OUTPUT);  pinMode(Motor1B, OUTPUT);  pinMode(Motor2A, OUTPUT);  pinMode(Motor2B, OUTPUT);  pinMode(echoPin, INPUT);  pinMode(trigPin, OUTPUT);}void loop() {    digitalWrite(trigPin, LOW);  delayMicroseconds(2);  digitalWrite(trigPin, HIGH);  delayMicroseconds(10);  digitalWrite(trigPin, LOW);  tempo = pulseIn(echoPin, HIGH);    delay(300);  distancia = tempo * (0.034/2);    if(distancia >= 10)  {    frente();  }    else        {    parar();    delay(500);    direita();    delay(1000);    parar();  }  }void frente(){  digitalWrite(Motor1B, LOW);  digitalWrite(Motor2B, LOW);    digitalWrite(Motor1A, HIGH);  digitalWrite(Motor2A, HIGH);}void re(){  digitalWrite(Motor1A, LOW);  digitalWrite(Motor2A, LOW);    digitalWrite(Motor1B, HIGH);  digitalWrite(Motor2B, HIGH);}void parar(){  digitalWrite(Motor1A, HIGH);  digitalWrite(Motor2A, HIGH);    digitalWrite(Motor1B, HIGH);  digitalWrite(Motor2B, HIGH); }void direita(){   digitalWrite(Motor1B, LOW);    digitalWrite(Motor2A, LOW);      digitalWrite(Motor1A, HIGH);    digitalWrite(Motor2B, HIGH);}

Next, we will explain step by step the developed set of lines.

First, we defined the names for the pins and declared the variables used.

#define Motor1A 2#define Motor1B 3#define Motor2A 4#define Motor2B 5#define echoPin 9#define trigPin 8long tempo = 0;byte distancia = 0;

After that, we enter the setup function and configure the motor driver and sensor drive pins as digital inputs and outputs.

void setup() {  Serial.begin(9600);    pinMode(Motor1A, OUTPUT);  pinMode(Motor1B, OUTPUT);  pinMode(Motor2A, OUTPUT);  pinMode(Motor2B, OUTPUT);  pinMode(echoPin, INPUT);  pinMode(trigPin, OUTPUT);}

In the loop function we have the main logic of the project. See the code portion below.

void loop() {    digitalWrite(trigPin, LOW);  delayMicroseconds(2);  digitalWrite(trigPin, HIGH);  delayMicroseconds(10);  digitalWrite(trigPin, LOW);  tempo = pulseIn(echoPin, HIGH);    delay(300);  distancia = tempo * (0.034/2);    if(distancia >= 10)  {    frente();  }    else        {    parar();    delay(500);    direita();    delay(1000);    parar();  }  }

First you must activate the trigger pin to trigger the sensor signal and count the transmission and reception time. See the code portion below.

digitalWrite(trigPin, LOW);  delayMicroseconds(2);  digitalWrite(trigPin, HIGH);  delayMicroseconds(10);  digitalWrite(trigPin, LOW);  tempo = pulseIn(echoPin, HIGH);

Time is stored in the variable "time".

After that, we calculate the distance value based on the following equation.

distancia = tempo * (0.034/2);

If the distance is greater than 10, then the robot must continue forward movement. Otherwise, the robot must stop, rotate to the right and stop again.

After that, he does a new reading and checks if there are other obstacles in this new direction. If not, then it will move forward.

Finally, all functions for each direction are implemented after the loop function.

We've come to the end of our article and we hope you'll be able to build your own robot with all these instructions.

In case of any question, leave your comment and I will answer you.

IMPORTANT NOTICE FOR YOU!

If you liked this article, please subscribe to the JLCPCB website. That way you will support us and we will be able to continue creating good content and with great instructions to help you.

Access the JLCPCB link and create your account right now. After that, you can use the JLC-REBE discount coupon and get 5 free printed circuit board samples.

Save your time in assembling projects and use this shield. We provide 5 free samples for you to earn and use in your projects.

Figure 16 - Shield to connect all robot devices.

Figure 16 - Shield to connect all robot devices.

Access the walkthrough below and get 5 free samples.

You must follow all these steps below.

Acknowledgments

We thank JLCPCB and Robô Lúdico for all their support in creating this project. Create your JLCPCB account and receive your circuit boards with quality.