Komli
Tuesday, March 10, 2009
Sensors to be used in Line follower
The first thing I would like to share is
Which Sensors to be used to detect black line??
I tried different circuits which even removes ambient light effect ( I will be posting the ckt oif it ) and IR sensors .Though I liked IR sensors the most , I was amazed to see the results when I used LDR sensors and White light . I used white light as my transmitter and LDR with a black tape covered as my reciever. The results were very good but the opnly problem was this is more sensitive to ambient light than IR sensors , but the change in ouput voltages were arnd 2 volts where as ir sensors always gave a change in output voltage of .89 .
If u want you can use LDR sensors with out a potmeter and opamp which I showed you in my ir sensor ckt.Give a try with ldr reciver ckt by replacing the transmitter and reciver with white led and LDR sensor
Sunday, June 29, 2008
Simple line follower using logic gates

This is a simple line follower using two sensors and without a microcontroller. We use here two types of logic gates and Lm 324 for the sensors. Two "OR" logic gates and one "Ex-OR" logic gates.The relay is used to run motors , can be replaced with motor driver L293D .
The ckt is self xplanatory , if u want to know the logic of its wrkng r have problem in understanding , wat its logic is , ask me and I will help you.
Wednesday, June 18, 2008
IR sensors From Scratch + Line follower

An infrared emitter is an LED made from gallium arsenide, which emits near-infrared energy at about 880nm.
The infrared phototransistor acts as a transistor with the base voltage determined by the amount of light hitting the transistor.
Hence it acts as a variable current source. Greater amount of IR light cause greater currents to flow through the collector-emitter leads.
As shown in the diagram below, the phototransistor is wired in a similar configuration to the voltage divider.
The variable current traveling through the resistor causes a voltage drop in the pull-up resistor.
This voltage is measured as the output of the device


IR reflectance sensors contain a matched infrared transmitter and infrared receiver pair.
These devices work by measuring the amount of light that is reflected into the receiver.
Because the receiver also responds to ambient light, the device works best when well shielded from abient light,
and when the distance between the sensor and the reflective surface is small(less than 5mm).
IR reflectance sensors are often used to detect white and black surfaces. White surfaces generally reflect well,
while black surfaces reflect poorly. One of such applications is the line follower of a robot.

Schematic Diagram for a Single Pair of Infrared Transmitter and Receiver


To get a good voltage swing , the value of R1 must be carefully chosen. If Rsensor = a when no light falls on it and Rsensor = b when light falls on it. The difference in the two potentials is:
Vcc * { a/(a+R1) - b/(b+R1) }
Relative voltage swing = Actual Voltage Swing / Vcc
= Vcc * { a/(a+R1) - b/(b+R1) } / Vcc
= a/(a+R1) - b/(b+R1)
The resistance of the sensor decreases when IR light falls on it. A good sensor will have near zero resistance
in presence of light and a very large resistance in absence of light. We have used this property of the sensor to form a potential divider. The potential at point ‘2’ is Rsensor / (Rsensor + R1). Again, a good sensor circuit should give maximum change in potential at point ‘2’ for no-light and bright-light conditions. This is especially important if you plan to use an ADC in place of the comparator
To get a good voltage swing , the value of R1 must be carefully chosen. If Rsensor = a when no light falls on it and Rsensor = b when light falls on it. The difference in the two potentials is:
Vcc * { a/(a+R1) - b/(b+R1) }
Relative voltage swing = Actual Voltage Swing / Vcc
= Vcc * { a/(a+R1) - b/(b+R1) } / Vcc
= a/(a+R1) - b/(b+R1)

If the emitter and detector (aka phototransistor) are not blocked, then the output on pin 2 of the 74LS14 will be high (apx. 5 Volts).
When they are blocked, then the output will be low (apx. 0 Volts). The 74LS14 is a Schmitt triggered hex inverter.
A Schmitt trigger is a signal conditioner. It ensures that above a threshold value, we will always get "clean" HIGH and LOW signals.
Not Blocked Case: Pin 2 High Current from Vcc flows through the detector. The current continues to flow through the base of Q2.
Current from Vcc also flows through R2, and Q2's Drain and Emitter to ground.
As a result of this current path, there will be no current flowing through Q1's base.
The signal at U1's pin 1 will be low, and so pin 2 will be high. Blocked Case: Pin 2 Low Current "stops" at the detector.
Q2's base is not turned on. The current is re-routed passing through R2 and into the base of Q1.
This allows current to flow from Q1's detector and exiting out Q1's emitter. Pin 1 is thus high and pin 2 will be low.
To detect a line to be followed, we are using two or more number of poto-reflectors.
Its output current that proportional to reflection rate of the floor is converted to voltage with a resister and tested it if the line is detected or not.
However the threshold voltage cannot be fixed to any level because optical current by ambent light is added to the output current.
Most photo-detecting modules are using modurated light to avoid interference by the ambient light.
The detected signal is filtered with a band pass filter and disused signals are filtered out.
Therefore only the modurated signal from the light emitter can be detected.
Of course the detector must not be saturated by ambient light, this is effective when the detector is working in linear region.


