Design of intelligent toy car based on optical sensor

Publisher:丝语轻风Latest update time:2010-12-14 Source: 21icKeywords:EM78P156  ETOMS-ET21X111  MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Intelligent robots are increasingly used in today's society. From ordinary toy robots to industrial control robots, from robots that can cook to robots that can conduct space exploration, it is foreseeable that the application of intelligent robots will be more extensive in the future. Everyone is familiar with ordinary wireless remote control cars, and everyone thinks Nintendo's video game WII is amazing. The familiar ones are not fun, and the amazing ones are unaffordable. This may be a common problem encountered by many people. This design starts from a new perspective of thinking and makes a smart car that can be played in daily life to share with readers who share the same hobby.

Overall system design

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

System overall framework

Figure 1 System overall framework

The overall function of this design can be simply summarized as: allowing the car to follow people (or objects). Separately, the following three small functions need to be realized: the sensor can correctly read X,

The Y and Z coordinate values ​​are the first condition. The MCU can correctly judge the size changes of the X and Z coordinate values, which is the key. Some people may wonder why the Y coordinate change is not judged? That is because the car cannot jump up and down (up and down are the Y axis). The MCU controls the motor direction and the motor PWM time according to the size changes of the coordinate values, which is the result.

Hardware system design

1 Sensor peripheral circuit design

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

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

The detailed interface circuit around the sensor is shown in Figure 2. From Figure 2, we can see that EO4~EO7 are high. This is the exposure setting that is pulled high by hardware. 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 4 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, and it can work normally after power-on automatic reset.

Sensor interface circuit

Figure 2 Sensor interface circuit [page]

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 motor PWM, and R and R+ control the right motor PWM. RS232 receives the sensor coordinate data input. The IC works at 3.3V voltage and automatically resets after power-on. The system clock uses a 4MHz external crystal oscillator.

MCU interface circuit

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 use PNP tubes, and L and L+ cannot be LOW at the same time to avoid short circuit.

Left motor control circuit

Figure 4 Left motor control circuit [page]

Software system design

After the system is powered on, it is first initialized, the registers of EMC78P156 are set, the interrupt flag register is enabled, and the interrupt is waited. Figure 5 is the main program flow chart.

Main program flow chart

Figure 5 Main program flow chart

When an interrupt occurs, the interrupt handling subroutine is entered. First, the interrupt flag must be turned off and the scene must be protected. Then the XYZ coordinate values ​​are read and analyzed, which can be divided into the following situations.

(1) Determine the change in the X-axis. If the X value is greater than 14 and less than or equal to 17, the motor does not rotate left or right. Then determine the change in the Z-axis coordinate value. If the Z value is also greater than 14 and less than or equal to 17, the motor does not rotate forward or backward.

(2) If the X-axis coordinate value is greater than 17, determine the Z-axis coordinate. If the Z value is greater than 17, reverse the right motor and then turn the left and right motors backward. If the Z value is less than 14, rotate the left motor forward and then turn the left and right motors forward. Otherwise, the motors do 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, reverse the left motor, and then the left and right motors rotate backward; if the Z value is less than 14, rotate the right motor forward, and then the left and right motors rotate forward; otherwise, the motors do not rotate. The flow of the interrupt handling subroutine is shown in Figure 6.

Interrupt handling subroutine flow

Figure 6 Interrupt handling subroutine flow[page]

Design Tips

1 Sensor design tips

ET21X111 has the best spectral response to infrared rays, but natural light contains a large amount of infrared rays, so strong natural light will affect the sensor data, causing a large deviation between the output coordinates and the actual coordinates. The solution is to add a filter, but this can only have an attenuation effect. The specific application depends on the situation.

2 Motor Control Circuit Design Techniques

When designing a circuit to control the forward and reverse rotation of a motor, please note that: when the MCU is powered on, the state of the I/O is uncertain, so at the beginning of the program, the two I/Os of Q3 and Q4 must be set to HI (Q3 and Q4 are PNP tubes, if they are NPN tubes, the I/O is set to LOW) to prevent both I/Os from being LOW when powered on, causing Q3 and Q4 to be turned on and form a short circuit. In addition, it should be noted that only one of Q3 and Q4 can be turned on at the same time.

