Design of intelligent toy car based on optical sensor

This article refers to the address: http://

Intelligent robots are becoming more and more widely used in today's society. From ordinary toy robots to industrial control robots, robots that can be used for cooking, and robots that can perform space exploration, it is foreseeable that the application of intelligent robots will become more widespread in the future. Everyone is familiar with the ordinary wireless remote control car. Nintendo's video game WII is also very amazing. Familiarity is not fun, and magical can't afford it. It may be a common problem that many people encounter. This design, from a new perspective, creates a smart car that can be played in everyday life, so that readers with common interests.

Overall system design


The principle of the smart car system is that the three-dimensional coordinate sensor is mounted on the trolley, and the trolley has an intelligent sensing function, and then moves along with the object moving forward and backward. The system mainly has three components: one is a three-dimensional coordinate light sensor (ETOMS-ET21X111), which is used to collect the moving coordinates of the target. The sensor is very simple to use. The second is the MCU (EMC-EM78P156), which reads the sensor data to control the motor. Rotating, EM78P156 is a common MCU on the market, easy to use and cheap; third is the motor, the motor can be used with ordinary DC motor, using PWM control. The overall framework of the system is shown in Figure 1.

Figure 1 system overall framework


The overall function of the design is simply summed up: let the car follow the person (or the target). Separately, the following three small functions need to be implemented: the sensor can correctly read the coordinate values ​​of X, Y, and Z, which is the primary condition. The MCU can correctly judge the change in the size of the X and Z coordinate values, which is the key. Some people may have questions, why not judge the Y coordinate changes? That's because the car can't jump up and down (the Y-axis above and below). The MCU controls the timing of the motor steering and motor PWM according to the change in the magnitude of the coordinate value, which is the result.

Hardware system design


1 sensor peripheral circuit design


The ETOMS-ET21X111 is a high-performance light sensor with X, Y, and Z coordinate data output functions. Has the following characteristics: high-speed data output, output coordinate data up to 75frame per second; low voltage operation, voltage range 2.7 ~ 3.5V; use standard RS232 serial data output format output coordinate values; use external crystal oscillator, range 0.5 ~ 12MHz, usually It adopts 3.58MHz; it has controllable exposure interfaces EO4~EO7.


The four interfaces EO4~EO7 are used for exposure control. They can be controlled by software or by hardware. Choose the right one according to your needs. This design uses hardware to set all four interfaces to a high level.


The detailed interface circuit around the sensor is shown in Figure 2. From Figure 2, it can be seen that EO4~EO7 are high. This is because the exposure setting is hardware pull-up, and it can also be set in software. When the IC is working normally, the coordinate data is output by the RS232 port. Note that the four LEDs in Figure 2 are infrared LEDs. The IC operating voltage is 3.3V and the system is powered by 5V. The IC uses a 3.58MHz external crystal oscillator, which can work normally after power-on automatic reset.

Figure 2 sensor interface circuit


2 MCU interface circuit design


The detailed design of the MCU peripheral control circuit is shown in Figure 3. In Figure 3, L and L+ control the left side motor PWM, and R and R+ control the right side motor PWM. RS232 receives sensor coordinate data input. The IC operates at 3.3V and is automatically reset after power-up. The system clock uses a 4MHz external crystal.

Figure 3 MCU interface circuit


3 left motor control circuit


The left motor control circuit is shown in Figure 4. The right motor control circuit is the same as the left one. In the figure, Q3 and Q4 adopt PNP tube, and L and L+ cannot be LOW at the same time to avoid short circuit.

Figure 4 left motor control circuit

Software system design


After the system is powered on, initialize it first, set the register of EMC78P156, enable the interrupt flag register, and wait for the interrupt. Figure 5 is a flow chart of the main program.

Figure 5 main program flow chart


When the interrupt is generated, enter the interrupt processing subroutine. First, close the interrupt flag and protect the scene. Then read and parse the XYZ coordinate values ​​and divide them into the following cases.


(1) Judging the X-axis change. If the X value is greater than 14 or less than or equal to 17, the motor does not rotate left and right, and then the Z-axis coordinate value is judged. If the Z value is also greater than 14 or less than 17, the motor does not rotate back and forth. .


(2) If the X-axis coordinate value is greater than 17, determine the Z-axis coordinate. If the Z-value is greater than 17, the right motor is reversed, then the left and right motors are rotated backwards; if the Z value is less than 14, the forward motor is rotated, and then the left and right motors are Turn; otherwise the motor does not rotate.


(3) If the X-axis coordinate value is less than 14, determine the Z-axis coordinate. If the Z-value is greater than 17, the left motor is reversed, then the left and right motors are rotated backwards; if the Z value is less than 14, the right motor is turned forward, and then the left and right motors are Turn; otherwise the motor does not rotate.
The flow of the interrupt processing subroutine is shown in Figure 6.

Figure 6 interrupt processing subroutine flow

Design skills


1 sensor design skills


ET21X111 has the best spectral response to infrared light, but natural light contains a lot of infrared light, so strong natural light will affect the sensor data, resulting in a large deviation between the output coordinates and the actual coordinates. The solution is to add a filter, but this It can only play a role in attenuation, depending on the situation.


2 motor control circuit design skills


When designing the circuit that controls the motor's forward and reverse rotation, pay attention to the fact that the I/O state is uncertain when the MCU is powered on, so the program must set the two I/Os of Q3 and Q4 to HI at the beginning. (Q3 and Q4 are PNP tubes, if I/O is NPN, I/O is set to LOW) to prevent both I/Os from being LOW at power-on, causing Q3 and Q4 to turn on to form a short circuit. Another thing to note is that only one of Q3 and Q4 can be turned on at the same time.


3 MCU design skills


When the brush DC motor starts or rotates, a large power supply glitch is generated. This is very unfavorable for the operation of the MCU, so this LCÏ€ type filter circuit is added, as shown in FIG.

Figure 7 filter circuit


4 programming skills


During the operation of the smart car, it is necessary to read the coordinate data transmitted from the sensor while controlling the PWM output of the motor. The sensor will output the coordinate data every 12ms, so the best way is to use the interrupt to read the sensor data, and do the PWM output when there is no data output.

Material:Neodymium Magnet and Plastic

Size:D25x30mm

Weight:4.5g/pcs

Holding Force: A single "pin" can hold up to 60 pieces of A4 paper.

Color:Various colors are available,such as White,Purple,Red,Green,Yellow,Blue... andso on

Package:16pcsper bag,each bag could contains four different colors or one color

Or customized package

A single "pin"can hold up to 60 pieces of A4 paper.These are designedto replace traditional pushpin tacks. These magnetic push pins can hold photos,notes, flow charts, road maps and restaurant orders to a refrigerator, filecabinets, magnetic boards, drawers or other metalsurfaces.

Various colorsare available, such as white,purple, red and so on.

Rainbow Skittle Magnets

Black Rainbow Skittle Magnets, Coloured Rainbow Skittle Magnets, Neodymium Rainbow Skittle Magnets, High Power Rainbow Skittle Magnets

Ningbo Wewinmagnet Co.,Ltd , http://www.wewinmagnet.com