How to Build a Robot

DFRobot Robot Project Tutorial

In general, a robot is a virtual artificial or mechanical agent that can react to its environment and make decisions about what to do to achieve a specific goal. Most of the time, a robot is controlled by an electronic circuit or computer program.

DFRobot Robot Platform

The robot platform is a robot’s body that decides how it looks and what it does. In the past, the most common type was a wheeled platform. It has a lot of advantages over other things, like being cheap, having a lot of options, and being easy to design and build.

A “brain” inside of a robot runs programs, makes decisions, and communicates with other things. A microcontroller is the robot's "brain." A popular microcontroller for constructing an Arduino robot is the DFRduino UNO, which is the same as the Arduino UNO. Romeo is another popular microcontroller for making an Arduino robot. There are motors and motor drivers. Motor drivers connect a microcontroller, a battery, and motors. Motors can turn electrical energy into physical movement. It gives the current at the correct voltage and works with microcontrollers to make the motors move correctly.

Robots can sense their surroundings thanks to a variety of electromechanical sensors. The Arduino robot could use an infrared sensor to figure out how far an object is from it, and then the Arduino microcontroller would then get this information. A grayscale sensor is needed to make a line-tracking robot.

Order the Pirate: 4WD Mobile Robot Kit for Arduino with Bluetooth 4.0

STEP 1: Assemble the Motor

Find eight long screws in your parts bag. These hold the motors in place. As illustrated in the image below, position the motors and screw them in place. The parts bag also includes washers and gaskets. Washers generate friction, which helps secure the motors. In an accident, the gaskets help keep the screw nuts from loosening and falling off.

Motor Assembly Schematic
Motor Assembly Schematic


STEP 2: Cable Soldering

Discard the black and red wires. Attach a 15-centimeter black and red cable to each motor (4 motors in total). Then, using your wire stripper, peel the insulation from both ends of the wires (watch out for the photographs below). Solder the wires to the motor pins. NOTE: When soldering, pay attention to the positions of red and black wires. Details can be found in the photographs below.

Cable Soldering


STEP 3: Romeo BLE Controller Assembly

Look for three copper supports. The 1cm supports hold the Romeo controller board. The controller board has three holes, as illustrated below. Insert the three copper supports into the holes and secure them with screws.

Romeo BLE Controller


STEP 4: Assemble the Battery Box

Take out two countersunk screws (their heads are flat). Then attach the battery to the car base, as shown in the image below.

Battery Box


STEP 5: Crafting the Power Switch

Batteries are a robot's lifeline. A power switch controls power usage by turning it off when not used, saving electricity and battery life. Assemble the power switch as shown below. When building the switch, pay attention to the gasket and screw nut order.

Power Switch


We'll start soldering the switch's wires after it's built. Take part of the old wire. Strip the wiring from both ends of the cables to expose the wire inside (same process as with the motors before). Solder the exposed wire ends to the switch pins. When soldering, keep track of the switch's pins' positions.

Charger Switch Connection


Hook up the switch to the charger. Keep track of both items' exact locations. Solder the red cables from the switch to the battery charger as illustrated.

Take one red and one black cable. Connect one cable to the negative pole of the battery charger and the other to the positive pole. Now connect both cords to the Romeo BLE controller.

Cable Connection


After soldering, check to verify that your wiring between the battery and Romeo controller is consistent and matches the pictures above.

STEP 6: Car Base Assembly

Using eight M3x6mm screws, attach the side plates to the front and back bumper plates, as shown by the diagram below. NOTE: During this stage, do not fully tighten the screws at first, so we can easily detach the top board later if necessary.

Car Base Assembly Schematic


Re-attach the base plate to the body, as shown in the picture below.

Re-attach the Base Plate


After assembling the car foundation, remember to install the battery pack!

STEP 7: Microcontroller Board and Motor Connection

We must now do two things before we can connect the motors with the microcontroller board. It's important to pay attention to this diagram. The red and black wires from the left motor should be soldered to M2. The red and black wires from the right motor should be soldered to M1.

You should pay extra attention to the battery pack. The black wire should be soldered into the wire port that says GND. The red wire should be soldered into the wire port that says VND. Use your screwdriver to loosen and tighten the wire ports as soon as the wires are in. Make sure these ports are secure once the wires are in.

