Monday 28 January 2013

Line Following Buggy Sensor Prototype

UoM Buggy Prototype 28Jan2013 (4)
As a second year student at the University of Manchester my team and I had to create a line following buggy. To demonstrate to the lecturers the basics of detecting the line and applying the correct duty cycle for the PWM I made a simple sensor prototype.



To create this prototype I made use of the following items.


  • Arduino Uno R3
  • Regular LED’s
  • Some Resistors (values I have used are shown below)
  • Wires TCRT500 Optical Sensor Package



  • I designed the circuit diagram shown below.

    UoM Buggy Prototype 28Jan2013 (7)


    UoM Buggy Prototype 28Jan2013 (2)
    Next the Arduino Uno was programmed with the following code.

    int r1 = 2;
    int r2 = 3;
    int r3 = 4;
    int r4 = 5;
    int l1 = 8;
    int l2 = 9;
    int l3 = 10;
    int l4 = 11;
    void setup() {
    Serial.begin(9600);
    pinMode(r1, OUTPUT);
    pinMode(r2, OUTPUT);
    pinMode(r3, OUTPUT);
    pinMode(r4, OUTPUT);
    pinMode(l1, OUTPUT);
    pinMode(l2, OUTPUT);
    pinMode(l3, OUTPUT);
    pinMode(l4, OUTPUT);
    }
    void loop() {
    int sensorValue = analogRead(A0);
    float voltage = sensorValue * (5.0 / 1023.0);
    int sensorValue2 = analogRead(A1);
    float voltage2 = sensorValue2 * (5.0 / 1023.0);
    float difference = (voltage2 - voltage);
    if (difference > 3.9){
    digitalWrite(l1, HIGH);
    digitalWrite(l2, HIGH);
    digitalWrite(l3, HIGH);
    digitalWrite(l4, HIGH);
    digitalWrite(r1, LOW);
    digitalWrite(r2, LOW);
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);
    }
    else if (difference > 2.8){
    digitalWrite(l1, HIGH);
    digitalWrite(l2, HIGH);
    digitalWrite(l3, HIGH);
    digitalWrite(l4, LOW);
    digitalWrite(r1, LOW);
    digitalWrite(r2, LOW);
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);
    }
    else if (difference > 1.6){
    digitalWrite(l1, HIGH);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    digitalWrite(r1, LOW);
    digitalWrite(r2, LOW);
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);
    }
    else if (difference > 0.5){
    digitalWrite(l1, HIGH);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    digitalWrite(r1, LOW);
    digitalWrite(r2, LOW);
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);
    }
    else if (difference > -0.5){
    digitalWrite(r1, LOW);
    digitalWrite(r2, LOW);
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    }
    else if (difference > -1.6){
    digitalWrite(r1, HIGH);
    digitalWrite(r2, LOW);
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    }
    else if (difference > -2.8){
    digitalWrite(r1, HIGH);
    digitalWrite(r2, HIGH);
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    }
    else if (difference > -3.9){
    digitalWrite(r1, HIGH);
    digitalWrite(r2, HIGH);
    digitalWrite(r3, HIGH);
    digitalWrite(r4, LOW);
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    }
    else if (difference > -5){
    digitalWrite(r1, HIGH);
    digitalWrite(r2, HIGH);
    digitalWrite(r3, HIGH);
    digitalWrite(r4, HIGH);
    digitalWrite(l1, LOW);
    digitalWrite(l2, LOW);
    digitalWrite(l3, LOW);
    digitalWrite(l4, LOW);
    }
    }

    The following pictures and videos shows how the sensors respond to a white line held in front of it. The LEDs act as bar to show the amount of white line detected by the sensors. The actual value shown on the LED is the difference of detection. i.e. if one sensor sees more of the white line than the other the sensor that sees the most line triggers the LEDs. If both sensors LEDs see the same amount of white line (with a tolerance of about 5%) there will not be any illumination on any of the LEDs. (Note - Real Resistor Values are not used)

    UoM Buggy Prototype 28Jan2013 (3)

    Line recognition:
    UoM Buggy Prototype 28Jan2013 (1)UoM Buggy Prototype 28Jan2013 (6)

    To improve the project I increased the number of LEDs and used a Launchpad MSP430 so that I can have a stand alone program using batteries.
    Since I do not have enough wires and pins I used 2 transistors to sink the LED current effectively.

    UoM Buggy Prototype 29Jan2013 (1)

    UoM Buggy Prototype 29Jan2013 (5)

    UoM Buggy Prototype 29Jan2013 (6)UoM Buggy Prototype 29Jan2013 (7)


    Here's a video of the final prototype


    No comments:

    Post a Comment