How to make a Line Following Robot using Arduino and Motor Shield


A) Hardware Required : ( All in one package) http://amzn.to/2m4P9W5 (Rs.1100/- only) without Arduino

- Arduino Board : http://amzn.to/2mlLbKP
- Motor Shield L293D : http://amzn.to/2mX5mvM 
- IR Sensor x2 : http://amzn.to/2mlJNYQ
- DC Motor and wheel x2 : http://amzn.to/2lJeynf
- Bovine Wheel 
- Chassis plate : http://amzn.to/2mlMee1
- Battery 9V
- Battery Buckle 
- Wires
- Button

----------

B) Create of the Chassis:

1) The DC motors attach to the chassis
2) The Arduino attach to the chassis
3) The Motor Shield attach to the Arduino.

About the Motor Shield:
- The motor controllers on this shield are designed to run from 4.5V to 25V.
- There are two places you can get your motor 'high voltage supply' from. One is the DC jack on the Arduino board and the other is the 2-terminal block on the shield that is labeled EXT_PWR.
- To connect a motor, simply solder two wires to the terminals and then connect them to either the M1, M2, M3, or M4.

4) The QTR-8RC Reflectance Sensor attach to the chassis.

----------

C) Connections : 

1) DC Motors connect to the Motor Shield

2) Left Motors connect to M3

3) Right Motors connect to M4

4) The IR Sensor Connections with Analog A0 and A1 pin in Arduino and also +5V and G

5) Battery and on / off button connection

- The (+) from the battery is connect to a leg of the button
- Connect a cable to the other legs of the button. This cable is for Motor Shield (+)

6) Attach wheels

----------

1) Open the new Arduino IDE page and Delete everything on the page

2) Get the code from the given link and paste in the Arduino IDE page

3) First Install the Arduino Libraries

3.1) Install the AF_Motor Arduino library

4) After installing the library, restart the Arduino IDE

5) Now you can see the libraries you have installed

6) When you verify, you will not see any errors

Get the Arduino Code - https://goo.gl/P96Ek4


Circuit Diagram:



----- Arduino Code -----

                     Click Here to Download Arduino Code




SHARE

About the Author: Roni Mondal

About Roni Mondal : Beyond blogging and digital marketing , Roni Mondal is an entrepreneur at heart who has made his hobby turned passion. Becoming a blogger, It was the most important part of his journey.
    Blogger Comment
    Facebook Comment

12 comments:

  1. Nice ..Thankx For sharing .

    ReplyDelete
  2. I have made a line following robot I have insert left motor to m3 and right for m4.i have inserted ir sensor to +5v for both and Gnd for both .as u I have given in the Blog pictures. But the robot isn't working I tried uploading ur code but still .What should I do.

    ReplyDelete
    Replies
    1. //CAMELLIA INSTITUTE OF TECHNOLOGY
      //SCIENCE EXHIBITION 2K17
      //(RONI,MONDIRA,AJIT)
      // declaring Shield
      int dataPin = 8;
      int latchPin = 12;
      int clockPin = 4;
      int en = 7;
      // declaring Sensor Pins.
      int LeftSensor = A0;
      int RightSensor = A1;
      int L_sensor_val = 0; // To store value from sensors.
      int R_sensor_val = 0;

      int threshold = 300; // Threshold value to distinguish black and white.

      void setup()
      { // setting up shield.
      pinMode(dataPin, OUTPUT);
      pinMode(latchPin, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(en, OUTPUT);
      digitalWrite(en, LOW);

      }

      void loop()
      {
      L_sensor_val = analogRead(LeftSensor); // Reading Left sensor data
      R_sensor_val = analogRead(RightSensor); // Reading Right sensor data


      if(R_sensor_val>threshold && L_sensor_valthreshold && L_sensor_valthreshold && R_sensor_valthreshold && R_sensor_val<threshold){
      turn_left();
      L_sensor_val = analogRead(LeftSensor);
      R_sensor_val = analogRead(RightSensor);
      }
      }

      else if(L_sensor_val<threshold && R_sensor_val<threshold){ // tesing for halt
      while (L_sensor_val<threshold && R_sensor_val<threshold){
      halt();
      L_sensor_val = analogRead(LeftSensor);
      R_sensor_val = analogRead(RightSensor);
      }
      }

      forward(); // Default movement is forward.
      }

      void forward(void){ // function for forward movement.
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 3);
      digitalWrite(latchPin, HIGH);

      }

      void turn_left(void){ // function for left turn.
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 161);
      digitalWrite(latchPin, HIGH);
      }

      void turn_right(void){ // function for Right turn.
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 38);
      digitalWrite(latchPin, HIGH);
      }

      void halt(void){ // function for stopping robot.
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 32);
      digitalWrite(latchPin, HIGH);
      }

      Delete
    2. Check your IR Pin connections...

      Delete
  3. i had bought this kit with lot of expectations but i found nothing i.e no coding or some tutorials are present but i am thankful that you gave the circuit diagrams and all other things but its so messy
    i feel you should buy any other line following machine

    ReplyDelete
  4. Hai, im using the same configuration and coding as yours but my robot doesnt work where my sensor need to be lift up to move, if theres any item block the sensor and it will stop. Can u help me \?

    ReplyDelete
  5. i want to increase the speeed of the bot can u help me plz i hav used 1000rpm geared dc otor but it didnt work

    ReplyDelete
  6. how if I add more ir sensor (become 4 ir sensor)?

    ReplyDelete