Without further ado, here are the pictures of the real thing
1. Project Components List
1. Buy a smart car chassis from Taobao (my car is four-wheel drive, so it has four motors, two acrylic plates and some accessory screws)
2. Two L298n modules (one 298 controls two motors)
3. HC-06 Bluetooth module
4. Battery box and 3 18650 batteries
5. Single chip microcomputer minimum system
6. At least 12 DuPont wires, the more the better
7. Several wires (for connecting the motor, and the battery box to L298N and the microcontroller)
2. Production process
First, learn about the wiring of L298N. I was also confused for a long time at that time, but I learned it by groping. Generally, there are materials in the store. Then, the use of the Bluetooth module. After getting the Bluetooth module, if you have a development board (if you don’t have it, use the microcontroller burner), first connect TXD to TXD and RXD to RXD, open the computer’s serial port assistant to establish communication with Bluetooth, open AT, and send AT command sets, such as setting the baud rate, changing the name, and changing the pairing password. But when connecting and communicating with the microcontroller via Bluetooth, TXD is connected to RXD. The last one is that I often run into obstacles when wiring. For example, the wire you thought was connected was actually not connected properly, and it didn’t work at all. I still took multimeter B to find out.
Because I forgot to buy the battery box, I used 12V DC power, which caused the remote control car to drag along the wires.
3. Physical picture
(I am dragging a car with a power cord and a power bank, but I don’t have electricity)
The data includes some information about L298N, as well as the Bluetooth manual (just read the AT command set) and source code.
/Mobile Bluetooth remote control car APP can be searched in the application market for Bluetooth serial port assistant
Turning left and right is about 90 degrees. My car is a four-wheel drive. If there is only one l298N, delete the one with 2.
PWM has ten levels of speed change/
#include #define Left_moto2_pwm P0_4 //Connect to the ENA enable terminal of the driver module, input PWM signal to adjust the speed of the left rear wheel #define Right_moto2_pwm P0_5 //Connect to drive module ENB right rear wheel #define Left_moto_pwm P1_4 //Connect to the ENA enable terminal of the driver module, input PWM signal to adjust the speed of the left front wheel #define Right_moto_pwm P1_5 //Connect to drive module ENB right front wheel #define uchar unsigned char #define uint unsigned int sbit P0_4=P0^4; //define P0_4 sbit P0_5=P0^5; //define P0_5 sbit P1_4=P1^4; //define P1_4 sbit P1_5=P1^5; //define P1_5 /Motor drive IO definition/ sbit IN1 = P1^2; //1, left motor reverses the front wheel sbit IN2 = P1^3; //1, left motor rotates the front wheel forward sbit IN3 = P1^6; //1, right motor rotates the front wheel forward sbit IN4 = P1^7; //1, right motor reverses the front wheel /*sbit EN1 = P1^4; //1 left motor enabled sbit EN2 = P1^5; //1, right motor enabled*/ sbit IN5 = P0^2; //1, the left motor reverses the rear wheel sbit IN6 = P0^3; //1, left motor rotates the rear wheel forward sbit IN7 = P0^6; //1, right motor rotates the rear wheel forward sbit IN8 = P0^7; //1, right motor reverses rear wheel /*sbit EN3 = P0^4; //1 left motor enables rear wheel sbit EN4 = P0^5; //1, right motor enables rear wheel*/ bit Right_moto_stop=1; bit Left_moto_stop =1; unsigned int time=0; int pwm=1; #define left_motor_en EN1 = 1 //Left motor enable #define left_motor_stops EN1 = 0 //Left motor stops #define right_motor_en EN2 = 1 //right motor enable #define right_motor_stops EN2 = 0 //right motor stops #define left_motor2_en EN3 = 1 //After the left motor is enabled #define left_motor2_stops EN3 = 0 //After the left motor stops #define right_motor2_en EN4 = 1 //After the right motor is enabled #define right_motor2_stops EN4 = 0 //After the right motor stops #define left_motor_go IN1 = 0, IN2 = 1 // Left motor forward #define left_motor_back IN1 = 1, IN2 = 0 // Left motor reverses #define right_motor_go IN3 = 1, IN4 = 0 //right motor forward #define right_motor_back IN3 = 0, IN4 = 1 //Right motor reverse #define left_motor2_go IN5 = 0, IN6 = 1 // Left motor forward #define left_motor2_back IN5 = 1, IN6 = 0 //Left motor reverses #define right_motor2_go IN7 = 1, IN8 = 0 // Right motor forward #define right_motor2_back IN7 = 0, IN8 = 1 //Right motor reverse unsigned char pwm_val_left =0; // variable definition unsigned char push_val_left =0; // Left motor duty cycle N/10 unsigned char pwm_val_right =0; unsigned char push_val_right=0; // right motor duty cycle N/10 void delay(uint z) { uint x,y; for(x = z; x > 0; x–) for(y = 114; y > 0 ; y–); } //Bluetooth initialization void UART_INIT() { SM0 = 0; SM1 = 1; //Serial port working mode 1 REN = 1; // Allow serial port to receive EA = 1; // Enable general interrupt ES = 1; //Open serial port interrupt TMOD = 0x20; //8-bit auto-reload mode TH1 = 0xfd; TL1 = 0xfd; //9600 baud rate TR1 = 1; //Start timer 1 } /****************************************************************************/ void run(void) //pwm speed control function { push_val_left =pwm; //PWM adjustment parameter 1-10 1 is the slowest, 10 is the fastest. Changing this value can change its speed push_val_right =pwm; //PWM adjustment parameter 1-10 1 is the slowest, 10 is the fastest. Changing this value can change its speed if(pwm10) pwm=0; if(pwm0&&pwm<0) pwm=0; } /*******************************************************************************/ / PWM modulated motor speed / /*******************************************************************************/ /* Left motor speed control*/ /*Adjust the value of push_val_left to change the motor speed and duty cycle*/ void pwm_out_left_moto(void) { if(Left_moto_stop) { if(pwm_val_left<=push_val_left) { Left_moto_pwm=1; Left_moto2_pwm=1; } else { Left_moto_pwm=0;Left_moto2_pwm=0; } if(pwm_val_left>=10) pwm_val_left=0; } else { Left_moto_pwm=0;Left_moto2_pwm=0; } } /********************************************************************/ / Right motor speed control / void pwm_out_right_moto(void) { if(Right_moto_stop) { if(pwm_val_right<=push_val_right) {Right_moto_pwm=1; Right_moto2_pwm=1; } else {Right_moto_pwm=0; Right_moto2_pwm=0;} if(pwm_val_right>=10) pwm_val_right=0; } else {Right_moto_pwm=0;Right_moto2_pwm=0; } } /**********************************************************/ ///TIMER0 interrupt service sub-function generates PWM signal/ void timer0()interrupt 1 using 2 { TH0=0XF8; //1Ms timing TL0=0X30; time++; pwm_val_left++; pwm_val_right++; pwm_out_left_moto(); pwm_out_right_moto(); } //The car moves forward void forward() { ET0 = 1; run(); //pwm program left_motor_go; //Left motor goes forward right_motor_go; //right motor goes forward left_motor2_go; //Left motor moves forward and rear wheels right_motor2_go; //right motor goes forward and rear wheels } void left_go() //Turn left { ET0 = 1; run(); left_motor_back; right_motor_go; left_motor2_back; right_motor2_go; delay(700); forward(); } //Turn right void right_go() { ET0 = 1; run(); delay(50); right_motor_back; left_motor_go; right_motor2_back; left_motor2_go; delay(700); forward(); } //The car turns left void left() { ET0 = 1; run(); delay(50); right_motor_go; // right motor goes forward left_motor_back; // Left motor moves backward right_motor2_go; // right motor goes forward left_motor2_back; // Left motor moves backward } //The car turns right void right() { ET0 = 1; run(); left_motor_go; right_motor_back; left_motor2_go; right_motor2_back; } //The car moves backward void back() { ET0 = 1; run(); left_motor_back; right_motor_back; left_motor2_back; right_motor2_back; } //Stop the car void stop() { ET0 = 0; P1=0; P0=0; } //Serial port interrupt void UART_SER() interrupt 4 { if(RI) { RI = 0; // Clear the receive flag switch(SBUF) { case 'g': forward(); break;//forward case 'b': back(); break;//backward case 'l': left(); break;//Turn left case 'r': right(); break;//turn right case 's': stop(); break;//stop case 'z': left_go(); break; //Turn left case 'y': right_go(); break; //Turn right case 'p': pwm++;break; //acceleration case 'c': pwm–;break; // deceleration } } 1 } void main() { TMOD=0X01; TH0= 0XF8; //1ms timing TL0 = 0X30; TR0= 1; ET0= 1; EA = 1; UART_INIT(); //Serial port initialization while(1); }
Previous article:51 single chip microcomputer drives LCD1602 liquid crystal display system
Next article:Universal password lock controlled by 51 single chip microcomputer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- The board has been mailed, please check the courier number in the post~
- I can't find any information about these two chips.
- [Project source code] Determine the correspondence between the dedicated clock input pin of the FPGA and the PLL
- MCU + I2C communication response signal is abnormal
- 【NUCLEO-L552ZE Review】- 7 : EXTI - One unexpected thing after another
- Issues that should be paid attention to when drawing PCB diagrams from the perspective of welding
- Can anyone help analyze the parameters of this DC-DC transformer?
- In the 5G era, IoT technology empowers smart healthcare
- 【TouchGFX Design】(2) Simple interface design
- Sony HT-Z9F speaker system disassembled with Rockchip RKNanoD chip