Welcome to Roboduino V2 repository
07.IR WiFi Control Car
IR WiFi Control Car
IR WiFi Control CarDevice connectionHardware connectionSoftware connectionImplementation ideasWiFi remote control carData format (communication protocol)Infrared remote control carData analysisCode AnalysisExperimental effectAPP remote control carAPP connectionAPP controlInfrared remote control carInfrared control
Use the K1 button to switch between WiFi remote control car and infrared remote control car in the car function mode selection stage.
xxxxxxxxxxSince the previous tutorial has explained the basic knowledge of all car modules, the car control tutorial will not be repeated, and the main focus is on the car function implementation ideas!
Device connection
Hardware connection
Use Type-B data cable to connect Arduino Uno and computer.
Software connection
Open the "Arduino IDE" software and select the model and serial port number corresponding to the development board.
Implementation ideas
WiFi remote control car: parse the data sent by the WiFi camera through the serial port and control the car according to the data;
Infrared remote control car: receive and parse the data from the infrared receiver, and then control the corresponding peripheral status of the car according to the data.
WiFi remote control car
Data format (communication protocol)
We only parse data in two data formats.
| Data format | Description | Example |
|---|---|---|
| $ | Data header | |
| # | Data tail | |
| Data,Data,Data | Data type 1 | Data represents only numbers: 1,0,0,0 |
| Alphabet+Data | Data type 2 | Alphabet+Data represents a letter plus the following three digits: A100 |
Example:
Data format 1: $1,0,0,0#, $2,0,0,0#, $3,0,0,0#
Data format 2: $A100#, $A090#, $B120#
Note:
Data format 1 is mainly used to control the car status
Data format 2 is mainly used to control the servo angle
Click the function button on Yahboom CAM, the serial port will send data in the above format, our program parses the data and controls the car status.
Infrared remote control car
Data analysis
| Infrared remote control | Parsed data | Function |
|---|---|---|
| Power | 0x00 | Stop all peripheral functions |
| RGB | 0x40 | Switch RGB colors |
| Buzzer | 0xA0 | Control the buzzer |
| Car Forward | 0x80 | Car forward |
| Car Backward | 0x90 | Car backward |
| Car Left | 0x20 | Car moves to the left |
| Car Right | 0x60 | Car moves to the right |
| Car Left Spin | 0x10 | Car rotates left |
| Car Right Spin | 0x50 | Car rotates right |
| Add | 0x30 | Increase speed |
| Sub | 0x70 | Decrease speed |
| Number 0 | 0xB0 | None |
| Number 1 | 0x08 | None |
| Number 2 | 0x88 | None |
| Number 3 | 0x48 | None |
| Number 4 | 0x28 | None |
| Number 5 | 0xA8 | None |
| Number 6 | 0x68 | None |
| Number 7 | 0x18 | None |
| Number 8 | 0x98 | None |
| Number 9 | 0x58 | None |
Code Analysis
The code content is not introduced here. For detailed code, please refer to the corresponding code file, which is provided in the download area!
This function combines the infrared remote control car and WiFi remote control car function codes. You can understand the ideas based on the code.
Experimental effect
After the program is started, the RGB light on the car expansion board will display white, indicating that the remote control function mode selection stage has entered.
Mode switching: Press the K1 button on the car expansion board to switch between two remote control modes. The mode switching time is about 5 seconds. Once the RGB does not display color, it means that the function switching mode is over and the last selected remote control mode is retained.
RGB light displays white: WiFi remote control car mode
RGB light displays red: infrared remote control car mode
xxxxxxxxxxIf you want to switch the remote control mode again, you can press the Reset button on the development board to restart the program!
xxxxxxxxxxThe drive motor needs an external battery pack and the expansion board switch is turned on to drive normally.The burning program cannot use other programs to occupy the serial port or the external serial communication module (for example: WiFi camera module), otherwise the program cannot be burned or an error message will be prompted!
APP remote control car
The car function mode needs to select WiFi remote control car mode: the initial setting is WiFi remote control mode after the program starts. Please wait for 5 seconds before remote control operation.
APP connection
The mobile phone connects to the hotspot of the WiFi camera (the name of the built-in hotspot: Yahboom_ESP32_WIFI), and then open the YahboomCam software.
xxxxxxxxxxSome mobile phones will prompt for connecting to a hotspot without a network. We need to click to keep connected!

Enter IP:192.168.4.1 in the YahboomCam software, then click to log in and enter the APP control interface.
xxxxxxxxxxThe IP of the WiFi camera's built-in hotspot is 192.168.4.1

APP control
After entering the APP interface, the APP will display the camera screen.
xxxxxxxxxxIf there is no display, check whether the phone is connected to the WiFi camera hotspot normally

Left button
Control the movement of the car: U (forward), D (backward), L (left move), R (right move), S (stop), LT(left rotation), RT(right rotation)
Right button
Control the rotation angle of the servo: CL(rotate left), CR (rotate right), CU (rotate upward), CD (rotate downward)
Note:
Image problem: Due to the installation problem of the WiFi camera on our car, we need to check the horizontal flip and vertical rotation of the camera, so that the displayed image will be normal!
Servo control problem: Our car is only equipped with one servo, so it can only be controlled by the left and right of the servo, and the rotation range is controlled in front of the car [35°, 145°].
xxxxxxxxxxThe car program limits the rotation angle of the servo sent by the APP, and the control rotation range is [35°, 145°], which is to avoid collision or squeezing between the WiFi camera and the car expansion board.
Infrared remote control car
The car function mode needs to select the infrared remote control car mode: please press the K1 button within 5 seconds after the program starts. When the RGB light of the expansion board changes from white to red, it means that the mode is switched to infrared remote control.
Infrared control
Use the infrared remote control to aim at the infrared receiver on the car expansion board to control the buttons. The APP only sets the functions of some buttons.

| Infrared remote control | Parse data | Function |
|---|---|---|
| Power | 0x00 | Stop all peripheral functions |
| RGB | 0x40 | Switch RGB colors |
| Buzzer | 0xA0 | Control the buzzer sound |
| Car Forward | 0x80 | Car forward |
| Car Backward | 0x90 | Car backward |
| Car Left | 0x20 | Car moves to the left |
| Car Right | 0x60 | Car moves to the right |
| Car Left Spin | 0x10 | Car spins left |
| Car Right Spin | 0x50 | Car spins right |
| Add | 0x30 | Speed increase |
| Sub | 0x70 | Speed reduction |
The infrared remote controller controls the movement of the car. You need to press and hold to perform corresponding control: for example, long press the car to move forward, and release the button to stop the car.
xxxxxxxxxxIn order to avoid infrared light interfering with the sensor, we need to use the infrared remote control function indoors