ATmega8 Line Follower Robot (LFR) Project

Now that the mechanical assembly part is over,and we have completed the construction of left and right (L&R) infrared sensor cards. Since the MCU (ATmega8) cannot drive the dc motors directly, a dedicated motor driver circuit is used. The motor driver circuit here is based on a simple 16-pin IC (L293D) which can drive two dc motors independently.

LFR-Motor Driver Circuit Diagram
LFR-Motor Driver Circuit Diagram
As can be seen in the circuit diagram, pins 4, 5, 13 and 12 of LM293 (U2) are connected to GND and the pin 16 (VSS) is connected to 5V. The ‘chip inhibit’ pins (1&9) act as the enable pins for the input-output pairs on left side and right side of the motor driver, respectively. Pin 8 (VC) receives the unregulated input supply (Vcc) from the LFR power supply circuit. It is noteworthy that this motor driver chip is PWM supporting, means that if you apply some voltage in the range 0V to 5V at any input, then it will be scaled up by a factor and will be available at the corresponding output.
The four input pins (2-7-10-15) receives motor drive instructions from the MCU. In short, U2 acts as the interface between the microcontroller (U3) and the dc motors (M1&M2) in which instructions from the microcontroller go into its input pins and the outputs are used to drive the robot motors.
LFR-Microcontroller Unit (MCU) Circuit Diagram
Here is the circuit of the MCU,wired around our favorite ATmega8 chip (U3). The first task is to resolve which pins of the MCU will be used for taking inputs from the infrared sensor cards and giving outputs to the motor driver circuit. As an exercise, I went for PC0 (left) and PC3 (right) of PORT C for the two inputs from two infrared sensor cards, and pins PB1 to PB4 of PORT B as outputs to motor driver circuit (actually only PB1 and PB4 are important at this time). The code is written using the C language so you need to be comfortable with the syntax of C language, concept of libraries, compiler, etc (IDE used is the AVR Studio 4). The final code (hex code) can be burned into the MCU using a suitable programmer (refer previous chapters of this avr tutorial).
P24-2
LFR-Power Supply Circuit Diagram
Usually LFR is powered by a battery supply voltage of 9 to 12V while most of the circuitry requires only 5V. You can use 6 to 8 AA cells (or a 9V 6F22 battery-not good for long run) as the power bank of the LFR. The fixed-voltage regulator LM7805 (U4) is used in the power supply circuit to convert the higher input supply (Vcc) voltage to a lower value (+5V) to make the MCU happy. LM7805 works even without the buffer capacitors but it is better if capacitors are used as they will stamp down the voltage fluctuations. Adding one 10nF ceramic capacitor across each dc motor terminal ( +/_ ) is another good practice to suppress unwanted noise generated by the motor.
P24-3
Sample Code

  1. #include <avr/io.h>
  1. int main(void)
  1. {
  1. DDRB=0b11111111 //PORTB as output port connected to motors;
  1. DDRC=0b0000000 //PORTC Input port connected to sensors;
  1. int left_sensor=0, right_sensor=0 ;
  1. while(1)
  1. {
  1. left_sensor=PINC&0b00000001;
  1. right_sensor=PINC&0b00001000 ;
  1. if((left_sensor==0b0000000) & (right_sensor==0b0000000)) //if both sensors "off"
  1. {
  1. PORTB=0b00000000 // stop;
  1. }
  1. if((left_sensor==0b00000001) & (right_sensor==0b00001000)) //if both sensors "on"
  1. {
  1. PORTB=0b00010010 // move forward;
  1. }
  1. if((left_sensor==0b0000000)&(right_sensor==0b0001000))
  1. {
  1. PORTB=0b00000010 // turn left;
  1. }
  1. if((left_sensor==0b00000001)&(right_sensor==0b0000000))
  1. {
  1. PORTB=0b00010000 // turn right;
  1. }
  1. }
  1. }
Now it is your turn. As a learner, you are requested to tweak the above code as per your requirement. Next, create the hex file from the code as explained earlier in the programming tutorial and burn the code into atmega 8. Finally, put the batteries in and place your finished LFR in the track (with the line printed on it using black colour). Place the LFR over the line, and switch on the LFR to see the action!


THANK YOU FOR VISITING..!!
PLEASE COMMENT

No comments:

Post a Comment