The line position is compeared to the center value to be tracked, the position error is processed with Proportional/Integral/Diffence filters
to generate steering command. The line folloing robot tracks the line in PID control that the most popular argolithm for servo control.
The proportional term is the commom process in the servo system. It is only a gain amplifire without time dependent process.
The differencial term is applied in order to improve the responce to disturbance, and it also compensate phase lag at the controled object.
The D term will be required in most case to stabilize tracking motion. The I term that boosts DC gain is applied in order to remove left offset error,
however, it often decrease servo stability due to its phase lag.
When any line sensing error has occured for a time due to getting out of line or end of line, the motors are stopped and
the microcontroller enters sleep state of zero power consumption.
Typical Examples of infrared Transmitter and Receiver installation

Saturday, May 17, 2008
A part of the Source Code for the Previous LFR
The 8 sensors are connected the port 0 .The numbers 160 n 255 are a constant
which u take this has been explained un my previous post so jst take a look.
while (1){
#ifdef debug
if(rep<255) prev="PINA;" i="0;i<8;i++)">>i)&0x01);
rep=0;
}
#endif
if(PINA!=255){
rotpow=255;
ldev=rdev=0;
if(PINA.3==0)
rdev=1;
if(PINA.2==0)
rdev=2;
if(PINA.1==0)
rdev=3;
if(PINA.0==0)
rdev=4;
if(PINA.4==0)
ldev=1;
if(PINA.5==0)
ldev=2;
if(PINA.6==0)
ldev=3;
if(PINA.7==0)
ldev=4;
if(rdev>ldev)
move(R,0,195+12*rdev);
if(rdev<160) rotpow="160;}">HMAX)
{move(CW,0,rotpow);}
else
{move(CCW,0,rotpow);}
}
};
}
void move (unsigned char dir,unsigned char delay,unsigned char power) {
PORTC=dir;
if(dir==L || dir==R) {
hcount=(hcount+1)%MAX;
history[hcount]=dir;
}
LSPEED=RSPEED=255;//power;
//delay_ms(delay);
}
This is taken from priyank patels LFR code .
Friday, May 16, 2008
AVR LINE FOLLOWER PD CONTROL
The robot uses IR sensors to sense the line, an array of 8 IR LEDs (Tx) and sensors (Rx), facing the ground has been used in this setup. The output of the sensors is an analog signal which depends on the amount of light reflected back, this analog signal is given to the comparator to produce 0s and 1s which are then fed to the µC.
Starting from the center, the sensors on the left are named L1, L2, L3, L4 and those on the right are named R1, R2, R3, R4.
The µC decides the next move so as to position the robot such that L1 and R1 both read 0 and the rest read 1.
Algorithm:
1. L= leftmost sensor which reads 0; R= rightmost sensor which reads 0.
If no sensor on Left (or Right) is 0 then L (or R) equals 0;

