Things used in this project

Hardware components:
Msp exp430f5529lp 5529 lp angle%5b1%5d
TI LaunchPad MSP-EXP430F5529LP MSP430 LaunchPad
×1
Adafruit industries ada161 image 75px
Photo resistor
×2
Sharp microelectronics gp2y0a41sk0f image
Proximity Sensor
×1
Texas instruments l293dne image
Texas Instruments Dual H-Bridge motor drivers L293D
×1
DC motor (generic)
×2
09590 01
LED (generic)
Optional
×2
Mfr 25frf52 10k sml
Resistor 10k ohm
×2
12002 04
Breadboard (generic)
×1
11026 02
Jumper wires (generic)
×1
Adafruit industries ada830 image 75px
4xAA battery holder
×1
61vhxtmzbyl
AA Batteries
×1
Software apps and online services:
Ccscube256
Texas Instruments Code Composer Studio
Energiabadgelogo2
TI LaunchPad Energia
Alternative
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Code

Main ProgramC/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

Mjoyqfasn0zslpeg4vrc
Ali Soomar
11 projects • 28 followers
Student at the University of Texas at Austin
Contact
Okefyxxiqf9txr4wd3hw
Rohan Balaji
0 projects • 3 followers
Student at The University of Texas at Austin
Contact
E4326e842e3e089ff0ce4ad77049071e
Arjun Singh
1 project • 1 follower
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login