0% found this document useful (0 votes)
2 views21 pages

Tutorial Document en

This document is a tutorial for the ESP8266 WiFi Car V2.0, detailing assembly instructions, programming guidance, and code analysis for various functionalities such as movement, following, and obstacle avoidance. It includes sections on motor control, ultrasonic distance measurement, and WiFi remote control setup. The tutorial provides code files and explanations for implementing each feature effectively.

Uploaded by

yg5yhfwggs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views21 pages

Tutorial Document en

This document is a tutorial for the ESP8266 WiFi Car V2.0, detailing assembly instructions, programming guidance, and code analysis for various functionalities such as movement, following, and obstacle avoidance. It includes sections on motor control, ultrasonic distance measurement, and WiFi remote control setup. The tutorial provides code files and explanations for implementing each feature effectively.

Uploaded by

yg5yhfwggs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1 / 21

ESP8266 WIFI CAR V2.0


ZYC0057
V2.02.308.31
2 / 21

Introduction to the tutorial

This tutorial includes the file content as shown below to help you learn more about the car kit and programming knowledge:

"1_Get_start": This folder stores the robot assembly guide and necessary software environment files. In order to complete
the assembly accurately and quickly, please be sure to read the manual in detail and assemble it according to the manual. At
the same time, the prerequisite for realizing program functions is to correctly create the software environment. Please view
the PDF file in this folder.
"2_Arduino_Code": This folder is used to store Arduino code files, upload the codes to the control board for use, each code
function is independent, each time you upload a code, the code uploaded later will overwrite the previous code;
"3_Graphical": This folder stores the graphical programming code and guidance files of the mind+ software.
After completing the car assembly and environment creation, follow this tutorial to gradually complete the smart car
program burning and realize different functions!

For enthusiasts with good programming foundation, you can jump directly to Section 4 to quickly implement the WiFi
remote control function of the car.
3 / 21

Table of contents
1. Let the car move ............................................................................................................................................ 5
1.1 Description ............................................................................................................................................5
1.2 Motor drive module L9110S ................................................................................................................ 5
1.3 How does the driver module L9110S work? ........................................................................................5
1.4 Code burning ........................................................................................................................................ 7
1.5 Code Analysis ....................................................................................................................................... 9
2. Follow the car .............................................................................................................................................. 11
2.1 Description ..........................................................................................................................................11
2.2 Ultrasound ...........................................................................................................................................11
2.3 Code Analysis ..................................................................................................................................... 12
3. Obstacle avoidance car ................................................................................................................................ 14
3.1 Description ..........................................................................................................................................14
3.2 Servo ................................................................................................................................................... 14
3.2 Code Analysis ..................................................................................................................................... 14
4. ESP8266 WiFi Car .......................................................................................................................................18
4.1 Description ..........................................................................................................................................18
4 / 21

4.2 The principle of WiFi remote control .................................................................................................18


4.3 Code upload ........................................................................................................................................18
4.4 Code Analysis ..................................................................................................................................... 19
5 / 21

1. Let the car move


1.1 Description
The content of this section mainly understands the principle of the motor and the motor drive module, and masters how to
control the car robot to complete forward, backward, left turn, and right turn walking through programming.
1.2 Motor drive module L9110S
1. Double L 9110 S chip
2. The working voltage of the motor is between 2.5v-12v, and the maximum working current is 0.8A;
3. It can drive two DC motors or one 4-wire 2-phase stepping motor at the same time.
4. PCB size: 2.8cm *2.1cm ultra-small size, suitable for assembly
5. With fixed mounting holes, diameter: 3mm
1.3 How does the driver module L9110S work?
Through B-1A (PIN 7 ) / B- 2A (PIN 6 ) / A-1A (PIN 8 ) / A-1B (PIN 4 ) output high and low levels or
output pwm to control the forward and reverse rotation of the motor . Here pwm value range (0~255), such as
analogWrite(PIN,180).
State of motion B-1A ( PIN 7 ) B-2A ( PIN 6 ) A-1A ( PIN8 ) A-1B ( PIN 4 )
Forward HIGH LOW LOW HIGH
Backward LOW HIGH HIGH LOW
Turn Left HIGH LOW HIGH LOW
Turn Right LOW HIGH LOW HIGH
stop LOW LOW LOW LOW
6 / 21

Set the speed variable speedCar and the forward function Forward( )

When the car is not going straight forward or backward, you can modify the parameters to adjust: speedCar+10 increases 10
units compared to the original speed, and you can adjust the car to the right. When (IN_2,speedCar-10) you can let the car
go Left adjustment; similarly, setting the parameter value of IN_2 or IN_3 can adjust the speed difference between the left
and right wheels of the car.
7 / 21

1.4 Code burning


Open the code file (folder path: 2_Arduino_Code\1_Motor\1_Motor.ino)

Use the USB cable to connect the control board to the computer and check that the Board Type and Serial Port settings are

correct.
8 / 21

Select NodeMCU1.0 for the board type and COM5 for the serial port here . The serial port will actually appear different,

although COM 5 is selected here , it could be COM3 or COM4 on your computer. Then, click the upload button and wait

for the upload to complete.

After the code is burned successfully, you can see that the car performs forward, backward, left turn and right turn
movements.
9 / 21

1.5 Code Analysis


Motor pin definition

Set the baud rate to 115200, the motor pins are output, and setup() is only executed once when the program starts.

Set the initial value of the speed variable of the left and right motors to 180. When the car does not go straight forward, you
can increase or decrease the speed of one side to adjust the straight line.

According to the previous analysis of the motor drive module, create functions for the car to move in all directions,
including forward function forward(), backward function Backward(), left turn, right turn and stop functions (the code has
been folded).
10 / 21

