Previous                                                                     Tutorial                                                                     Tutorial

Contents

Authorized Online Retailers

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES

Objective

Welcome to the third lesson of OSOYOO 2WD Robot Car Starter Kit!

In this lesson, we will add 2 black/white tracking sensors to the framework built in Lesson 1 and Lesson 2. If you have not completed installation in Lesson 1, please finish it first.

The software in this lesson will read data from these 2 black/white tracking sensors and automatically guide the 2WD Robot Car to move along the black track line in the white ground.

top

Parts and Devices

Device

Picture
Qty.

Accessories

OSOYOO UNO R3

(fully compatible with Arduino UNO R3)

1 M3*6 Plastic Screw  x 3

M3 Plastic Nut  x 4

M3*5+6 Plastic Pillar x 4

OSOYOO Model-X Motor Driver Module
1 M3*6 Plastic Screw  x 4

M3 Plastic Nut  x 4

M3*5+6 Plastic Pillar x 4

Sensor Shield V5.0 for Arduino UNO
1
Tracking sensor module 2 M3*5 Screw x4

M3*10 Double Pass Copper Pillar x2

IR receiver
1
M3*6 Plastic Screw  x 1

M3 Plastic Nut  x 1

M3*5+6 Plastic Pillar x 1

IR remote controller
1
Car Chassis
1
Motors with wires
2
Wheels
2

Universal Wheel

1 M3*10 Double Pass Copper Pillar x 4

M3*5 Screw x 8

18650 Battery Box
(Battery is not include,
Battery Height ≤ 67 mm)
1 M3*10 Screw  x 4

M3*10 Nut  x 4

Metal Motor Holders
2
DC Power Connector
1
Phillips Screwdriver
1
Slot Type Screwdriver
1
40pin 10cm Female to Female Cable 1
10pin 30cm Female to Female Cable 1
20pin 15cm Male to Female Cable 1
Cable Tie 20

top

top

Hardware Installation

1) Install the 2WD Robot Car Chassis

Install the smart car basic framework as per 2WD Robot Car Starter Kit Lesson 1 and Lesson 2. If you have already completed installation in Lesson 1 and Lesson 2, just keep it, no need to remove any module installed.

2) Install the tracking sensor module

Accessories:

Use M3*5 Screws to install M3*10 Double Pass Copper Cylinders on the two tracking sensor modules, then use M3*5 Screws to install tracking sensor modules under the chassis

3) Using the female to female Dupont line to connect Sensor Shield V5.0 for Arduino UNO with the tracking sensor module:

The Right Tracking Sensor
Tracking Sensor Sensor Shield V5.0 for Arduino UNO
VCC 5V
GND GND
DO S3
AO Not Connected
The Left Tracking Sensor
Tracking Sensor Sensor Shield V5.0 for Arduino UNO
VCC 5V
GND GND
DO S2
AO Not Connected

More information about this module please refer to:

TCRT5000 Infrared Line Tracking Sensor

top

Software Installation

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to Arduino.

Step 1: Install latest Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step). Download Arduino IDE from https://www.arduino.cc/en/Main/Software?setlang=en , then install the software.

Step 2: Download and unzip lesson-3.zip , you will see a folder called lesson-3.

Step 3: Connect UNO R3 board to PC with USB cable, open Arduino IDE, choose corresponding board/port for your project,upload the sketch to the board.

Step 4: Arduino IDE: Click file -> click Open -> choose code “lesson-3.ino” in lesson-3 folder, load the code into arduino.

top

Code Explanation

Port Definitions between tracking sensor and Arduino UNO:

#define LFSensor_1 2 //line follow sensor1
#define LFSensor_2 3 //line follow sensor2

Defines an array, stores the signals detected by the tracing module in an array:

char sensor[2]={0,0};

The following two variables represent the speed of the car turning and executing:

Notice: Do not set the speed too large, when the speed is too big, the car may run out of track.

#define M_SPEED1   150  //motor speed
#define M_SPEED2   170  //motor speed

The following is the core code of the tracking function. The car will go straight when the black line is located between the left and right tracking sensor modules; the car will turn left when the left tracking sensor module above the black line; the car will turn right when the right tracking sensor module above the black line; the car will stop when the left and right tracking sensor module are both above the black line.

void auto_tarcking(){
  read_sensor_values();
  if((sensor[0]==LOW)&&(sensor[1]==HIGH)){ //The right sensor is on the black line.The left sensor is on the white line
    set_motorspeed(M_SPEED1,M_SPEED1);
    turn_right(20);
  }
  else if((sensor[0]==HIGH)&&(sensor[1]==LOW)){//The right sensor is on the white line.The left sensor is on the black line
    set_motorspeed(M_SPEED1,M_SPEED1);
    turn_left(20);
  }
  else if((sensor[0]==LOW)&&(sensor[1]==LOW)){//The left an right sensor are on the white line.
    set_motorspeed(M_SPEED2,M_SPEED2);
    go_ahead();
  }
  else if((sensor[0]==HIGH)&&(sensor[1]==HIGH)){//The left an right sensor are on the black line.
    go_stop();
  }
 }

top

Testing

Disconnect OSOYOO UNO R3 board from PC, put 2 fully-charged 18650 battery into battery box (check the box instruction and make sure polar direction is correct). Open the power switch in the battery box.

Step 1: Prepare a black track on white ground. (the width of the black track is more than 20mm and less than 30mm)

Please note, the bend angle of the track can’t be larger than 90 degree. If the angle is too large, the car will move out of the track.

Step 2: Adjust the sensitivity of tracking sensor modules.

Turn on and hold the car to adjust the potentiometer on the tracking sensor with Phillips screwdriver until you get the best sensitivity status: the signal indicate LED light will turn on when sensor is above white ground, and the signal LED
will turn off when the sensor is above black track.

Signal Indicate LED ON: White Ground

Signal Indicate LED OFF: Black Track

Step 3: Turn on the car and put the car over the black track, then the car will move along the black track.

Use the IR controller, press “OK”, the car will along the track; press “0”, the car will stop.

If the car can’t move, please check the following:

  1. If the battery can work;
  2. If the IR controller is too far away from the receiver;
  3. If the connection is right;
  4. If adjusted well the sensibility of the tracking sensor

top

Previous                                                                     Tutorial                                                                     Tutorial