Line Tracking Robot Racer: The 2nd Model and testing

On this model, the Racer traveled in a straight line due to the wheel supports making it much easier to test. We used the 2 meter track previously used and timed it to gather the same data recorded from the last model (speed, acceleration and force).

Speed: We used the time it took for the Racer to finish the 2 meter track to calculate the speed, (the racer finished the track in 6 seconds).

Speed = Distance / Time

Speed = 2 / 6

Speed = 0.33 meters per second

An increased speed of  0.11 meters per second.


After calculating the change in velocity we worked out the acceleration. Acceleration had also improved.


80mm Wheels Acceleration = 0.055 meter / square second {m/s2}

An increase in acceleration by 0.0464 meter / square second {m/s2}


I order to calculate the force we reweighed the racer (including the egg this, as that will be included on the day of the race). The racer weight 350 grams, which is another 100 grams. Although we decreased the thickness of material and chose a less dense material, the amount of material to create the extra layer and structural support was added, so we expected an increase in weight overall.


Force = mass X acceleration

Force = 0.35(kg) X  0.055 (m/s2)

Force = 0.01925 N

An additional 0.0171 N of force was required.


Changes in the code were required for the Racer to move most efficiently due to the change in the Racers body.

  • Delays could be reduced due to the wheels being larger.
  • One wheel now turns in the opposite direction in order to achieve sharper turns.
  •  We set the motors to 220 on the PWM (pulse width modulation) pins when neither of the sensors are detecting the black lines which really helped in producing a noticeable improvement in speed.
Fastest Code So Far

Here we have the best code yet, I feel we’re nearing the sweet spot in terms of speed and reliability.

//left motor controls
int enableA = 10;
int in1 = 9;
int in2 = 8;

//right motor
int enableB = 5;
int in3 = 7;
int in4 = 6;

//sensor pins

int leftSensor = 4;
int rightSensor = 3;

void setup() {
pinMode(enableA, OUTPUT);
pinMode(enableB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(leftSensor, INPUT);
pinMode(rightSensor, INPUT);

void loop() {
int leftSensorValue = digitalRead(leftSensor);
int rightSensorValue = digitalRead(rightSensor);
boolean leftSenDetect = digitalRead(leftSensor);
boolean rightSenDetect = digitalRead(rightSensor);

//testing sensor values

Serial.print(“left sensor”);

Serial.print(“right sensor”);

// false is dark surface
//true is light surface

if (leftSenDetect == true && rightSenDetect == true) {
//left motor direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

analogWrite(enableA, 220);

// right motor

digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

analogWrite(enableB, 220);

else if (leftSenDetect == false && rightSenDetect == true) {

// left motor opposite way
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

analogWrite(enableA, 50);
//right motor speed
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

analogWrite(enableB, 70);


else if (leftSenDetect == true && rightSenDetect == false) {
// left motor speed
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

analogWrite(enableA, 70);

// right motor opposite way

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

analogWrite(enableB, 50);




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s