3 MCU Design Tips

When the brushless DC motor starts or rotates, it will generate large power burrs, which is very detrimental to the operation of the MCU, so this LC π-type filter circuit is added, as shown in Figure 7.

Filter circuit

Figure 7 Filter circuit

4 Programming skills

When the smart car is running, it needs to read the coordinate data from the sensor while controlling the PWM output of the motor. The sensor will output coordinate data every 12ms, so the best way is to use interrupts to read the sensor data and perform PWM output when there is no data output.

Keywords:EM78P156  ETOMS-ET21X111  MCU Reference address:Design of intelligent toy car based on optical sensor

Previous article:Photoelectric Roll Angle Measuring Instrument Based on FPGA/MCU
Next article:Design of a power supply for automobile solenoid valve quality test

Recommended ReadingLatest update time:2024-11-16 21:29

Very stable and reliable MCU key debounce program
//Very stable and reliable MCU button debouncing program, there will be no jitter #include reg52.h #define uint unsigned int #define uchar unsigned char sbit K1 = P1^4; sbit K2 = P1^5; void delay1ms(uint n)   {     uchar a,b,c,d; for(d=n;d 0;d--)     for(c=1;c 0;c--)         for(b=222;b 0;b--)           
[Microcontroller]
Very stable and reliable MCU key debounce program
c8051f330 series microcontroller AD conversion
c8051f330 series microcontroller AD conversion. Author lml198694 Date 2008-7-21 10:53:00 2 recommend According to the C8051F330 microcontroller that I have recently learned, I wrote a program about AD conversion. However, when debugging, I always found that its accuracy is not as high as I imagined. I don’
[Microcontroller]
51 single chip microcomputer-LED module-flowing water lamp
#include reg52.h #include intrins.h #define uchar unsigned char #define uint unsigned int #define long unsigned long sbit LED1 = P1^0; void Delay600ms(); //@11.0592MHz void main(void) { bit flag = 0; unsigned char cnt; LED1 = 0; while(1) { if(0==flag) { for(cnt=1;cnt 8;cnt++) { Delay600ms(); P1 =
[Microcontroller]
A brief introduction to designing timers using microcontrollers
  1. Experimental tasks   Use the timer/counter T0 of the AT89S51 microcontroller to generate a one-second timing time as the second counting time. When one second is generated, the second count is increased by 1. When the second count reaches 60, it automatically starts from 0. Now I will start to introduce how to ma
[Microcontroller]
A brief introduction to designing timers using microcontrollers
What functional components does the hardware of the microcontroller system mainly consist of?
Answer: The hardware of the single-chip microcomputer system consists of the single-chip microcomputer chip and external devices. The single-chip microcomputer chip contains a microprocessor (CPU), memory (ROM, RAM, etc. for storing program instructions or data), input/output ports (I/O ports) and other functional co
[Microcontroller]
Single chip one-button multi-function key recognition technology
In some single-chip microcomputer systems, it is sometimes necessary to use some one-key multi-function technologies. Let me introduce them to you here. Switch SP1 is connected to the P3.7/RD pin. Four light-emitting diodes are connected to the P1 port of the AT89S51 single-chip microcomputer. When powered on, the l
[Microcontroller]
Design of hip force tester based on SPCE061A single chip microcomputer
  Abstract: This paper introduces the system structure and some software writing process of the hip force tester based on SPCE061A single-chip microcomputer, focusing on the force measurement method of the tester and the principle of using photoelectric encoder for speed measurement and phase discrimination. The teste
[Test Measurement]
Design of hip force tester based on SPCE061A single chip microcomputer
Design of automatic quantitative water temperature controller based on single chip microcomputer technology
  1. Overall design and demonstration of the scheme   1.1 Selection of liquid level sensor   The self-made sensor is made by using the conductive properties of metal conductors and water. It can collect data at any position without blind spots, and is very conducive to the expansion of the device. And the cost is
[Microcontroller]
Design of automatic quantitative water temperature controller based on single chip microcomputer technology
Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号