8051 Microcontroller & IR Sensor Based Object Detection and Collision Avoidance System
CHAPTER I: PROLOGUE
The main objective of this design is to implement a collision avoidance system based on 89C51 microcontroller and infrared (IR) sensors, as a major building block for the sake of completion of the autobot project. Before going into the depths of its constructional characteristics and functional details, few basic perceptions associated to the microcontroller, IR transmitter, IR receiver, timer IC and the theory of operation has to be revived for the sake of its profound understanding.
1.1 INFRARED BASICS
As illustrated in Figure 1.1, Infrared is an energy radiation with a frequency below our eyes sensitivity level, thus can’t be seen with naked eyes. Infrared waves can be easily generated and does not undergo electromagnetic interference, so it can be used abundantly for communication and control oriented operations. There are some potentially constraining sources of infrared emission also, such as sunlight (a major source of infrared), or any other heat radiating body in the vicinity that can cause severe interference to infrared energy levels. Despite of the presence of these restraining aspects Infrared wave finds hand full of applications in the field of electronics and can easily be opted as a far better means to implement the line of sight collision detection scheme over the existing alternatives.
Figure 1.1: Light Spectrum
1.2 OBJECT DETECTIONAND COLLISION AVOIDANCE
The principle of object detection is carried out by infrared waves radiated from IR light emitting diodes (LEDs) and monitoring the reflected light by means of IR sensors to detect the presence of any obstacle on the line of sight path. Thereafter, depending upon it, the microcontroller makes a befitting decision to avoid the collision. The concept of obstacle detection and collision avoidance is depicted in Figure 1.2.
Figure 1.2: Principle of Operation
Here the phrase ‘befitting decision’ means to make the robotic cart to take a turn towards the correct direction or to stall its motion and to take a ‘U-turn’ depending upon the obstacle’s dimensions and its location in the path.
CHAPTER II: PRIME CONSTITUENTS
The major constituents devised in this project are: AT89C51 microcontroller IC to control the rest of the blocks and to perform collision detection and avoidance, 555 timer IC for the sake of triggering the IR LEDs. TSAL 6200 IR LEDs, used as infrared emitter and TSAL 1738 IR sensor, used to receive the reflected IR waves.
2.1 IR LED
TSAL6200 by VISHAY Semiconductors is a high efficiency infrared emitting diode in Gallium Aluminum Arsenide (GaAlAs) on Gallium Arsenide (GaAs) technology, molded in clear, blue-grey tinted plastic packages. These IR LEDs provide high radiant at a low forward voltage. They emit IR waves of 760 nm wavelength.
Figure 2.1: TSAL6200 IR LED
2.2 IR SENSOR
TSOP1738 by VISHAY Semiconductors is an ambient light immune low power consumptive photo detector and pre amplifier embedded in the single epoxy package for IR wave reception and demodulation. The pinnacle of this IR sensor is that the demodulated output signal can directly be fed to the controller unit as it supports both TTL and CMOS logics reducing the requirement of additional hardware for decoding. This sensor can demodulate IR wave of frequency 38 kHz accurately. Pin 1 is GND, Pin 2 is Vs and Pin 3 is OUT.
Figure 2.2: TSOP1738 IR Sensor
2.3 TIMER IC
The 555 timer IC has become a mainstay in electronics design. The timer produces a pulse when a trigger signal is applied to it. The pulse length is determined by charging and discharging a capacitor connected to the timer. The 555 timer can operate in a monostable (one-shot) or astable (oscillatory) or time-delay mode. Here the astable mode of operation is opted for the project. The IC looks as given in Figure 2.3.
Figure 2.3: 555 Timer Pin Details
As output pin oscillates from high to low creating a series of output pulses, the duration for which output stays high is tHIGH=0.67.C.(R1+R2) and the duration for which it stays low is tLOW= 0.67.C.R2. Then the frequency for the series of pulses will be (Figure 2.4):
The IR sensor can detect IR signal of 38 kHz so components has to be rigged in such a way so that the frequency of the output signal (in turn the IR wave) will be 38 kHz only for the train of IR pulses get detected accurately.
Figure 2.4: Astable Mode Circuit
The Atmel 89C51 microcontroller is used for controlling the peripherals and the relevant program is written in assembly level language. Figure 2.5 shows the pin details of this dual inline package.
Figure 2.5: AT89C51 Pin Details
CHAPTER III: HARDWARE & THEORY
The discussion of hardware and the underlying theory is broadly classified into two major parts: transmitter section (IR LED and related triggering issues) and receiver section (IR sensor and microcontroller functionality). The transmitter section is more or less independent, because it is triggered using 555 timer IC and only thing to do with this is to tune its frequency to 38 kHz to be exact. And there onwards its job is to emit IR waves of that frequency.
Comparatively, the receiver section seems to be a little complicated because it has to do sack full of jobs and that too with sheer precision: like sensing the reflected IR wave and then forwarding it to the microcontroller. The microcontroller by means of duly coded program interprets the data and makes the decision on behalf of the robotic cart.
3.1 TRANSMITTER SECTION
The IR based emitter circuit is illustrated in Figure 3.1. Values of R1, R2 and C has to be such that frequency of the modulated infrared light wave equals 38 kHz (Formula mentioned in section 2.4 are used for the calculation). Despite of all the calculation, discrepancies may arise. To avoid that, the 10 KΩ POT has to be tuned to get the exact value on a CRO first then that resistance value can be used for the transmitter.
Figure 3.1: Transmitter Section
As we can see in Figure 3.1, there are three IR LEDs used here one is for any obstacle coming on the right side another two are for left sided and central object detection.
3.2 RECEIVER SECTION
The receiver circuit is depicted in Figure 3.2. Two TSOP1738 IR demodulator is used to monitor the three IR LEDs distinctly. Accordingly the sensor outputs are fed to the Port pins 3.4 and 3.5 (T0 and T1 respectively) of the microcontroller which are then used for decision making purpose and to control the movement of the robot’s wheels connected via unipolar stepper motors. Depending upon the sensed data, the microcontroller notifies the motor’s wheel controller through Port pins 1.0 and 1.1 in the form of an interrupt whether a turn has to be taken or not. In case of a turn, it notifies the motor controller about the turn’s direction by raising the respective Port 1 pin high. Accordingly the motor’s controller will adjust the stepper motor’s rotation to perform a turn in the correct direction to avoid the probable collision.
Figure 3.2: Receiver Section
CHAPTER IV: ALGORITHM & CODING
This chapter highlights the algorithm of sensing any obstacle coming on the way and making the cart’s wheel to take a turn for the sake of avoiding collision with that obstacle along with the assembly level code to implement the algorithm.
4.1 FLOW DIAGRAM
4.2 CALCULATION AND PRESUMES
We know that the operating frequency of TSOP1738 is 38 kHz. So, the time period for a single pulse will be its inverse: T=1/f =0.026315789 ms. Let there be 80 such pulses in a single burst, bringing the burst length to B =80 x T=2.105263158 ms. In the presence of an obstacle there will be pulses at the detector output, let the pulse detection threshold be 50 pulses per burst. So, 51 or more pulses in a single burst will invoke a turning action. Considering the fact that due to the presence of noise in the surroundings there will be around 30 pulses received by the detector for every burst. There will be an inter burst gap of 40 cycles. This concept holds good for a single IR sensor. To implement more than one sensors all we have to do is just to switch from one sensor to another after every burst (with an inter burst gap obviously) and this operation has to be performed continuously in a cyclic manner on every IR demodulator.
4.3 CIRCUIT DIAGRAM
The following circuit diagram comprises both the transmitter and receiver section along with the power supply module also.
4.4 ASSEMBLY LANGUAGE PROGRAM
The following code is written for the prototype in the standard assembly programming language for 8051 series of microcontrollers. This assembly coding conforms to the design stated above but due to dependency on other module such as the motor controller, the delay value required for that module to perform turning operation has to be calculated separately and should be fed to the DELAY entitled portion for its proper functionality.
MOV P1,#00H ; port 1 as output
//for left side obstacle checking//
RPT: MOV TMOD,#15H ; timer1= timer, timer0= counter
SETB P3.4 ; p3.4= input for counter 0
MOV TL0,#00H ; initialize counter
MOV TH0,#00H ;
MOV TL1,#6BH ; time delay for one burst
MOV TH1,#0F8H ;
SETB TR1 ; start timer 1
BACK1: JNB TF1,BACK1 ; check for timer 1 overflow
CLR TR1 ; stop timer 1
MOV A,TL0 ; take count value and do collision
CLR C ; check for left side obstacle
SUBB A,#1FH ;
JNB PSW.2,ROTRYT ;
CLR PSW.2 ;
ACALL DELAY1 ; inter burst delay
//for right side obstacle checking//
MOV TMOD,#51H ; timer0= timer, timer1= counter
SETB P3.5 ; p3.5= input for counter 1
MOV TL1,#00H ; initialize counter
MOV TH1,#00H ;
MOV TL0,#6BH ; time delay for one burst
MOV TH0,#0F8H ;
SETB TR0 ; start timer 0
BACK2: JNB TF0,BACK2 ; check for timer 0 overflow
CLR TF0 ;
CLR TR0 ; stop timer 0
MOV A,TL1 ; take count value and do collision
CLR C ; check for right side obstacle
SUBB A,#1FH ;
JNB PSW.2,ROTLFT ;
CLR PSW.2 ;
ACALL DELAY2 ; inter burst delay
SJMP RPT ; repeat the same
//delay for left side obstacle case//
DELAY1: MOV TMOD,#10H ; inter burst delay for left check
MOV TL1,#35H ; it is half of the burst length
MOV TH1,#0FCH ;
SETB TR1 ;
BACK3: JNB TF1,BACK3 ;
CLR TF1 ;
CLR TR1 ;
//delay for right side obstacle case//
DELAY2: MOV TMOD,#01H ; inter burst delay for right check
MOV TL0,#35H ; it is half of the burst length
MOV TH0,#0FCH ;
SETB TR0 ;
BACK4: JNB TF0,BACK4 ;
CLR TF0 ;
CLR TR0 ;
//right turn for left side obstacle//
ROTRYT: SETB P1.0 ; if obstacle on left
ACALL DELAY ; raise p1.0 high
CLR P1.0 ; to perform
RET ; right turn
//left turn for right side obstacle//
ROTLFT: SETB P1.1 ; if obstacle on left
ACALL DELAY ; raise p1.1 high
CLR P1.1 ; to perform
RET ; left turn
//delay for motor controller to do its job//
DELAY: MOV R1,#IMM_VAL1 ; let the motor controller
HERE1: MOV R2,#IMM_VAL2 ; module do its job
HERE2: DJNZ R2,HERE2 ; delay value is calculated
DJNZ R1,HERE1 ; on the basis of that code