######
Verified, known issues corrected!
# **1. Work introduction**
This project comes from the winter vacation training camp. It uses GD32F470ZGT6 as the core of a four-wheel drive smart car, tracking, ultrasonic obstacle avoidance, Bluetooth remote control, DHT11 temperature and humidity measurement, OLED display of battery temperature, temperature and humidity and other information. . Powered by 1450 lithium batteries, two strings of lithium battery charging modules of CS5090EA. Reserve the openmv serial port pins for later completion of advanced functions: finding color blocks, face detection, eye tracking, edge detection, mark tracking, etc.
``` ada
(1) Place two LEDs on the front of the car to simulate the car lighting system and learn the output function of the microcontroller;
(2) Use independent buttons to simulate the one-button start function of the car and learn the input detection of the microcontroller;
(3) No power on the road What to do, use the battery voltage detection function and learn the ADC voltage acquisition function;
(4) Four-way motors are independently controlled to realize the car walking, and learn the motor drive and PWM output functions;
(5) There are obstacles in front, and ultrasonic obstacle avoidance allows the car to move. Safer, learn the use of sensors;
(6) Infrared photoelectric tube, realize the car's driverless tracking function, learn the use of sensors;
(7) Use the Bluetooth module to control the car's driving through the mobile phone APP, and master the serial port protocol and data transmission ;
(8) Use the lithium battery module to charge the car through type-c, which saves the car from the trouble of changing batteries;
(9) Use the DHT11 module to measure the temperature and humidity of the car, and learn the single bus protocol to communicate with the microcontroller;
(10) ) Use the OLED module to display information such as the car's power, temperature and humidity, and learn IIC communication.
```
![1.png]
# **Physical display:**
![3.jpg]
![4.jpg]
![1.1.jpg]
![2.jpg]
![5.jpg]
![6 .jpg]
# Lithium battery charging display
***Charging process***
CS5090E adopts a complete CC/CV charging mode.
1. When the voltage of the double-cell lithium battery is less than 2V, the system charges the battery at 1/20 lcc.
2. When the voltage of the double-cell lithium battery is greater than 2V and less than 5.6V, the system charges the battery at 1/10 Icc.
3. When the voltage of the double-cell lithium battery is greater than 5.6V, the system enters constant current charging mode.
4. When the battery voltage is close to 8.4V, the system enters constant voltage mode. After entering constant voltage mode, if the charging current is less than 100mA, the system will stop charging.
5. When the battery is fully charged, if the battery voltage drops below 8.2V, the system will restart to charge the battery.
***Protection Function***
CS5090E has complete battery charging protection function. 1. When the chip experiences overvoltage at the input end, overvoltage at the output end, or overtemperature, the boost charging function will be turned off immediately.
2. When the battery voltage is lower than VsHORT, the output undervoltage protection function is turned on, the main power tube is turned off first, and the block tube will enter linear mode and charge the battery with a charging current of 1/20 lcc.
3. When the battery voltage is higher than VsHORT, the output short circuit protection function is turned off.
***Adaptive input current limit function***
CS5090E has a built-in special loop that can automatically adjust the charging current to protect the input DC power supply from entering an overdrive state. Because a large charging current will cause the input power supply voltage to drop, as the power supply voltage drops, the input terminal of the internal adaptive loop op amp also drops. When it is reduced to the internal reference value, the built-in adaptive loop automatically adjusts the system duty cycle to reduce the charging current to reduce the driving pressure of the input power supply, so that the output voltage is fixed at 4.5V. ***Charging LED indication***
1. It stays on during charging and turns off after charging.
2. When input overvoltage, output undervoltage or overvoltage occurs, the NTC port detects abnormal battery temperature, output short circuit, charging time times out or chip overtemperature, it will flash at a frequency of 1.6Hz.
![IMG_20230210_172850.jpg]
![IMG_20230210_172917.jpg]
# 2. Function introduction
### **1. Lithium battery charging**
CS5090E is a 5V input, maximum 1.5A charging current, supports dual-cell lithium battery series application, Boost charge management IC for lithium-ion batteries. CS5090E integrates power MOS and adopts an asynchronous switching architecture, which requires only a few peripheral devices during application, which can effectively reduce the overall solution size and BOM cost. The CS5090E's boost switching charging converter operates at 500KHz and has a conversion efficiency of 90%. The CS5090E has an input voltage of 5V and a built-in adaptive loop that can intelligently adjust the charging current to prevent the adapter output from being overwhelmed and can match all adapters. CS5090E provides a tiny ESOP8L package type for customers to choose from, and its rated operating temperature range is -40°C to 85°C.
![1.png]
![2.png]
**(Note: ++When purchasing an IC, be sure to ask whether it is CS5090E or CS5090EA, because CS5090E is no longer produced, so some merchants will ship CS5090EA. The circuit design of the two is slightly different, and the charging current calculation formula is 10 times different, so when using the CS5090E with a 10K resistor, the maximum charging current can reach 1A, while the 5090EA will be 0.1A ++)**
**. More detailed parameters: CS5090E specification sheet [[http://www.szczkjgs.com/products_3834.htm](http://www.szczkjgs.com/products_3834.htm)]**
### **2. Power supply The module's **
power input uses two 14500 lithium batteries for power supply. The working voltage is 3.7*2=7.4V. The LDO linear voltage regulator chip reduces the voltage by 5v to supply power to the main control chip and module. The lithium battery 7.4v supplies four N20s. The motor driver chip
provides power. Ensure stable operation between various modules.
![1.png]
### 3.
The infrared tracking circuit of the tracking module is based on the ITR9909 sensor and uses the LM393 comparator to detect the input status. With the potentiometer for precision adjustment, the measurement distance can be within the range of 1mm~15mm. adjust.
Car tracking generally involves walking along a black line on a white floor, using the reflection of infrared light in different colors for identification. Infrared light is always emitted to the outside. If the bottom of the car is a white floor, the light will be refracted back. At this time, the receiving tube receives the signal and outputs a low level through the comparator, the LED indicator light turns on, and the microcontroller detects the low level; if the car is driving on Around the black line, the infrared light is absorbed by the black color, and the receiving tube cannot receive the emitted signal. At this time, the comparator circuit output is high level, the LED indicator light goes out, and the microcontroller detects the high level. Tracing is actually a process of finding black lines and walking along them.
![1.png]
### 4. ******LED drive circuit******
A car without lights has no soul, so you must choose bright LEDs to simulate the left and right sides of the car. car lights. The cathode of the LED lamp is connected to the power supply ground GND. The value of the current limiting resistor here is slightly smaller, making the LED current larger and the lamp brighter. The program control of LED lights is also relatively easy. The left end of the R23 resistor is connected to an LED-R network tag and the microcontroller pin. When the pin outputs a high level, the diode conducts and the LED lights up. By using the timer, delay and IO port output configuration, you can achieve the effects of flashing car lights and high and low brightness.
![1.png]
### 5. ******Button circuit******
By pressing the button to select one-button start and mode switching function, it can be controlled by using two independent buttons on the smart car. Startup and mode conversion functions. The button pin is connected to the interrupt pin of the microcontroller, and can also be used for interrupt experimental demonstrations. Use 100nf capacitor for physical debounce.
![1.png]
### 6. The ******buzzer circuit******
uses a 3V active buzzer: it has its own oscillation source, connect the positive and negative poles to the DC voltage. Continuous sound generation with fixed frequency.
Because the pin drive capability of the microcontroller is limited and the power of the buzzer is relatively large, it needs to be driven by a transistor. R11 is the current limiting resistor. If the microcontroller pin (BUZZER) is given a low level, the transistor will be turned on, and 3.3v will Supply power to the buzzer to make a sound. If the buzzer is given a high level, the transistor will be disconnected. (Note: **The buzzer is active 3v**)![1.png]
### 7. ******ADC sampling circuit******
ADC is an analog-to-digital converter (or The abbreviation of AD converter). ADC is a device that converts analog quantities into digital quantities. A common application is to convert continuously changing voltage values into digital quantities. The principle is the sampling principle, which can be simply understood as sampling the voltage value at a certain frequency so that the continuous value becomes a discrete value, and a number of digital quantities are obtained.
Using two lithium batteries for power supply, the maximum voltage is 4.2*2=8.4V. However, the reference voltage of the Liangshan School development board is 3.3V and cannot collect 8.4V. Then you need to use resistors to divide the voltage or use an op amp circuit to reduce the voltage. to within the voltage tolerated by the microcontroller. Here we use three 10K resistors to divide the voltage, and take 1/3 of the voltage point and connect it to the ADC pin of the microcontroller. ![1.png]
### 8. Motor drive circuit
This module uses four RZ7899 as drive chips. Each chip can withstand 3A drive current and 3V-25V drive voltage. You can directly use the microcontroller pins to control OUTA and OUTB output status. Both outputs can independently control a DC motor to move forward, backward, and brake.
![1.png]
**Note: The speed can be adjusted through PWM, but the frequency cannot be too high, otherwise the RZ7899 will heat up very much, and the PWM frequency set in actual use is less than 1K. **
**![1.png]
### 9. Ultrasonic module
The model of the ultrasonic module is **HY-SRF05**. It uses five pins to connect to the microcontroller, which are GND, OUT, VCC, Trig and Echo. Pins, except for the power pins, only two signal lines are needed to detect the distance of ultrasonic detection of obstacles in front. Suitable for four-legged ****HC-SR04. ****
![2.png]
**Basic working principle:**
(1) Use the IO port TRIG to trigger ranging and give a high-level signal of at least 10us.
(2) The module automatically sends 8 40khz cycle levels and detects echoes. Once an echo signal is detected, an echo signal is output.
(3) **Echo signal**: A high level is output through the IO port ECHO. The duration of the high level is the time from emission to return of the ultrasonic wave. Test distance = (high level time * speed of sound (340M/S))/2 or us/58 = centimeters or us/148 = inches.
The timing diagram is as follows:
![1.png]
In general, if you send a high level of more than 10us to the control port Trig, you can wait for the high level output at the receiving port. Once there is output, you can start the timer. When When this port becomes low level, you can read the value of the timer. At this time, it is the time of this distance measurement, and the distance can be calculated. With such continuous periodic measurement, you can reach the value of your mobile measurement.
**Note: This project uses HY-SRF05 with 5 pins, which is suitable for HC-SR-4 with 4 pins. **
**![1.png]
### 10. DHT11 temperature and humidity measurement
DHT11 digital temperature and humidity sensor is a calibrated [digital signal] (https://so.csdn.net/so/search?q =%E6%95%B0%E5%AD%97%E4%BF%A1%E5%8F%B7&spm=1001.2101.3001.7020) output temperature and humidity composite sensor, which is internally controlled by an 8-bit microcontroller and a resistive humidity sensing element. and an NTC temperature measuring element. Although DHT11 also uses a single bus protocol, this protocol is slightly different from the single bus protocol of DS18B20. Compared with DS18B20, which can only measure temperature, DHT11 can detect both temperature and humidity. However, the accuracy and measurement range of DHT11 are lower than DS18B20. Its temperature measurement range is 0~50℃, and the error is ±2℃; humidity The measurement range is 20%~90%RH (Relative Humidity - refers to the percentage of water vapor pressure and saturated water vapor pressure in the air), and the error is ±5%RH. The DHT11 circuit is very simple. You only need to connect the DATA pin to an I/O of the microcontroller. However, this pin needs to be pulled up with a **5K** resistor. The power supply voltage of DHT11 is **3~5.5V** .
![2.png]
###
### 11. The OLED display
uses a 0.96-inch OLED with four-pin IIC communication to display information such as temperature and humidity, remaining power of the car, ranging distance, etc., which is helpful for debugging the car.
![1.png]
### 12.
Since the Bluetooth module is to be used as a smart car, wireless control is indispensable. Commonly used smart car control solutions include infrared, Bluetooth, WIFI, 2/4G and other solutions. This car uses Bluetooth control. This method has a simple circuit. The mobile phone is the remote control. In addition, you can also learn the design of Bluetooth APP.
The smart car uses the HC05 Bluetooth master-slave module, which has a total of 6 pins. The EN pin is used to control the Bluetooth module to enter the AT command. When set to high level, the status and data transmission of the Bluetooth module can be set; the VCC pin and the GND pin are power input pins, and the input voltage range is 3.6-6V; TXD and RXD are the serial port pins used to connect to the microcontroller. RXD is connected to the TXD of the microcontroller, and TXD is connected to the RXD pin of the microcontroller. Please note that it cannot be connected in reverse; the last pin is the STATE pin, and its function is to display Bluetooth pairing. status. When Bluetooth is connected to the mobile phone, this pin outputs high level.
![1.png]
13. OpenMV camera
OpenMV is an open source, powerful machine vision module.
[Machine Vision] on OpenMV(https://so.csdn.net/so/search?q=%E6%9C%BA%E5%99%A8%E8%A7%86%E8%A7%89&spm=1001.2101 .3001.7020) algorithms include finding color patches, face detection, eye tracking, edge detection, landmark tracking, etc.
Reserve the serial port interface to communicate with it.
![1.png]
# 3. Summary
** This is my second time to participate in the Lichuang training camp. The free curling and board teaching is really attentive. I have benefited a lot from the exchanges and answers among the group members, which makes me I am going further and further on the road of electronics enthusiasts. Thank you very much to Jialichuang! ! !**
**This winter vacation training camp is for smart cars. The smart car I made has been greatly improved. One of the N20 motors is very shaking, the motor speed is very fast, the obstacle avoidance is not very good, and the delay is very high. Not sensitive. The Bluetooth operation is okay, and it is very sensitive to interrupts. **
**The infrared tube I bought had a problem. I changed a batch and found out that I am in my junior year. Now that I have started school, I have no time to improve it. I hope I can improve it and do better in my free time in my senior year. Finally, I am very grateful to Jialichuang for its support and help. **