Line Tracking Robot Racer: Further Component Analysis

We returned back to the components list after familiarising ourselves with the infrared sensors. We wanted to think outside the box when it come to the components we included in our design so that it was unique in comparison to the many other Robot Racers online. One unique idea for components we had was using a free moving wheel at the front of the racer, this not only add a quirky look and function but it would also use less energy than a servo operated wheel and is also lighter in weight. We will decided whether it will be included on the final design after testing it on a prototype model. But before we can test this free moving wheel and other components we need a working code.

There are a list of component that were given to us that need to be included in our design including two dc motors and a servo motor. We were also given a choice of motor controllers, we chose to include the L298N. From previous research, this motor controller seems perfect for what we are trying to achieve as it is simplistic and easy to control the speed (which is controlled using Pulse Width Modulation pins on the Arduino) and direction (each motor is connected to an additional two digital pins that control the direction through simple LOW /  HIGH code combinations). A 9v battery will be used to power the Arduino through the motor controller. The motor controller is necessary because one  motor will not consume much current, but can’t move a large mass whereas as two motors can move a large mass but will consume a large current. 

motor controllertesting motors

We realised from previous testing with the IR sensors that for them to work at there best they needed to be approximately 20mm from the floors surface due to shadowing and reflection from the light source on the sensor which would provide an inaccurate reading.

As mentioned in the previous blog post the idea is that we could attach the digital sensors to each side of the car and they will then hopefully they will be able to sense the light difference between the flooring and the black tape, and will always be able to correct itself so that the black tape is kept in between the two sensors. Therefore the Racer will be able to follow the line. Depending on which sensor detects the tape, either the left or right motor will switch off so that the robot will correct itself.


The Code:

//motor controls
//left motor
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 and distance required from ground

Serial.print(“left sensor = “);

Serial.print(“right sensor = “);

//false is if surface is DARK!
//true is if surface is LIGHT!

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

//left motor speed

//right motor direction
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

//right motor speed
analogWrite(enableB, 200);

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

// slow down left motor speed
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);

//left motor speed

analogWrite(enableA, 75);

//maintain right motor speed
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);


analogWrite(enableB, 100);


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

analogWrite(enableA, 100);

//slow down right motor
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);


analogWrite(enableB, 75);





This was basic prototype to test the functions of the model, although it lacked aesthetic quality to allowed us to test what we needed to. the base consisted of a 140mm X  70mm MDF board, and the components were attached to this with a range if blue tack, glue and double sided tape. These temporary attachment methods were useful for quick disassembly, in order to find the best position for the components.

Testing this prototype also made us aware of changes that needed to be made in the code, for example, we added a delay to the “if else” statements, giving the Racer more time to correct itself when turning sharp corners, due to this testing the delay has been set at 550 milliseconds, but this is open to change in further testing.

The first track we tested the model on was simplistic with minimal sharp corners, but since we are unsure on what the track will be like on the day, we created a more complex track once the car could follow the line on the first track.


There were a lot more issues with the second track (displayed below). The corners were so sharp that the Racer didn’t have enough delay time to sense the black line therefore it would leave the track. We altered the code and positioning of the sensors and after numerous attempts managed to get the Racer to follow it.


The laser cut wheels that were cut from the 6mm MDF lacked grip, this caused wheel spin when having one motor on and the other off. We solved this by using elastic bands to increase the traction greatly on the wheels.



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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s