Car parameters: 5 control keys: forward, backward, turn left, turn right, stop; effective distance 200 meters; speed:
I think everyone has played with remote control cars, and there are also detailed instructions for making various DIY cars on the Internet. The remote control car I made is similar to other works, but as a single-chip microcomputer design, this time I mainly emphasized single-chip microcomputer control, that is, this car is controlled by a single-chip microcomputer. This time I took the single-chip microcomputer button sending program, the use of wireless modules, and motor drive as the core content of this tutorial.
1. Hardware Assembly
1 Car movement part
This picture was assembled by my junior brother, please use it as a reference
Required workpieces: 4 DC motors, L293D motor driver module, a battery, chassis
Note: You can buy the chassis and battery according to your own purchasing power. As for the L293D module, it is more expensive on Taobao, but I use the finished module, and the effect is very good. Students with little money can buy chips and make their own modules. The principle is very simple, and the official information is very detailed; or change to relay control, depending on your actual purchasing power. The advantage of using the module is that the module can output 5V power to power the system. Please refer to Taobao for details.
If you buy a ready-made chassis, it will be the same as mine. There is really nothing to say about assembly. Just fix the motor on it. No? Don't be kidding, even elementary school students can do it! As for those who want to make their own chassis, I want to say that it should be sturdy. Our car has enough horsepower because it is driven by a motor and has a relatively fast speed (be careful with a chassis without a reduction gear, as it has a very fast speed). It also has enough stamina, so it is normal to accidentally hit the wall, so be careful with a bad chassis!
After assembly, it is time to connect the motor and driver module. Now I will explain in detail the use of the L293D module:
L293D is a special motor driver chip, with an operating voltage of 5V, a drive voltage input of up to 36V, an output current of positive and negative 600ma, 4 control terminals, and 4 output terminals. The principle is as follows
picture:
A is the output control terminal, Y is the output control terminal, 1A controls 1Y, and so on. 1, 2EN 3, 4EN need to be short-circuited, and the maximum operating voltage of the chip must not exceed 7V.
Package Diagram:
Vcc1 is connected to the working voltage, 5V, and Vcc2 is connected to the motor's driving power supply. Generally speaking, this voltage should be higher than 5V. I use a 12V battery, so I connect the positive pole of 12v to VCC2. Remember that the chip, microcontroller, and battery power supply need to share a common ground. Don't think that your motor is 12V and the microcontroller control part is 5V, so the power supply should be completely independent. It's true that the positive pole is completely independent, but the GND (negative pole) must be connected together.
Connection method between driver chip and motor:
Example: Left front and rear wheels:
1Y connects to the red wire of the motor, 2Y connects to the black wire of the motor, and the left front wheel motor
3Y connects to the red wire of the motor, 4Y connects to the black wire of the motor, and the left rear wheel motor
Forward command: 1A=1 (output 12V), 2A=0 (output 0V), 3A=1 (output 12V), 4A=0 (output 0V)
Backward command: 1A=0 (output 12V), 2A=1 (output 0V), 3A=0 (output 12V), 4A=1 (output 0V)
The connection method on the right is exactly the same as that on the left.
Note: Forward and backward are not absolute, because it is a DC motor, and the positive and negative poles are not emphasized deliberately. It depends on how your motor is connected. The result can be completely opposite to mine. However, the uniformity of the motor wiring must be ensured. It cannot be arbitrary. You cannot say that the front wheel is connected in a clockwise sequence and the rear wheel is connected in a counterclockwise sequence. If the motor connection wire you buy does not have a color, you must measure it yourself to see which connection is clockwise and which is counterclockwise. Otherwise, the front wheel moves forward and the rear wheel moves backward, which is very damaging to the motor, or the rotation directions of the two pairs of motors on the left and right are not unified, resulting in programming troubles.
The chip outputs 0V by default, so when there is no program, you don't need to worry about the motor turning. One chip can only control 2 motors, so just connect another chip to the right. The modules sold online all have 2 driver chips, which is just enough for 4 motors. The advantage of buying a module is that you can connect it directly, and there are numbers on the module, so you don't have to worry about connecting it wrong. I hope beginners will still buy modules. It is expensive, but the speed is guaranteed! The driver module is as shown in the figure:
After connecting, I will talk about the rotation method of the car: forward and backward means that the four motors rotate forward and reverse at the same time; there are two ways to turn left and right: A rotates while not rotating, B rotates forward while rotating in the opposite direction. These two methods have their own advantages. You can determine the turning method according to your actual situation. The chassis effects of different cars are definitely different. The turning method is controlled by the program. This program is method B.
[page]
This kind of motor is decelerated, so it will not be very fast. If the wheel is driven directly by the motor and a 12V power supply is used, the speed will be very fast. The output of the module is directly connected to the motor power line, and the output is connected to the microcontroller according to the label or program.
Wiring of microcontroller:
As shown in the figure:
This is my smallest system board, all IOs are led out, with onboard USB download function, and the P0 port output is connected to 8-way water lights (with a selection switch). This board is designed to specifically check the output status when the P0 port is output. The board is designed by our studio, and all our work debugging is based on it. This kind of USB download board is also sold online, about 40 yuan!
I am a lazy person, so I used a motor driver module. The inputs of L293D are numbered, and 1-8 can be directly connected to P1.0-P1.7 in sequence. Having said that, I have to say that the wiring of the microcontroller is very free, because it is program controlled, and there is no way to just change the port. I only explain the wiring according to my program, and those who have a basic understanding can design it by themselves!
After the driver chip and the motor are connected, the wires need to be fixed, leaving 8 control wires to be connected to the microcontroller. Also, be sure to leave a small space for the wireless module.
[page]
Wireless module explanation:
Our studio has been using 433 wireless serial port module. I will attach the specific model and price in the list. Now I will talk about its performance. The biggest advantage of this wireless module is that it has strong anti-interference. Two modules can directly set ID. Only modules under one ID number can communicate, and one-to-many communication can be realized. Moreover, this module does not need programming. Just send data to the serial port. The module will automatically modulate and demodulate. As far as the current use is concerned, it has not been found that it has a modulation and demodulation error. It can be said that in data transmission, the error rate of this module is still very low. However, it should be noted that the interval between the module's two receptions (transmissions) should be greater than 200ms. This is a very important parameter. If you want to do high-speed data transmission, please choose it carefully! (This paragraph is from the manual of Taobao Ruidi wireless module. I have also uploaded it. Please respect the copyright of the store.)
The wiring of the module is quite simple, with 2 power lines and 2 data lines: TX (connected to the microcontroller RX), RX (connected to the microcontroller TX). For the setting scheme of the wireless module, please refer to the data manual of the model XL02-232AP1 of Ruidi Wireless on Taobao. The red and green lights of the module will flash at the same time when it is powered on, and then go out, entering the standby state. When the module sends data, the red light is on; when receiving data, the green light is on.
The picture after assembly:
I use a 12V battery. After connecting it to the driver module, the 5V output of the module can directly power the wireless module and the minimum system. Although it looks bulky, the 12V power supply has substantially improved the speed and endurance of ordinary cars!
Remote control part:
hex code, simulation provides hexadecimal file
[page]
source code:
; Receiving program
ORG 0 ; program starting address
SJMP STAR ; Jump to the main program
ORG 30H ;Serial port interrupt address
sjmp loop ; jump to interrupt service routine
STAR:
MOV SP, #5FH ; Set up the stack
MOV SCON, #50H; serial data format (please refer to the 51 manual for details)
MOV TMOD, #20H; Timer working mode (please refer to 51 manual)
MOV PCON, #0; baud rate is not doubled (please refer to 51 manual)
MOV TH1, #0fdH; Set the baud rate to 9600
MOV TL1, #0fdH; Set the baud rate to 9600
SETB EA ; Enable interrupt
clr ET1 ; Disable timer 1 interrupt
SETB ES ; Enable serial port interrupt
SETB TR1 ; Start timer 1
mov a,#0 ;
mov p1, a; set the initial value, that is, p1 output 00h when powered on, the car does not move
main:
mov p1, a; put the value of a into port p1
sjmp main ; infinite loop main program
LOOP:
jnb ri, $; Determine whether the receiving bit is received
clr ri ; clear the receiving bit after receiving
mov a, sbuf; send data to a
reti; after returning, the value of a will be given to p1
END
; Send program
ORG 0 ; program starting address
SJMP START ; Jump to the main program
ORG 30H ;Serial port interrupt address
START:
MOV SP, #5FH ; Set up the stack
MOV TMOD, #20H; Timer working mode (please refer to 51 manual)
MOV PCON, #0; baud rate is not doubled (please refer to 51 manual)
MOV SCON, #50H; serial data format (please refer to the 51 manual for details)
MOV TH1, #0fdH; Set the baud rate to 9600
MOV TL1, #0fdH
setb EA ; Enable interrupt
clr ET1 ; Disable timer 1 interrupt
setb ES ; Enable serial port interrupt
SETB TR1 ; Start timer 1
main:
lcall kcs ;Call key scanning program
jnz key ;If a key is pressed, jump to the key program segment
sjmp main ; infinite loop main program
kcs:
mov p1, #0ffh; p1 is given an initial value
mov a, p1; the value of p1 is given to a
cpl a ; negate a
anl a,#0ffh ;AND operation
ret
key:
lcall delay; software delay program, key debounce
jb acc.0, send1
jb acc.1, send2
jb acc.2, send3
jb acc.3, send4
jb acc.4, send5
ret
DELAY:
MOV R5, #20
D1:MOV R6, #10
D2:MOV R7, #100
DJNZ R7, $
DJNZ R6, D2
DJNZ R5, D1
ret
send1:
mov r1, #10101010b ; forward instruction
sjmp send
send2:
mov r1, #01010101b ; Backward instruction
sjmp send
send3:
mov r1, #01011010b ; turn left instruction
sjmp send
send4:
mov r1, #10100101b ; right turn instruction
sjmp send
send5:
mov r1, #00h ; stop instruction
sjmp send
send:
MOV SBUF, r1 ; instruction to sbuf
JNB TI, $; Determine whether the sending is completed
reti ;Interrupt return
END
Previous article:Simulating PLC Control Using Atmel89S51 Single Chip Microcomputer
Next article:High-precision division usage and program list of 51 single-chip microcomputer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Information] The latest domestic card swiping chip (ultra-low power consumption 13.56M chip)
- Looking to buy a zynq board from Black Gold Technology
- What parameter changes does the OBD2 plug use to obtain the engine speed signal from the OBD interface?
- Study and share information about wildfire motors
- 【Qinheng CH582】8 CH582 evaluation summary
- The robotic arm that won the German Technology Innovation Award
- TMS320C66x programming 16-bit to 32-bit operation
- USB Issues
- Some useful terms related to antennas
- ST Low Power RF Products FAQ