The loop() loop function calls the function that the car moves in all directions, and controls the execution time through the
delay() function.

If the whole process can be realized to prove that the motor drive wiring is correct, then the following project tasks can be
carried out.
11 / 21

2. Follow the car


2.1 Description
Ultrasonic distance measurement is a very useful and widely used measurement method. This section mainly understands
the working principle of the ultrasonic module, masters the connection of the ultrasonic circuit and realizes the following
function of the car through programming.
2.2 Ultrasonic
How does ultrasound work?
1. Transmitter (trig pin) sends signal: high-frequency sound;
2. When the signal hits an object, it will be reflected;
3. Receiver (echo pin): Receive the signal reflected from it.
There are many methods of ultrasonic distance measurement. The principle of this system in ultrasonic measurement is:
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. According to the time T recorded by the timer , the
distance (S) from the launch point to the obstacle can be calculated.
formula: S = V * T/2
12 / 21

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.

2.3 Code Analysis


Open the code file (folder path: 2_Arduino_Code\2_Follow\2_Follow.ino)
On the basis of the content in the previous section, the definition of ultrasonic sending (2) and receiving (15) pins is added,
and the distance variables measured by ultrasonic waves are distance and cm.

The function GetDistance() used to obtain the ultrasonic detection distance


13 / 21

Call the function to obtain the ultrasonic distance in the main function and save it to a variable, and then compare the
values.

The principle of following the trolley:


When the ultrasonic detection distance of the object in front is less than 5, it backs up, and when it is between 10 and 25, the
car moves forward and follows, otherwise it stops. There are three states of forward, backward and stop.
14 / 21

3. Obstacle avoidance car


3.1 Description
In the previous section, we have understood and learned the relevant knowledge of the ultrasonic module. In this section, we
will add the steering gear to control the ultrasonic rotation function, and master the principle of the obstacle avoidance car ,
and finally realize the obstacle avoidance function through programming.
3.2 Servo

The steering gear ( servo motor ) control pulse signal period is 20MS pulse width modulation signal (PWM), the pulse
width is from 0.5ms to 2.5ms, and the corresponding steering position changes linearly from 0 to 180 degrees.
There is a reference circuit inside the steering gear, which generates a pulse signal with a period of 20ms and a width of
1.5ms. There is a comparator that compares the external signal with the reference signal to determine the direction and
magnitude, thereby generating a motor rotation signal.
3.2 Code Analysis

Open the code file (folder path: 2_Arduino_Code\3_Obstacle_avoidance\3_Obstacle_avoidance.ino)


15 / 21

Principle of obstacle avoidance:


When it is judged that the distance between the ultrasonic wave and the obstacle in front (variable cm) is less than the set
value (< set_dis), let the car stop for 200ms, that is, call the stop function Stop(), and the steering gear will drive the
ultrasonic wave to turn left and obtain the distance between the left ultrasonic wave and the obstacle. The distance between
them is saved to the variable leftDis. Similarly, the ultrasonic wave turns right again to obtain the distance and saves it to the
variable rightDis, and finally the steering gear returns to the front. By comparing the distance between the left and right
sides, let the car drive to the side with the larger distance. If the maximum distance is less than 10cm, then the car will back
and forth and then turn to avoid obstacles.
Create a new obstacle avoidance function avoidance(int set_dis) with parameters. First, save the distance in front of the
ultrasonic detection to the internal variable cm

Determine if an obstacle is encountered ahead (cm<set_dis), and save the left and right distances obtained by ultrasonic
16 / 21

waves to leftDis and rightDis.

When the distance to the right is greater, turn right. If the maximum distance is less than 10, then back up and then turn
right.
17 / 21

In the same way, you can get the code when turning left

Finally keep going straight when there are no obstacles.


18 / 21

4. ESP8266 WiFi Car


4.1 Description
The Esp8266 main controller has a powerful WiFi function, and the WiFi hotspot can be released by setting the AP mode
through programming, and another device can be connected to the hotspot to realize the remote control function.
4.2WiFi remote control principle
The car with the esp8266 main control can release the WiFi hotspot after uploading the corresponding code. For example,
the name of the WiFi hotspot in this project is: ZY ESP8266 Car. After connecting the hotspot with the device with the
command function APP, the remote control command can be sent, and the car receives it. Execute the corresponding action
after receiving the command. During the connection process, you need to enter an IP address to complete the device
connection, and once the connection is successful, it means that your network service has been switched to the esp8266
hotspot instead of your GPRS network, and you are only able to control the car but not Internet situation.
Regarding the installation of APP, there are different installation methods on different devices, please check the
documentation in the folder "4_APP".
4.3 Code upload
Open the code file (path: 2_Arduino_Code\4_esp8266_Car\4_esp8266_Car.ino)
19 / 21

board type NodeMCU1.0 and serial port COM5 in ArduinoIDE .


Click the upload button "upload" and wait for the upload to complete.

4.4 Code Analysis


Import required library files

Set the character variable String command to receive the command and two speed variables speedCar (one big and one
small form a speed difference turn, where 1.5 is the difference multiple relationship, which can be adjusted according to the
actual situation)

Set the WiFi hotspot name variable and instantiate the network service with port 80
20 / 21

Set WiFi mode to AP mode and WiFi name setting

After the connection is successful, the IP address is printed and can be viewed on the serial monitor.

Start the web server and receive the returned html file function HTTP_handleRoot

Execute service interaction within the loop function loop() and save the obtained command status value to the variable
command
21 / 21

Execute corresponding movement according to the received command value. Different letters represent different movement
directions, and 0~9 represent different speeds.

You might also like