Line Follower Robot
This Robot is programmed to follow a black line on a white background. The path is made with black electrical tape or black paint on a white surface. LFR constantly correcting wrong moves using feedback mechanism forms a simple yet effective closed loop system using IR Sensor pair.. As a programmer you get an opportunity to ‘teach’ the robot how to follow the line thus giving it a human-like property of responding to stimuli.
Hardware -
In the circuit two IR sensors, one LCD display and two DC geared motors are connected to the ATMega16. The robot uses IR sensors to sense the line an array of 2 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. By comparing this analog signal microcontroller decides the next move according to the algorithm.
#include "avr io.h" #include "util delay.h" #include "lcd_lib.h" #include"stdio .h" #include"adc_lib .h" int main() { char A[20]= " "; int s1,s2; DDRD=255; ADCinit(); LCDinit(); LCDclr(); while(1) { s1=read_adc(0); s2=read_adc(2); 'Give conditions here to drive Motors using ' if() condition. sprintf(A, "s1=%d s2=%d ", s1,s2); LCDGotoXY(0,0); LCDstring(A,14); } }
IR Sensor
A sensor is a device that produces a measurable response to a change in a physical condition, such as temperature or thermal conductivity, or to a change in chemical concentration. A sensor when coupled with an electronic circuit converts the physical change into a signal which can be read by an observer or by an instrument. The most common use of sensors is to get feedback from external environment.
IR sensor Pair:
- Transmitter = LED (Light Emitting Diode)
It is similar to normal LEDs but emit infra-red light its glow can be seen with a digital camera or mobile phone camera.
- Receiver = Photodiode/IR Transistor.
- A photodiode is a diode that conducts only when light falls on it.
Interfacing IR sensor with ATmega
ADC (Analog to Digital Convertor) An ADC converts an input voltage into a number. An ADC has an resolution. A 10 bit ADC has a range of 0-1023. The ADC has also reference voltage Aref. When the input voltage is GND the output is 0. When the input voltage is equal to Aref the output is 1023. So the input range is 0-Aref and digital output is 0-1023.
Code:
#include "avr/io.h" #include “lcd_lib.h” #include "util/delay.h" #include “adc_lib.h” #include "stdio.h" void main ( ) { int x; char a[15]; LCDinit(); LCDclr( ); ADCinit(10); while (1) { x = read_adc(0); sprintf(a, "Value = %d ",x); LCDclr (); LCDstring (a, 10); _delay_ms (300); } }
LED Interfacing
LED interfacing is the primary application of any microcontroller. We can interface LED to any pin of four ports name PORTA,B,C,D of microcontroller then it shows the results according to program which we provide.
Sample Code :
#include "avr/io.h" #include "util/delay.h" int main(void) { DDRB=255; DDRC=255; DDRD=255; while (1) { PORTB=1; _delay_ms(100); PORTB=2; _delay_ms(100); PORTB=4; _delay_ms(100); PORTB=8; _delay_ms(100); PORTB=16; _delay_ms(100); PORTB=32; _delay_ms(100); PORTB=64; _delay_ms(100); PORTB=128; _delay_ms(100); PORTC=1; _delay_ms(100); PORTC=2; _delay_ms(100); PORTC=4; _delay_ms(100); PORTC=8; _delay_ms(100); PORTC=16; _delay_ms(100); PORTC=32; _delay_ms(100); PORTC=64; _delay_ms(100); PORTC=128; _delay_ms(100); PORTD=1; _delay_ms(100); PORTD=2; _delay_ms(100); PORTD=4; _delay_ms(100); PORTD=8; _delay_ms(100); PORTD=16; _delay_ms(100); PORTD=32; _delay_ms(100); PORTD=64; _delay_ms(100); PORTD=128; _delay_ms(100); } }