NOTE: Make sure that the wires from one motor (the left motor) are soldered into the port for the motor. Motor wires should not be soldered to two different ports. (It's not safe to do this.)

Motor Connection


Installing the top plate and connecting the motor wires to the microcontroller board completes the build. You can install a sensor plate (see diagram below) before attaching the top plate if you don't want to utilize sensors yet.

Install Top Plate


Component Connections Complete


STEP8: Attach a Level to Your Robot

Locate the four holes in the base's top plate. Attach the four M3x60mm Copper Standoffs, then the additional top plate as illustrated in the diagram below using M3x6mm screws. Put some wheels on your robotic platform and let it rip!

Completed Robot


Project Coding

After assembly, program the microcontroller to maneuver your Arduino robot. Once constructed, the robot has all the moving parts. Examine the code samples in the “MotorTest.ino” Arduino file.

Sample code MotorTest:



Upload the code to your microcontroller. The motors and wheels should fire quickly. If not, check your batteries and power switch. Then watch your robot car and see if it can go forward and backward in 1 second. If so, GOOD LUCK. Components do not need adjusting. If you need to adjust the car base or motors, please see the details below.

Check if your robot follows the code above: 1 second forward, 1 second backward. If so, skim the text below, and you're good to go! Most folks will need to modify their motors. Before we do that, let's review our robot's motors and code.

Make the Robot Move Forward

To answer this, let us first evaluate our robot's forward motion. The graphic below depicts this progress.
Robot Move Forward


The red arrow above shows the wheel's direction. As illustrated in the map above, the car can only move forward if both wheels/motors move forward. This robot only advances when both left and right motors and wheels advance.

Code Synopsis

The first line of code is:

#include DFMobile.h // call library
All we’re doing is calling upon/employing a set of functions — the DFMobile library — that exist outside of Arduino’s basic framework.

The next line of code is:

DFMobile Robot (4,5,7,6); // initiate the Motor pin
This function is taken from the DFMobile library (that is, it’s not a universal Arduino function). We use it here to initialize the motor pins (4, 5, 7, 6) on the microcontroller — without this, the motors won’t start.

We’ll be using this function later on as well. Take a look at the function below:

DFMobile Robot
(EnLeftPin,LeftSpeedPin,EnRightPin,RightSpeedPin);
This function is used to initialize the four motor pins (4, 5, 7, 6) and is divided into four separate parameters:

EnLeftPin Pin that controls left motor direction
LeftSpeedPinn Pin that controls left motor speed
EnRightPin Pin that controls right motor direction
RightSpeedPin Pin that controls right motor speed


The robot's motors will not run without this function. In your Arduino program, place this method in the void setup() field.

The robot may start to drift, shift, and not quite follow the code we've given it. The motor wires were not properly soldered to the batteries. Don't worry, we can fix it in code. Using LOW/HIGH values, we can change the car's turn direction.

How to Adjust the Straight Direction for the Robot

To adjust the direction of the motors and wheels, we need the following line of code:

Robot.Direction (LOW,HIGH);
The function is as follows:

Robot.Direction (LeftDirection, RightDirection);
This function is used to make the motors move in a forward direction. The function is divided into two parameters: LeftDirection and RightDirection, which are written in the Arduino code as either LOW or HIGH.

Earlier, we discussed how to make the Arduino robot go forward. LOW/HIGH will be used to correct the robot's movement. In the example code, LeftDirection is set to LOW. However, the robot car's left wheels may rotate backwards. Now simply change the LeftDirection from LOW to HIGH. The same for the right wheels.

For example, LeftDirection is set to LOW in this code. Suppose your left wheels travel backwards instead of forwards. Change LeftDirection from LOW to HIGH. Change it to HIGH and re-upload your code. Your left wheel should now move forward instead of backwards. If this works, try RightDirection (LOW to HIGH or vice versa).

You're done adjusting your Arduino robot's direction! You can now use the robot's basic functions. Before concluding, let us briefly review the Robot.Speed() function.

Look at the following function:

Robot.Speed (LeftSpeed,RightSpeed);
LeftSpeed and RightSpeed are used to set the motor's speed. -255 to 255 is acceptable. The maximum is 255 and the direction is negative.

This function controls the motors' speed. LeftSpeed and RightSpeed are the function's two parameters. The Arduino code for these parameters ranges from -255 to 255. 255 is the fastest forward velocity; -255 is the fastest backward velocity (that is, reversing).

We already configured the robot’s speed in the void setup() part of our code. Now, we can use the speed() function to control the car’s speed and even forward/backwards direction.

Review the following two lines:

Robot.Speed (255,255);
Robot.Speed (-255,-255);
The first line depicts the car driving forward at top speed. The second line depicts the car reversing at full speed. In this sense, speed() is essential. Next, we'll revisit our last section: the robot's movement and rotation.

How the Robot Moves and Turns

The map below displays the robot car's typical routes. For example, if the robot's Left Direction speed is zero, it will turn left if the right wheels are pushed forward.

The following diagram shows how the Arduino robot may move and turn. If the left wheels' speed is set to 0, the right wheels will go forward, causing the Arduino robot to turn left.

Robot Moves and Turns

It's also possible to run more code to test and calibrate your own robot. This is what you need to do: open the file "MotorTest2.ino." This code should help you better understand and figure out how far you can move forward and backward, as well as how far you can turn left and right. Let go of the brakes, put the tires down, and go!


Project copy and images provided by DFRobot. DFRobot was founded from a local maker community in 2008, among the first to embrace open-source hardware. Their mission is to create creative, user-friendly hardware and software products that become the building blocks in all types of electronic projects, while nurturing a vibrant community of learners around it.