Ali SoomarRohan BalajiArjun Singh
Published

Line Follower Robot

Cool robot that can follow a black line and stop before objects!

BeginnerShowcase (no instructions)4 hours3,847
Line Follower Robot

Things used in this project

Hardware components

MSP-EXP430F5529LP MSP430 LaunchPad
Texas Instruments MSP-EXP430F5529LP MSP430 LaunchPad
×1
Photo resistor
Photo resistor
×2
Proximity Sensor
Proximity Sensor
×1
Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
DC motor (generic)
×2
LED (generic)
LED (generic)
Optional
×2
Resistor 10k ohm
Resistor 10k ohm
×2
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
4xAA battery holder
4xAA battery holder
×1
AA Batteries
AA Batteries
×1

Software apps and online services

Code Composer Studio
Texas Instruments Code Composer Studio
Energia
Texas Instruments Energia
Alternative

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

Main Program

C/C++
Use Code Composer Studio, Code Composer Studio Cloud, or Energia
void setup() {
  // put your setup code here, to run once:
  analogReadResolution(12);
  Serial.begin(9600);

  pinMode(29, OUTPUT); //MOTOR 1
  pinMode(30, OUTPUT);

  pinMode(32, OUTPUT); //MOTOR 2
  pinMode(31, OUTPUT); 
}

void loop() {
  // put your main code here, to run repeatedly: 
  int photo1 = analogRead(23);//photoresistor1 is connected to analog pin 23
  int photo2 = analogRead(24);//photoresistor2 is connected to analog pin 24
  int ir = analogRead(25);//IR sensor is connected to analog pin 25
  Serial.print(photo1);
  Serial.print("      ");
  Serial.print(photo2);
  Serial.print("     ");
  Serial.println(ir);
  
  //***THRESHOLD VALUES MAY NOT BE THE SAME FOR YOU***
  //Use the displayed values on the serial port to find out
  //what threshold values should be used for you

  //The following case occurs when both photoresistors(LDRs)
  //detect white
  if (photo1 > 2900 && photo2 > 2200 && ir < 2000)
  {
   digitalWrite(29, HIGH);//HIGH for forward
   digitalWrite(30, LOW); //LEFT MOTOR GOES FORWARD

   digitalWrite(32, HIGH);//HIGH for forward
   digitalWrite(31, LOW); //RIGHT MOTOR GOES FORWARD
    
  }
  
  /*The following case occurs if the right LDR detects black 
   * and the left LDR detects white
   */
   else if (photo1 < 2900 && photo2 > 2200 && ir < 2000)
  {

   digitalWrite(29, HIGH);
   digitalWrite(30, LOW); //LEFT MOTOR GOES FORWARD

   digitalWrite(32, LOW);
   digitalWrite(31, HIGH); //RIGHT MOTOR GOES BACKWARDS
  }
  
   /*The following case occurs if the left LDR detects black 
    * and the right LDR detects white
    */
    else if (photo1 > 2900 && photo2 < 2200 && ir < 2000)
  {

   digitalWrite(29, LOW);
   digitalWrite(30, HIGH); //LEFT MOTOR GOES BACKWARDS

   digitalWrite(32, HIGH);
   digitalWrite(31, LOW); //RIGHT MOTOR GOES FORWARD
  }

  /*The following case occurs if the robot reaches a 90 degree
   *turn. In this case, it will turn left because the specific
   *setup of lines I had for my assignment had 90 degree turns
   *go left and not right. If you want to have a variation of
   *turning left and right for 90 dgree turns, an additional
   *photoresistor(LDR) is needed between the two, and if the 
   *middle LDR and left LDR detects black, it should turn left.
   *Similarly, if the middle LDR and right LDR detects black, it
   *should turn right.
   */
  else if (photo1 < 2900 && photo2 < 2200 && ir < 2000)
  {

   digitalWrite(29, LOW);
   digitalWrite(30, HIGH); //LEFT MOTOR GOES BACKWARDS

   digitalWrite(32, HIGH);
   digitalWrite(31, LOW); //RIGHT MOTOR GOES FORWARD
  }
 
   //The following case occurs if the an object is close
  else if (ir > 2000)
  {
   digitalWrite(29, LOW);
   digitalWrite(30, LOW); //LEFT MOTOR STOPS

   digitalWrite(32, LOW);
   digitalWrite(31, LOW); //RIGHT MOTOR STOPS
  }
  delay(50);
}

Credits

Ali Soomar

Ali Soomar

11 projects • 41 followers
Student at the University of Texas at Austin
Rohan Balaji

Rohan Balaji

0 projects • 5 followers
Student at The University of Texas at Austin
Arjun Singh

Arjun Singh

1 project • 2 followers

Comments