Buy from US | Buy from UK | Buy from DE | Buy from IT | Buy from FR | Buy from ES |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
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.
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.
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:
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.
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(); } }
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:
DownLoad Url osoyoo.com
You must be logged in to post a comment.
adf