Tutorial Documentation
Tutorial Documentation
the assembly is completed and the battery is installed, the infrared remote control can be realized. Then follow the guide to
operate!
Step 1: You need to complete the assembly of the car according to the assembly manual or video guidance;
Step 2: Install the battery (make sure the power is sufficient), turn on the switch of the battery box, and the status light of the
Step 3: Align the infrared remote control with the "infrared receiver" on the main board of the car to control the movement
of the car.
2 / 75
3 / 75
"0_Assembly_guide": This folder stores the robot assembly guide. In order to complete the assembly accurately and quickly,
"1_Arduino software": This folder stores the software download link guide and software installation steps;
4 / 75
"2_Libraries": Change the folder to contain the required library file compression package, select this path to add the
"2_Arduino_Code": This folder is used to store code files, and each code file is uploaded and used independently;
"4_Bluetooth_APP": This folder stores the Bluetooth APP installation package and APP setting guidance tutorial. This
Bluetooth APP is only used in products with a Bluetooth module. If there is no Bluetooth module, please ignore it.
5 / 75
Table of contents
Three Steps To Move ............................................................................................................................................................. 1
Unplug the Bluetooth module from the main control board .......................................................................................... 11
Click the "upload" button to compile and upload the code. ...........................................................................................13
The three control mode buttons are set to send data as follows ..................................................................................... 19
3. Receiver (echo pin): Receives the signal reflected from it. ......................................................................................... 36
7 / 75
Open the "Tools" menu option, click "Development Board", select the board type Arduino Uno.
12 / 75
Then select the COM number of the serial port, here it is COM8, but actually everyone’s COM number will be different.
13 / 75
At the bottom of the editor, you can see that the upload and writing are 100% complete. If there is an error or failure, please
check whether the board type and serial number are displayed normally.
Plug in the Bluetooth module again , and then start the installation and setting of the Bluetooth APP, please see the next
section.
14 / 75
Next, we use an Android mobile phone to demonstrate how to control the car through this application: First, turn on the
Open the APP just installed and make sure that the robot car is powered on, and the Bluetooth is in the state of slow flashing
15 / 75
As shown in the figure, under the "Device Connection" menu, click the middle icon to search for Bluetooth
Find BT05 in the bluetooth device that appears, and then click the "+" on the right to connect. When the icon turns into an
After the connection is successful, click the fourth "button control" option in the bottom menu bar to enter the "button
control" interface
Then click the "Edit Mode" switch to enter the edit mode.
First add direction and stop buttons FORWARD, LEFT, RIGHT, BACK, STOP
17 / 75
Click the button to edit, first add a name: forward (default will be converted to capital letters) , F is the Bluetooth
information to be sent when the button is pressed, and S is the information when it is released. That is, F is sent when
In the same way, modify LEFT, RIGHT, DOWN, STOP. The corresponding information sent is:
BACK B S
LEFT L S
RIGHT R S
STOP S
Taking the setting of the obstacle avoidance mode button as The three control mode buttons are set to send data as
OA 1
FOLLOW 2
TRACKING 3
20 / 75
All settings are completed, turn off the editing mode, and now you can try to remotely control your car
So far, you have learned how to realize the complete process of Bluetooth remote control from scratch. The following
courses will introduce and guide you to learn this kit in detail!
21 / 75
module, and pins are well packaged and drawn out, such as the pins of the Bluetooth module. It also has an LED, which
When you connect the board to the computer with the USB cable , you may find that its LED is already blinking, this is
board using our own Blink sketch , and then change its blink rate. Now keep the board connected to the computer, set up
the Arduino IDE and make sure you can find the correct serial port , and upload the program to test.
The Arduino IDE includes a number of example sketches that you can load and use , including a "blink" example sketch
23 / 75
for making an "L" LED . In the IDE menu system File > Examples > 01. The " Blink " sketch you will find in Basics .
The example sketches included with the Arduino IDE are "read only". That is, you can upload them to the dashboard , but
if you change them, you can't save them as the same file. So the first thing you need to do is save your own copy.
From the Arduino IDE's File menu, select "Save As.." and save the sketch as "MyBlink".
You've saved a copy of the "flicker" in your sketchbook, if you ever want to find it again, just open it using the " File >
Connect the Arduino board to the computer using a USB cable and check that the Board Type and Serial Port are set
correctly.
25 / 75
Note: The board type here is Uno and the serial port is COM5 .
Actually the serial port appears to be different for everyone, even though COM 5 is selected here , it could be COM3 or
COM4 on your computer. A correct COM port should be COM X (arduino X XX) standard.
After clicking the "Upload" button, the program starts to upload. At this time, the LED on the Arduino will start to blink
This could mean that your board is not connected at all, or that the CH340 driver is not installed (if required) or that the
serial port is selected incorrectly . If you encounter this situation, please check your IDE settings and motherboard
27 / 75
connection, and ask business personnel for help after taking a screenshot .
When the upload is complete , the board LED should reboot and start blinking. Note that a large part of this sketch
consists of annotations. These are not actual program instructions; rather, they explain how to make the program work.
They are there for your easy readability . Everything between " /* " and " */ " at the top of the sketch is a block comment ,
A single-line comment starts with "//" and everything up to the end of the line is considered a comment.
Every sketch needs a "setup" function , aka "Void setup()" function, which is executed when the reset button is pressed. It
is executed whenever the board is reset for any reason, such as powering on for the first time or after uploading a sketch .
28 / 75
The next step is to name the pin and set the output, here set " LED_BUILTIN " as the output port. On most Arduinos,
including UNO , pin 13 is the pin corresponding to the LED, and for the convenience of programming, the program has
set the LED_BUILTIN variable to this pin, so it is not necessary to rename it to pin 13 for direct use.
The sketch must also have a " loop " function. Unlike the "Set" function, which only runs once, after a reset, the "Loop"
Inside the loop function, the command first turns on the LED pin (high level), then "delays for 1000 milliseconds (1
second), then turns off the LED pin and pauses for one second.
You are now going to make your LED blink faster. The key, as you might have guessed, is changing the parameters in "
29 / 75
delay ()".
This delay time is in milliseconds, so if you want the "LED" to blink twice as fast, change the value from "1000" to
"500" . This will pause for half a second on each delay, instead of a second. Upload the sketch again and you should see
So far, you have understood and mastered the basic Arduino programming knowledge and the basic steps of downloading
the program, which will lay a good foundation for learning complex projects later.
30 / 75
4. Motor Testing
4.1 Course Introduction
In the previous class, we learned the basic method of uploading programs. In this class, we will learn and master the control
1、ENA controls enable , PWM output, and different combinations of IN1 and IN2 control different outputs
2、out1 , out2 , out3 , out 4 high and low level control motor rotation;
31 / 75
Define the enable terminal pwm pin and IN1/IN2 input terminal
Define the motor speed variable, you can modify the value by yourself (100~220 is more suitable) to get different
movement speeds
The setup function defines the baud rate as 9600 and the pin as output
33 / 75
The loop function loop( ) repeatedly executes forward, backward, left turn and right turn for 3 seconds each. Of course, you
working principle of the ultrasonic module, masters the connection of the ultrasonic circuit diagram, and learns the method
Measuring angle 15 °
Output echo signal Output TTL level signal, proportional to the range
36 / 75
detect the transmission time of the ultrasonic wave from the ultrasonic transmitter through the gas medium to the receiver,
multiply this time by the speed of sound in the air, and obtain the sound propagation time distance.
The ultrasonic transmitter emits ultrasonic waves in a certain direction, and the MCU starts timing at the same time. The
ultrasonic waves are emitted in the air, and return immediately when encountering obstacles on the way, and the
ultrasonic receiver stops timing immediately after receiving the reflected waves.
T recorded by the timer , the distance ( s ) from the launch point to the obstacle can be calculated .
Formula: S = VT/2
37 / 75
Four factors limit the maximum measurable distance of an ultrasound system: the amplitude of the ultrasound waves, the
texture of the reflector, the angle between the reflected and incident sound waves, and the sensitivity of the receiving
transducer. The ability of the receiving transducer to receive the sound pulse directly will determine the minimum
measurable distance.
The control signal enters the signal modulation chip receiver from the channel to obtain a DC bias voltage. It has an internal
reference circuit which generates a period of 20ms and a width of a reference signal of 1.5ms. The obtained DC bias voltage
38 / 75
is compared with the voltage of the potentiometer to obtain a voltage difference output. Finally, the positive and negative
output of the voltage difference is sent to the motor driver chip to determine the forward and reverse rotation of the motor.
When the motor speed is fixed, the driving potentiometer rotates through the cascade reduction gear, so that the voltage
controls the angle. The pulse range is generally 0.5ms~2.5ms. Take the servo motor with a servo of 180 degrees as an
example.
0.5ms 0°
1.0ms 45°
1.5ms 90°
2.0ms 135°
39 / 75
As shown in the picture above (left), the front of the car is facing upwards. When installing the ultrasonic wave, make
sure that the initial position is on the right. The operation method is to use the white mechanical handle (as shown in the
right picture above) to try to twist the central axis of the servo motor, and measure the limit position 0° and 180°. To
ensure that the ultrasonic rotation range (0~180°) is left, front, and right, it is necessary to install the ultrasonic wave at
The induction module light can sense the environment. It has a pair of infrared emitting and receiving tubes. When the
detection direction encounters an obstacle, the infrared receiving tube receives the reflected infrared frequency signal . After
processing by the comparison circuit, the indicator light is on, and the signal output interface Output digital signal (low level
signal) . The effective sensing distance range is 2~30cm, the working voltage is 3.3V~5V , and it has the characteristics of
below), and the signal light is on when an object is detected (as shown in the right picture below). If no object is detected,
both lights are on. This is because the detection distance is too far, and it needs to be adjusted counterclockwise to reduce
OUT port continuously outputs a low-level signal. The detection distance is 2~30cm from the module, and the detection
angle is 35°.
43 / 75
2. The sensor actively detects infrared reflections, so the shape and shape of the reflectivity target is the key to the detection
range. Among them, the black detection distance is small, and the white detection distance is large.
3. The output port OUT of the sensor module can be directly connected to the IO port of the microcontroller ;
4. A 3-5V DC power supply can be used to power the module . When the power is turned on, the red power indicator light is
on.
44 / 75
detects a signal and turns to the left, and the sensors on both sides detect a signal and back off. Otherwise, it is judged that
the ultrasonic detection distance in the front is between 10 and 30cm, and then follow forward, and stop when it is greater
than 30cm or between 5 and 10cm. Finally, when the ultrasonic distance is too close to less than 5cm, the car will retreat.
Define servo, left and right infrared sensors and ultrasonic pins
46 / 75
Initialize the setup, set the servo pin and sensor input and output
task
47 / 75
module. In this course, we will complete a car with automatic obstacle avoidance.
the trolley stops the servo motor and drives the ultrasonic wave to turn left to obtain the distance of the obstacle on the left,
then turn right and obtain the distance of the obstacle on the right and save it to the variables "leftDistance" and
"rightDistance" respectively middle. Then compare the distance, which side has the greater distance, that is, turn to which
The function of defining servo, sensor pin and obtaining ultrasonic distance in the code is consistent with the last lesson.
50 / 75
The moving function adds a slow function forward_U(), and switches to slow forward when the distance to the obstacle is
The obstacle avoidance function Ultrasonic() saves the detected values of the left and right infrared sensors and the distance
When the distance is less than 25cm, the car brakes and stops, and the left and right distances are detected by ultrasonic
51 / 75
Comparing the distance between the left and right sides, the car turns to the side with the larger distance, and the delay(380)
function represents the turn execution time, the larger the value, the larger the turn.
When the ultrasonic detection distance is greater than 25, it is determined whether the obstacles are detected on both sides
52 / 75
of the car and the corresponding avoidance is carried out. Otherwise, the default is to move forward. While moving forward,
7. Tracking Car
7.1 Four-way tracking module:
different reflection intensity characteristics, and the infrared light is continuously emitted to the ground during the driving
process of the car . When the infrared light meets the white floor, it is diffusely reflected and the reflected light It is received
by the receiving tube installed in the car ; if it encounters a black line, the infrared light is absorbed, and the receiving tube
on the car does not receive the infrared light . Therefore, the position of the black line and the driving route of the car can be
54 / 75
The detection information of the 4-way tracking module is obtained in the loop function body, and the car motion control is
carried out according to the detection results (high level means the black line is detected).
On the basis of the original move function, the functions of turning left big turn and right big turn are added, left_M() and
right_M(). The difference between turning big turn and small turn is mainly adjusted in the input pwm of ENA.
56 / 75
In the loop() function, the values of the four sensors are stored in variables.
After the code is uploaded, we open the serial port monitor to view the values read by the four infrared sensors, and see that
the four values are separated by "--" for easy viewing. Under normal conditions, the reading value of the sensor that detects
the black line is 1, and other values are 0. When we see the following numerical situation, the IN1(T_Sensor1) sensor
detects the black line, and the other sensors do not detect the black line.
57 / 75
In the following figure, after the power is energized, the power lamp D5 turns on, and the four infrared sensors connected
from the top to the bottom correspond to four lamps respectively D1/D2/D3/D4.
When the IN1 (T_Sensor1) sensor detects the black line, the corresponding lamp (D1 lamp) turns off and the rest lights on.
58 / 75
When the black line is detected but the corresponding lamp is not off, it is necessary to turn the potentiometer with a
screwdriver (circled position) and slowly adjust to the critical value of the lamp just off.
59 / 75
In the same way, four infrared sensors are used to detect the black line in turn to adjust the potentiometer to ensure that the
light can be correctly turned off each time the black line is detected.
After all the sensors are tested, the car can be put on the black route to walk. The code to control the car to realize the
8 Infrared Control
8.1 Course Introduction
Infrared remote control is a widely used remote control method. The car is already equipped with an IR receiver, thus
allowing it to be controlled using an IR remote. This lesson mainly understands the infrared remote control and receiver ,
the principle of infrared remote control and the idea of learning infrared remote control programming.
infrared remote control, and the receiving part is composed of an infrared receiving tube. The signal sent by the infrared
remote control is a series of binary pulse codes. In order not to be interfered by other infrared signals during wireless
transmission, it generally needs to be modulated at a given carrier frequency, and then transmitted through an infrared
emitting phototransistor. The infrared receiving tube filters out other noise waves, only receives the signal of a given
frequency, and restores it to the demodulated binary pulse code. The built-in receiving tube sent by the infrared
light-emitting diode transforms the optical signal, amplifies the signal through the amplifier in the IC, restores the original
code sent by the remote control through automatic gain control, band-pass filtering, demodulation, and wave formation, and
outputs the signal through the infrared receiving module The pin identifies the circuit that enters the appliance.
The coding scheme that matches the infrared remote control protocol is: NEC protocol. Next, let us understand what is NEC
protocol.
(1) 8 address bits, 8 sequence bits Address bits and sequence bits are transmitted twice to ensure reliability
63 / 75
forward //16712445--"+";
backward //16750695--"-";
Stop //16754775--">";
64 / 75
Open the code file with Arduino IDE (path: " 3_ Arduino _Code
Import the infrared module library and define the encoding variables sent by the infrared remote control
Enable the infrared module, define the variable val and time preMillis used to receive the code
Analyze the received infrared code in the loop function, and then control it through "switch...case" combined with the
66 / 75
movement function
When the time is greater than 500 and the signal is still not received, stop the car.
67 / 75
module , so it can be controlled through a Bluetooth APP . This lesson mainly understands the principle of Bluetooth remote
control, can wirelessly control your car in a specific space and learn the programming ideas of Bluetooth remote control.
Bluetooth is a wireless technology standard for exchanging data between different devices at close range using short-wave
UHF radio waves in various fields including industry, science and medicine. The car is equipped with a BT05 Bluetooth,
and a Bluetooth APP for remote control is prepared in the data package: bluetooth-V1.95.apk. Bluetooth has 4 pins, only the
Note that one side of the Bluetooth has been marked, and the pin arrangement is as follows:
Because Bluetooth will occupy the RX/TX port, so unplug the Bluetooth before uploading the code!
In the previous course, we have mastered the function code of the car movement, such as the forward function "forward()".
In this lesson, we will focus on understanding the mobile control by using "Switch...case" after Bluetooth receives data, and
first judge whether the connection is successful. And receive the Bluetooth data, and execute the corresponding action after
receiving the corresponding Bluetooth data, such as receiving "F" and executing the forward() function.
69 / 75
70 / 75
When the Bluetooth APP presses the OA button, that is, "1" is sent
71 / 75
At this time, "1" is judged by "Switch...case" in the code, and 1 is saved in the mode variable, at this time "Car_mode = 1".
72 / 75
In the loop loop function, the conditional judgment of the mode control is carried out. When car_mode == 1, the obstacle
In the same way, you can understand the programming principles of other modes. Receive "2" for follow mode, receive "3"
The "Follow"function
74 / 75
At this point, the study of the entire tutorial has been completed!