2. If all sensors read 1 go to step 3,
else,
If L>R Move Left
If L
If L=R Move Forward
Go to step 4
3. Move Clockwise if line was last seen on Right
Move Counter Clockwise if line was last seen on Left
Repeat step 3 till line is found.
For a good voltage swing from the potential divider use
The 8 sensors are connected to PORTA.
You need not connect anything to AVCC and AREF, it is required only if ADC is used.
The L298 Motor Driver has 4 inputs to control the motion of the motors and two enable inputs which are used for switching the motors on and off. To control the speed of the motors a PWM waveform with variable duty cycle is applied to the enable pins. Rapidly switching the voltage between Vs and GND gives an effective voltage between Vs and GND whose value depends on the duty cycle of PWM. 100% duty cycle corresponds to voltage equal to Vs, 50 % corresponds to 0.5Vs and so on. The 1N4004 diodes are used to prevent back EMF of the motors from disturbing the remaining circuit.
Thursday, May 15, 2008
line follower with software diff
PID CONTROL :
A proportional integral derivative controller (PID controller) is a common method of controlling robots. PID theory will help you design a better control equation for your robot.
Shown here is the basic closed-loop (a complete cycle) control diagram:
The point of a control system is to get your robot actuators (or anything really) to do what you want without . . . ummmm . . . going out of control. The sensor (usually an encoder on the actuator) will determine what is changing, the program you write defines what the final result should be, and the actuator actually makes the change. Another sensor could sense the environment, giving the robot a higher-level sense of where to go.
To get you started, here are a few terms you will need to know:
error - The error is the amount at which your device isnt doing something right. For example, if your robot is going 3mph but you want it to go 2mph, the error is 3mph-2mph = 1mph. Or suppose your robot is located at x=5 but you want it at x=7, then the error is 2. A control system cannot do anything if there is no error - think about it, if your robot is doing what you want, it wouldnt need control!
proportional (P) - The proportional term is typically the error. This is usually the distance you want the robot to travel, or perhaps a temperature you want something to be at.
derivative (D) - The derivative term is the change in error made over a set time period (t). This is usually the velocity of your robot. So if your robot was at x=5 about one t ago, and is at x=7 now, then the derivative term is 7 - 5 = 2/t. If you are using a microcontroller, you can calculate the time with this timer tutorial.
integral (I) - The integral term is the rate of change in the error made over a set period of time (t). This is usually the acceleration of your robot. If your derivative term was 2/t a second ago, and it is 2/t now, your integral term is 2 - 2 = 0/t^2. Thats an acceleration error of zero . . .
One example of only P control can be seen here: taken from amol deshmukhs site ,
This is a small line following robot designed to follow a white line drawn on a black surface. The software can be changed to interchange the colours. The software still has lot's of room for improvement but works well. It constantly corrects wrong moves using feedback mechanism which forms a closed loop control system.
mechanical design It has two DC motors in wheelchair design. Direction of the robot is controlled by controlling speeds of the two motors. Lets say the speeds are
Right wheel : SpeedR
Left wheel : SpeedL
To control the speed of the motor controlled power is fed by PWM ( Pulse Width Modulation ) technique.
electronic design Processor AVR ATmega16 [ the ADC feature comes in handy to read output of sensors ]
Motor driver : L293D ( 2 )
Sensors : IR LED-photodiode pair ( 2 )( non-modulated )
Power supply : Li-Ion cells ( 2 ) 1700mAHr giving 8V regulated with voltage regulator.
control algorithm and software
Lets say the two sensor outputs, i.e. the intensity of reflected light sensed at the two sensor positions is
Sensor Left : SensL
Sensor Right : SensR
If Err is the error of sensors from mean position then it will be proportional to the difference between the two sensor readings
Err = K * ( SensR - SensL )
Where K is constant of proportionality
If Err is a +ve quantity then we must drive Left motor a bit faster than the right i.e. the speed of right motor must be increased a bit and speed of motor right be decreased a bit
SpeedL = CntrSpeed + Kp * Err
SpeedR = CntrSpeed - Kp * Err
This is called Proportional Control
Check for my next post on 8 sensors using PD control wth algo.
The above one is only P control n taken from this site
http://www.me.iitb.ac.in/~adeshmukh/linefollower.php
Friday, April 11, 2008
LINE FOLLOWER
firstly the motor driver , then op amp , sensors, which i have told in my last posts n the the most important part either using logic gates r else using micro controllers tats programming it .
I will be tellng u both the ways of doing it tats using logic gates and also using muc(i will be gvng only the logic part ).
This is how it basically luks like
I will xplain making of a line follower using one sensor till an array of sensor(ie 7 sensors).
BASIC PRINCIPLE:
White colour reflects light and black colour absorbs .
So when the sensor is on the white line the output will be high and when on black it will be low.
WE ASSUME WE ARE FOLLOWING A BLACK LINE ON WHITE BACK GROUND.
LFR USING A SINGLE SENSOR
Lets assume tat sensor is placed on center ie the sensor correctly places above the line , then there is no way tat it can follow a line bcoz it cant diff btw curves tilted towards left n right.
so wat we do is place the bot in such a way tat when the sensor cums to the right side of the line .
conditions:
1)when the sensor is not on the main line move fwd.
2)when the line is turning towards left the sensor detects the line so now take a left turn
3)when the line is turning towards rite u r sensor cant detect the line and it keeps moving forward as it satisfies condition number 1
RESULT:We cant use this thing.
LFR USING TWO SENSORS:
We place our sensor on either side of the line .
conditions:
When the line is straight and the two sensors are on either side of the line, move forward
when there is a right bend in the line the right sensor detects it ,now as ur bot shuld take turn, the rite motor shld stop and the left motor shuld move.
when there is a left bend in the line the left sensor detects it ,now as ur bot shuld take left turn, the left motor shld stop and the rite motor shuld move.
The pic shows the left curves and the right curves, the blue ones are u r sensors, the left pic shows the left sensor about to detect the line and the rite pic shows the right sensor about to detect the line.For the ckt directly connect the output of sensors to the the inputs of l293d n tat s it but use 30 rpm motors for it hope u got it .
But the problem with this is it will always move in zig zag manner so wastage of time.
I will give the ckt diagram of this after i explain about Logic gates .
And remember this is only with two sensors , i will explain till we can use 7 sensors so keep checking.